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();
29 Authorization
getAuthorization();
31 boolean isAnonymous();
33 ZonedDateTime
getCreationTime();
35 ZonedDateTime
getEnd();
41 /** @return The {@link CmsSession} for this {@link Subject} or null. */
42 static CmsSession
getCmsSession(BundleContext bc
, Subject subject
) {
43 if (subject
.getPrivateCredentials(CmsSessionId
.class).isEmpty())
45 CmsSessionId cmsSessionId
= subject
.getPrivateCredentials(CmsSessionId
.class).iterator().next();
46 String uuid
= cmsSessionId
.getUuid().toString();
47 Collection
<ServiceReference
<CmsSession
>> sr
;
49 sr
= bc
.getServiceReferences(CmsSession
.class, "(" + CmsSession
.SESSION_UUID
+ "=" + uuid
+ ")");
50 } catch (InvalidSyntaxException e
) {
51 throw new IllegalArgumentException("Cannot get CMS session for uuid " + uuid
, e
);
53 ServiceReference
<CmsSession
> cmsSessionRef
;
55 cmsSessionRef
= sr
.iterator().next();
56 return bc
.getService(cmsSessionRef
);
57 } else if (sr
.size() == 0) {
60 throw new IllegalStateException(sr
.size() + " CMS sessions registered for " + uuid
);