1 package org
.argeo
.cms
.auth
;
3 import java
.time
.ZonedDateTime
;
4 import java
.util
.Collection
;
5 import java
.util
.Locale
;
8 import javax
.naming
.ldap
.LdapName
;
9 import javax
.security
.auth
.Subject
;
11 import org
.argeo
.naming
.LdapAttrs
;
12 import org
.osgi
.framework
.BundleContext
;
13 import org
.osgi
.framework
.InvalidSyntaxException
;
14 import org
.osgi
.framework
.ServiceReference
;
15 import org
.osgi
.service
.useradmin
.Authorization
;
17 /** An authenticated user session. */
18 public interface CmsSession
{
19 final static String USER_DN
= LdapAttrs
.DN
;
20 final static String SESSION_UUID
= LdapAttrs
.entryUUID
.name();
21 final static String SESSION_LOCAL_ID
= LdapAttrs
.uniqueIdentifier
.name();
31 Authorization
getAuthorization();
35 boolean isAnonymous();
37 ZonedDateTime
getCreationTime();
39 ZonedDateTime
getEnd();
45 void registerView(String uid
, Object view
);
47 /** @return The {@link CmsSession} for this {@link Subject} or null. */
48 static CmsSession
getCmsSession(BundleContext bc
, Subject subject
) {
49 if (subject
.getPrivateCredentials(CmsSessionId
.class).isEmpty())
51 CmsSessionId cmsSessionId
= subject
.getPrivateCredentials(CmsSessionId
.class).iterator().next();
52 String uuid
= cmsSessionId
.getUuid().toString();
53 Collection
<ServiceReference
<CmsSession
>> sr
;
55 sr
= bc
.getServiceReferences(CmsSession
.class, "(" + CmsSession
.SESSION_UUID
+ "=" + uuid
+ ")");
56 } catch (InvalidSyntaxException e
) {
57 throw new IllegalArgumentException("Cannot get CMS session for uuid " + uuid
, e
);
59 ServiceReference
<CmsSession
> cmsSessionRef
;
61 cmsSessionRef
= sr
.iterator().next();
62 return bc
.getService(cmsSessionRef
);
63 } else if (sr
.size() == 0) {
66 throw new IllegalStateException(sr
.size() + " CMS sessions registered for " + uuid
);