X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Fauth%2FCmsSession.java;h=ad91cb7f05a11655f348f6ff6a411ccdb7c22959;hb=a1e5c8447beec2b896b0a03e38a4c17608a4b85d;hp=118f875891a8782ed8248d6633b730bb689cc600;hpb=b45e59192a4bb34a6b38a9bfa416b3dc3f6b7892;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/auth/CmsSession.java b/org.argeo.cms/src/org/argeo/cms/auth/CmsSession.java index 118f87589..ad91cb7f0 100644 --- a/org.argeo.cms/src/org/argeo/cms/auth/CmsSession.java +++ b/org.argeo.cms/src/org/argeo/cms/auth/CmsSession.java @@ -1,41 +1,68 @@ package org.argeo.cms.auth; import java.time.ZonedDateTime; +import java.util.Collection; +import java.util.Locale; import java.util.UUID; import javax.naming.ldap.LdapName; +import javax.security.auth.Subject; import org.argeo.naming.LdapAttrs; +import org.osgi.framework.BundleContext; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; import org.osgi.service.useradmin.Authorization; +/** An authenticated user session. */ public interface CmsSession { final static String USER_DN = LdapAttrs.DN; final static String SESSION_UUID = LdapAttrs.entryUUID.name(); final static String SESSION_LOCAL_ID = LdapAttrs.uniqueIdentifier.name(); - // public String getId(); - UUID getUuid(); + String getUserRole(); + LdapName getUserDn(); String getLocalId(); Authorization getAuthorization(); + + Subject getSubject(); boolean isAnonymous(); ZonedDateTime getCreationTime(); + ZonedDateTime getEnd(); - boolean isValid(); + Locale getLocale(); - // public Session getDataSession(String cn, String workspace, Repository - // repository); - // - // public void releaseDataSession(String cn, Session session); + boolean isValid(); - // public void addHttpSession(HttpServletRequest request); + void registerView(String uid, Object view); - // public void cleanUp(); + /** @return The {@link CmsSession} for this {@link Subject} or null. */ + static CmsSession getCmsSession(BundleContext bc, Subject subject) { + if (subject.getPrivateCredentials(CmsSessionId.class).isEmpty()) + return null; + CmsSessionId cmsSessionId = subject.getPrivateCredentials(CmsSessionId.class).iterator().next(); + String uuid = cmsSessionId.getUuid().toString(); + Collection> sr; + try { + sr = bc.getServiceReferences(CmsSession.class, "(" + CmsSession.SESSION_UUID + "=" + uuid + ")"); + } catch (InvalidSyntaxException e) { + throw new IllegalArgumentException("Cannot get CMS session for uuid " + uuid, e); + } + ServiceReference cmsSessionRef; + if (sr.size() == 1) { + cmsSessionRef = sr.iterator().next(); + return bc.getService(cmsSessionRef); + } else if (sr.size() == 0) { + return null; + } else + throw new IllegalStateException(sr.size() + " CMS sessions registered for " + uuid); + } }