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