Skip to content

Commit ce769fa

Browse files
author
Alex Heneveld
committed
Further tidy-up of login/logout logging
1 parent f046b27 commit ce769fa

4 files changed

Lines changed: 29 additions & 4 deletions

File tree

rest/rest-resources/src/main/java/org/apache/brooklyn/rest/filter/BrooklynSecurityProviderFilterHelper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ public void run(HttpServletRequest webRequest, ManagementContext mgmt, @Nullable
165165
if (idxColon >= 0) {
166166
user = userpass.substring(0, idxColon);
167167
pass = userpass.substring(idxColon + 1);
168+
if ("logout".equals(user) && "logout".equals(pass)) {
169+
// logout:logout sent by UI to clear browser state; force failure here and suppress subsequent error messages in log, after a logout
170+
throw abort("Reauthorization required after logout", provider.requiresUserPass());
171+
}
168172
} else {
169173
throw abort("Invalid authorization string (no colon after decoding)", provider.requiresUserPass());
170174
}
@@ -192,7 +196,8 @@ public void run(HttpServletRequest webRequest, ManagementContext mgmt, @Nullable
192196
}
193197
}
194198
LoginLogging.logLoginIfNotLogged(preferredSession2, user,
195-
MutableMap.of("origin", webRequest.getRemoteAddr(), "provider", provider.getClass().getName()));
199+
MutableMap.of("origin", webRequest.getRemoteAddr(), "provider",
200+
DelegatingSecurityProvider.getTarget(provider).getClass().getName()));
196201

197202
return;
198203
}

rest/rest-resources/src/main/java/org/apache/brooklyn/rest/security/LoginLogging.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.brooklyn.rest.security;
2020

2121
import org.apache.brooklyn.util.collections.MutableMap;
22+
import org.apache.brooklyn.util.exceptions.Exceptions;
2223
import org.slf4j.Logger;
2324
import org.slf4j.LoggerFactory;
2425

@@ -50,7 +51,20 @@ private static String getValuesForLogging(HttpSession session, Map<String, Strin
5051
}
5152

5253
public static void logLogout(HttpSession session, String user, Map<String,String> values) {
53-
session.setAttribute(LOGIN_LOGGED, false);
54+
boolean error = false;
55+
try {
56+
session.setAttribute(LOGIN_LOGGED, false);
57+
} catch (Exception e) {
58+
Exceptions.propagateIfFatal(e);
59+
// expected
60+
error = true;
61+
}
62+
if (!error) {
63+
log.warn("Expected error clearing logged attribute on session but session did not report an invalidated error: "+session);
64+
values = MutableMap.copyOf(values).add("error", "WARN: unconfirmed; see log above");
65+
}
66+
// above is just to be safe; normally logout will invalidate session so the above will error with no side-effect
67+
5468
log.debug(
5569
"Logout of " +
5670
(user==null ? "anonymous user" : "user: "+user) +

rest/rest-resources/src/main/java/org/apache/brooklyn/rest/security/provider/DelegatingSecurityProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public DelegatingSecurityProvider(ManagementContext mgmt) {
5151

5252
private SecurityProvider delegate;
5353

54+
public static SecurityProvider getTarget(SecurityProvider provider) {
55+
if (provider instanceof DelegatingSecurityProvider) return getTarget( ((DelegatingSecurityProvider) provider).getDelegate() );
56+
return provider;
57+
}
58+
5459
public synchronized SecurityProvider getDelegate() {
5560
if (delegate == null) {
5661
delegate = loadDelegate();

rest/rest-resources/src/main/java/org/apache/brooklyn/rest/security/provider/ExplicitUsersSecurityProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.brooklyn.core.internal.BrooklynProperties;
3232
import org.apache.brooklyn.rest.BrooklynWebConfig;
3333
import org.apache.brooklyn.rest.security.PasswordHasher;
34+
import org.apache.brooklyn.util.text.Strings;
3435
import org.slf4j.Logger;
3536
import org.slf4j.LoggerFactory;
3637

@@ -74,10 +75,10 @@ private synchronized void initialize() {
7475

7576
@Override
7677
public boolean authenticate(HttpServletRequest request, Supplier<HttpSession> sessionSupplierOnSuccess, String user, String pass) throws SecurityProviderDeniedAuthentication {
77-
if (user==null) return false;
78+
if (Strings.isBlank(user)) return false;
7879
if (!allowAnyUserWithValidPass) {
7980
if (!allowedUsers.contains(user)) {
80-
LOG.debug("REST rejecting unknown user "+user);
81+
LOG.debug("REST authentication rejecting unknown user '"+user+"'");
8182
return false;
8283
}
8384
}

0 commit comments

Comments
 (0)