Improve logging
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / auth / UserAdminLoginModule.java
index 2b5c41ddf8333395ddccf823d14124b5000ddcbf..638547d2471a3d94e69d7de82a7595d60ea29e0e 100644 (file)
@@ -103,6 +103,11 @@ public class UserAdminLoginModule implements LoginModule {
                        username = (String) sharedState.get(CmsAuthUtils.SHARED_STATE_NAME);
                        password = null;
                        preauth = true;
+               } else if (sharedState.containsKey(CmsAuthUtils.SHARED_STATE_OS_USERNAME)) {
+                       // single user, we assume Kerberos or other mean for commit
+                       username = (String) sharedState.get(CmsAuthUtils.SHARED_STATE_OS_USERNAME);
+                       password = null;
+                       preauth = true;
                } else {
 
                        // ask for username and password
@@ -205,7 +210,7 @@ public class UserAdminLoginModule implements LoginModule {
 //             }
                UserAdmin userAdmin = CmsContextImpl.getCmsContext().getUserAdmin();
                Authorization authorization;
-               if (callbackHandler == null) {// anonymous
+               if (callbackHandler == null && !sharedState.containsKey(CmsAuthUtils.SHARED_STATE_OS_USERNAME)) {// anonymous
                        authorization = userAdmin.getAuthorization(null);
                } else if (bindAuthorization != null) {// bind
                        authorization = bindAuthorization;
@@ -277,14 +282,16 @@ public class UserAdminLoginModule implements LoginModule {
 
                if (log.isDebugEnabled()) {
                        StringBuilder msg = new StringBuilder();
-                       msg.append("Logged in to CMS: " + authorization.getName() + "(" + authorization + ")\n");
-                       for (Principal principal : subject.getPrincipals()) {
-                               msg.append("  Principal: " + principal.getName()).append(" (")
-                                               .append(principal.getClass().getSimpleName()).append(")\n");
-                       }
-                       for (Object credential : subject.getPublicCredentials()) {
-                               msg.append("  Public Credential: " + credential).append(" (")
-                                               .append(credential.getClass().getSimpleName()).append(")\n");
+                       msg.append("Logged in to CMS: '" + authorization + "' (" + authorization.getName() + ")\n");
+                       if (log.isTraceEnabled()) {
+                               for (Principal principal : subject.getPrincipals()) {
+                                       msg.append("  Principal: " + principal.getName()).append(" (")
+                                                       .append(principal.getClass().getSimpleName()).append(")\n");
+                               }
+                               for (Object credential : subject.getPublicCredentials()) {
+                                       msg.append("  Public Credential: " + credential).append(" (")
+                                                       .append(credential.getClass().getSimpleName()).append(")\n");
+                               }
                        }
                        log.debug(msg);
                }