Make username and user role more consistent.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / auth / CmsSessionImpl.java
index 8761480fe29f8ebdc57a4d7336ab4c748ab4ffd1..9ae0fd8d8b5634091d221633085bd93618df2090 100644 (file)
@@ -24,6 +24,7 @@ import javax.naming.ldap.LdapName;
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
+import javax.security.auth.x500.X500Principal;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -60,6 +61,8 @@ public class CmsSessionImpl implements CmsSession {
        private Set<String> dataSessionsInUse = new HashSet<>();
        private LinkedHashSet<Session> additionalDataSessions = new LinkedHashSet<>();
 
+       private Map<String, Object> views = new HashMap<>();
+
        public CmsSessionImpl(Subject initialSubject, Authorization authorization, Locale locale, String localSessionId) {
                this.creationTime = ZonedDateTime.now();
                this.locale = locale;
@@ -222,6 +225,11 @@ public class CmsSessionImpl implements CmsSession {
                return userDn;
        }
 
+       @Override
+       public String getUserRole() {
+               return new X500Principal(authorization.getName()).getName();
+       }
+
        @Override
        public String getLocalId() {
                return localSessionId;
@@ -247,6 +255,13 @@ public class CmsSessionImpl implements CmsSession {
                return end;
        }
 
+       @Override
+       public void registerView(String uid, Object view) {
+               if (views.containsKey(uid))
+                       throw new IllegalArgumentException("View " + uid + " is already registered.");
+               views.put(uid, view);
+       }
+
        public String toString() {
                return "CMS Session " + userDn + " local=" + localSessionId + ", uuid=" + uuid;
        }