Improve CMS security layer documentation.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / auth / CmsSessionImpl.java
index 8761480fe29f8ebdc57a4d7336ab4c748ab4ffd1..b6966765d9534ea1469188dc5a81c06b1cf80fa3 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;
@@ -38,6 +39,7 @@ import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.useradmin.Authorization;
 
+/** Default CMS session implementation. */
 public class CmsSessionImpl implements CmsSession {
        private final static BundleContext bc = FrameworkUtil.getBundle(CmsSessionImpl.class).getBundleContext();
        private final static Log log = LogFactory.getLog(CmsSessionImpl.class);
@@ -60,6 +62,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 +226,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 +256,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;
        }