import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
-import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
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;
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);
private Map<String, Session> dataSessions = new HashMap<>();
private Set<String> dataSessionsInUse = new HashSet<>();
- private LinkedHashSet<Session> additionalDataSessions = new LinkedHashSet<>();
+ private Set<Session> additionalDataSessions = new HashSet<>();
+
+ private Map<String, Object> views = new HashMap<>();
public CmsSessionImpl(Subject initialSubject, Authorization authorization, Locale locale, String localSessionId) {
this.creationTime = ZonedDateTime.now();
}
public Set<SecretKey> getSecretKeys() {
+ checkValid();
return getSubject().getPrivateCredentials(SecretKey.class);
}
public Session newDataSession(String cn, String workspace, Repository repository) {
+ checkValid();
return login(repository, workspace);
}
public synchronized Session getDataSession(String cn, String workspace, Repository repository) {
+ checkValid();
// FIXME make it more robust
if (workspace == null)
workspace = NodeConstants.SYS_WORKSPACE;
return !isClosed();
}
- protected boolean isClosed() {
+ private void checkValid() {
+ if (!isValid())
+ throw new IllegalStateException("CMS session " + uuid + " is not valid since " + end);
+ }
+
+ final protected boolean isClosed() {
return getEnd() != null;
}
@Override
public Authorization getAuthorization() {
+ checkValid();
return authorization;
}
return userDn;
}
+ @Override
+ public String getUserRole() {
+ return new X500Principal(authorization.getName()).getName();
+ }
+
@Override
public String getLocalId() {
return localSessionId;
return end;
}
+ @Override
+ public void registerView(String uid, Object view) {
+ checkValid();
+ 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;
}