gluu
公開メンバ関数 | 静的公開変数類 | 非公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.xdi.oxauth.service.SessionIdService クラス
org.xdi.oxauth.service.SessionIdService 連携図
Collaboration graph

公開メンバ関数

String getAcr (SessionId session)
 
SessionId assertAuthenticatedSessionCorrespondsToNewRequest (SessionId session, String acrValuesStr) throws AcrChangedException
 
void reinitLogin (SessionId session, boolean force)
 
void resetToStep (SessionId session, int resetToStep)
 
String getSessionIdFromCookie (HttpServletRequest request)
 
String getUmaSessionIdFromCookie (HttpServletRequest request)
 
String getConsentSessionIdFromCookie (HttpServletRequest request)
 
String getSessionIdFromCookie (HttpServletRequest request, String cookieName)
 
String getSessionIdFromCookie ()
 
void createSessionIdCookie (String sessionId, String sessionState, HttpServletResponse httpResponse, String cookieName)
 
void createSessionIdCookie (String sessionId, String sessionState, HttpServletResponse httpResponse, boolean isUma)
 
void createSessionIdCookie (String sessionId, String sessionState, boolean isUma)
 
void createSessionStateCookie (String sessionState, HttpServletResponse httpResponse)
 
void removeSessionIdCookie (HttpServletResponse httpResponse)
 
void removeUmaSessionIdCookie (HttpServletResponse httpResponse)
 
void removeConsentSessionIdCookie (HttpServletResponse httpResponse)
 
SessionId getSessionId ()
 
Map< String, String > getSessionAttributes (SessionId sessionId)
 
SessionId generateAuthenticatedSessionId (HttpServletRequest httpRequest, String userDn)
 
SessionId generateAuthenticatedSessionId (HttpServletRequest httpRequest, String userDn, String prompt)
 
SessionId generateAuthenticatedSessionId (HttpServletRequest httpRequest, String userDn, Map< String, String > sessionIdAttributes)
 
SessionId generateUnauthenticatedSessionId (String userDn)
 
SessionId generateUnauthenticatedSessionId (String userDn, Date authenticationDate, SessionIdState state, Map< String, String > sessionIdAttributes, boolean persist)
 
SessionId setSessionIdStateAuthenticated (HttpServletRequest httpRequest, SessionId sessionId, String p_userDn)
 
boolean persistSessionId (final SessionId sessionId)
 
boolean persistSessionId (final SessionId sessionId, boolean forcePersistence)
 
boolean updateSessionId (final SessionId sessionId)
 
boolean updateSessionId (final SessionId sessionId, boolean updateLastUsedAt)
 
boolean updateSessionId (final SessionId sessionId, boolean updateLastUsedAt, boolean forceUpdate, boolean modified)
 
void updateSessionIdIfNeeded (SessionId sessionId, boolean modified)
 
SessionId getSessionById (String sessionId)
 
SessionId getSessionId (String sessionId)
 
boolean remove (SessionId sessionId)
 
void remove (List< SessionId > list)
 
boolean isSessionValid (SessionId sessionId)
 
boolean isSessionIdAuthenticated ()
 
boolean isSessionIdAuthenticated (SessionId sessionId)
 
boolean isNotSessionIdAuthenticated ()
 
List< String > acrValuesList (String acrValues)
 
void refreshSessionId ()
 

静的公開変数類

static final String SESSION_STATE_COOKIE_NAME = "session_state"
 
static final String SESSION_ID_COOKIE_NAME = "session_id"
 
static final String UMA_SESSION_ID_COOKIE_NAME = "uma_session_id"
 
static final String CONSENT_SESSION_ID_COOKIE_NAME = "consent_session_id"
 
static final String SESSION_CUSTOM_STATE = "session_custom_state"
 

非公開メンバ関数

Map< String, String > getCurrentSessionAttributes (Map< String, String > sessionAttributes)
 
SessionId generateAuthenticatedSessionId (HttpServletRequest httpRequest, String userDn, Date authenticationDate, Map< String, String > sessionIdAttributes, boolean persist)
 
SessionId generateSessionId (String userDn, Date authenticationDate, SessionIdState state, Map< String, String > sessionIdAttributes, boolean persist)
 
Jwt generateJwt (SessionId sessionId, String audience)
 
void putInCache (SessionId sessionId)
 
SessionId getFromCache (String sessionId)
 
SessionId mergeWithRetry (final SessionId sessionId, int maxAttempts)
 
boolean isPersisted (List< Prompt > prompts)
 
String dn (String p_id)
 
String getBaseDn ()
 
List< PromptgetPromptsFromSessionId (final SessionId sessionId)
 
void auditLogging (SessionId sessionId)
 

非公開変数類

Logger log
 
ExternalAuthenticationService externalAuthenticationService
 
ExternalApplicationSessionService externalApplicationSessionService
 
ApplicationAuditLogger applicationAuditLogger
 
AppConfiguration appConfiguration
 
StaticConfiguration staticConfiguration
 
WebKeysConfiguration webKeysConfiguration
 
FacesContext facesContext
 
ExternalContext externalContext
 
CacheService cacheService
 
RequestParameterService requestParameterService
 

詳解

著者
Yuriy Zabrovarnyy
Yuriy Movchan
Javier Rojas Blum
バージョン
August 9, 2017

関数詳解

◆ acrValuesList()

List<String> org.xdi.oxauth.service.SessionIdService.acrValuesList ( String  acrValues)
inline

By definition we expects space separated acr values as it is defined in spec. But we also try maybe some client sent it to us as json array. So we try both.

戻り値
acr value list
759  {
760  List<String> acrs;
761  try {
762  acrs = Util.jsonArrayStringAsList(acrValues);
763  } catch (JSONException ex) {
764  acrs = Util.splittedStringAsList(acrValues, " ");
765  }
766 
767  return acrs;
768  }

◆ assertAuthenticatedSessionCorrespondsToNewRequest()

SessionId org.xdi.oxauth.service.SessionIdService.assertAuthenticatedSessionCorrespondsToNewRequest ( SessionId  session,
String  acrValuesStr 
) throws AcrChangedException
inline
126  {
127  if (session != null && !session.getSessionAttributes().isEmpty() && session.getState() == SessionIdState.AUTHENTICATED) {
128 
129  final Map<String, String> sessionAttributes = session.getSessionAttributes();
130 
131  String sessionAcr = getAcr(session);
132 
133  if (StringUtils.isBlank(sessionAcr)) {
134  log.error("Failed to fetch acr from session, attributes: " + sessionAttributes);
135  return session;
136  }
137 
138  List<String> acrValuesList = acrValuesList(acrValuesStr);
139  boolean isAcrChanged = !acrValuesList.isEmpty() && !acrValuesList.contains(sessionAcr);
140  if (isAcrChanged) {
141  Map<String, Integer> acrToLevel = externalAuthenticationService.acrToLevelMapping();
142  Integer sessionAcrLevel = acrToLevel.get(sessionAcr);
143 
144  for (String acrValue : acrValuesList) {
145  Integer currentAcrLevel = acrToLevel.get(acrValue);
146 
147  log.info("Acr is changed. Session acr: " + sessionAcr + "(level: " + sessionAcrLevel + "), " +
148  "current acr: " + acrValue + "(level: " + currentAcrLevel + ")");
149 
150  // Requested acr method not enabled
151  if (currentAcrLevel == null) {
152  throw new AcrChangedException(false);
153  }
154 
155  if (sessionAcrLevel < currentAcrLevel) {
156  throw new AcrChangedException();
157  }
158  }
159  // https://github.com/GluuFederation/oxAuth/issues/291
160  return session; // we don't want to reinit login because we have stronger acr (avoid overriding)
161  }
162 
163  reinitLogin(session, false);
164  }
165 
166  return session;
167  }
Logger log
Definition: SessionIdService.java:77
void reinitLogin(SessionId session, boolean force)
Definition: SessionIdService.java:169
String getAcr(SessionId session)
Definition: SessionIdService.java:109
ExternalAuthenticationService externalAuthenticationService
Definition: SessionIdService.java:80
Map< String, Integer > acrToLevelMapping()
Definition: ExternalAuthenticationService.java:472
List< String > acrValuesList(String acrValues)
Definition: SessionIdService.java:759

◆ auditLogging()

void org.xdi.oxauth.service.SessionIdService.auditLogging ( SessionId  sessionId)
inlineprivate
770  {
771  HttpServletRequest httpServletRequest = ServerUtil.getRequestOrNull();
772  if (httpServletRequest != null) {
773  Action action;
774  switch (sessionId.getState()) {
775  case AUTHENTICATED:
776  action = Action.SESSION_AUTHENTICATED;
777  break;
778  case UNAUTHENTICATED:
779  action = Action.SESSION_UNAUTHENTICATED;
780  break;
781  default:
782  action = Action.SESSION_UNAUTHENTICATED;
783  }
784  OAuth2AuditLog oAuth2AuditLog = new OAuth2AuditLog(ServerUtil.getIpAddress(httpServletRequest), action);
785  oAuth2AuditLog.setSuccess(true);
786  applicationAuditLogger.sendMessage(oAuth2AuditLog);
787  }
788  }
ApplicationAuditLogger applicationAuditLogger
Definition: SessionIdService.java:86
void sendMessage(OAuth2AuditLog oAuth2AuditLog)
Definition: ApplicationAuditLogger.java:78

◆ createSessionIdCookie() [1/3]

void org.xdi.oxauth.service.SessionIdService.createSessionIdCookie ( String  sessionId,
String  sessionState,
HttpServletResponse  httpResponse,
String  cookieName 
)
inline
284  {
285  String header = cookieName + "=" + sessionId;
286  header += "; Path=/";
287  header += "; Secure";
288  header += "; HttpOnly";
289 
290  Integer sessionStateLifetime = appConfiguration.getSessionIdLifetime();
291  if (sessionStateLifetime != null && sessionStateLifetime > 0) {
292  DateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
293  Calendar expirationDate = Calendar.getInstance();
294  expirationDate.add(Calendar.SECOND, sessionStateLifetime);
295  header += "; Expires=" + formatter.format(expirationDate.getTime()) + ";";
296  }
297 
298  httpResponse.addHeader("Set-Cookie", header);
299 
300  createSessionStateCookie(sessionState, httpResponse);
301  }
Integer getSessionIdLifetime()
Definition: AppConfiguration.java:1345
void createSessionStateCookie(String sessionState, HttpServletResponse httpResponse)
Definition: SessionIdService.java:321
AppConfiguration appConfiguration
Definition: SessionIdService.java:89

◆ createSessionIdCookie() [2/3]

void org.xdi.oxauth.service.SessionIdService.createSessionIdCookie ( String  sessionId,
String  sessionState,
HttpServletResponse  httpResponse,
boolean  isUma 
)
inline
303  {
304  String cookieName = isUma ? UMA_SESSION_ID_COOKIE_NAME : SESSION_ID_COOKIE_NAME;
305  createSessionIdCookie(sessionId, sessionState, httpResponse, cookieName);
306  }
static final String UMA_SESSION_ID_COOKIE_NAME
Definition: SessionIdService.java:72
static final String SESSION_ID_COOKIE_NAME
Definition: SessionIdService.java:71
void createSessionIdCookie(String sessionId, String sessionState, HttpServletResponse httpResponse, String cookieName)
Definition: SessionIdService.java:284

◆ createSessionIdCookie() [3/3]

void org.xdi.oxauth.service.SessionIdService.createSessionIdCookie ( String  sessionId,
String  sessionState,
boolean  isUma 
)
inline
308  {
309  try {
310  final Object response = externalContext.getResponse();
311  if (response instanceof HttpServletResponse) {
312  final HttpServletResponse httpResponse = (HttpServletResponse) response;
313 
314  createSessionIdCookie(sessionId, sessionState, httpResponse, isUma);
315  }
316  } catch (Exception e) {
317  log.error(e.getMessage(), e);
318  }
319  }
ExternalContext externalContext
Definition: SessionIdService.java:101
Logger log
Definition: SessionIdService.java:77
void createSessionIdCookie(String sessionId, String sessionState, HttpServletResponse httpResponse, String cookieName)
Definition: SessionIdService.java:284

◆ createSessionStateCookie()

void org.xdi.oxauth.service.SessionIdService.createSessionStateCookie ( String  sessionState,
HttpServletResponse  httpResponse 
)
inline
321  {
322  // Create the special cookie header with secure flag but not HttpOnly because the session_state
323  // needs to be read from the OP iframe using JavaScript
324  String header = SESSION_STATE_COOKIE_NAME + "=" + sessionState;
325  header += "; Path=/";
326  header += "; Secure";
327 
328  Integer sessionStateLifetime = appConfiguration.getSessionIdLifetime();
329  if (sessionStateLifetime != null && sessionStateLifetime > 0) {
330  DateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
331  Calendar expirationDate = Calendar.getInstance();
332  expirationDate.add(Calendar.SECOND, sessionStateLifetime);
333  header += "; Expires=" + formatter.format(expirationDate.getTime()) + ";";
334  }
335 
336  httpResponse.addHeader("Set-Cookie", header);
337  }
Integer getSessionIdLifetime()
Definition: AppConfiguration.java:1345
static final String SESSION_STATE_COOKIE_NAME
Definition: SessionIdService.java:70
AppConfiguration appConfiguration
Definition: SessionIdService.java:89

◆ dn()

String org.xdi.oxauth.service.SessionIdService.dn ( String  p_id)
inlineprivate
643  {
644  final String baseDn = getBaseDn();
645  final StringBuilder sb = new StringBuilder();
646  if (Util.allNotBlank(p_id, getBaseDn())) {
647  sb.append("oxAuthSessionId=").append(p_id).append(",").append(baseDn);
648  }
649  return sb.toString();
650  }
String getBaseDn()
Definition: SessionIdService.java:679

◆ generateAuthenticatedSessionId() [1/4]

SessionId org.xdi.oxauth.service.SessionIdService.generateAuthenticatedSessionId ( HttpServletRequest  httpRequest,
String  userDn 
)
inline
378  {
379  return generateAuthenticatedSessionId(httpRequest, userDn, "");
380  }
SessionId generateAuthenticatedSessionId(HttpServletRequest httpRequest, String userDn)
Definition: SessionIdService.java:378

◆ generateAuthenticatedSessionId() [2/4]

SessionId org.xdi.oxauth.service.SessionIdService.generateAuthenticatedSessionId ( HttpServletRequest  httpRequest,
String  userDn,
String  prompt 
)
inline
382  {
383  Map<String, String> sessionIdAttributes = new HashMap<String, String>();
384  sessionIdAttributes.put("prompt", prompt);
385 
386  return generateAuthenticatedSessionId(httpRequest, userDn, new Date(), sessionIdAttributes, true);
387  }
SessionId generateAuthenticatedSessionId(HttpServletRequest httpRequest, String userDn)
Definition: SessionIdService.java:378

◆ generateAuthenticatedSessionId() [3/4]

SessionId org.xdi.oxauth.service.SessionIdService.generateAuthenticatedSessionId ( HttpServletRequest  httpRequest,
String  userDn,
Map< String, String >  sessionIdAttributes 
)
inline
389  {
390  return generateAuthenticatedSessionId(httpRequest, userDn, new Date(), sessionIdAttributes, true);
391  }
SessionId generateAuthenticatedSessionId(HttpServletRequest httpRequest, String userDn)
Definition: SessionIdService.java:378

◆ generateAuthenticatedSessionId() [4/4]

SessionId org.xdi.oxauth.service.SessionIdService.generateAuthenticatedSessionId ( HttpServletRequest  httpRequest,
String  userDn,
Date  authenticationDate,
Map< String, String >  sessionIdAttributes,
boolean  persist 
)
inlineprivate
393  {
394  SessionId sessionId = generateSessionId(userDn, new Date(), SessionIdState.AUTHENTICATED, sessionIdAttributes, true);
395 
396  if (externalApplicationSessionService.isEnabled()) {
397  String userName = sessionId.getSessionAttributes().get(Constants.AUTHENTICATED_USER);
398  boolean externalResult = externalApplicationSessionService.executeExternalStartSessionMethods(httpRequest, sessionId);
399  log.info("Start session result for '{}': '{}'", userName, "start", externalResult);
400  }
401 
402  return sessionId;
403  }
boolean executeExternalStartSessionMethods(HttpServletRequest httpRequest, SessionId sessionId)
Definition: ExternalApplicationSessionService.java:54
Logger log
Definition: SessionIdService.java:77
ExternalApplicationSessionService externalApplicationSessionService
Definition: SessionIdService.java:83
SessionId generateSessionId(String userDn, Date authenticationDate, SessionIdState state, Map< String, String > sessionIdAttributes, boolean persist)
Definition: SessionIdService.java:414

◆ generateJwt()

Jwt org.xdi.oxauth.service.SessionIdService.generateJwt ( SessionId  sessionId,
String  audience 
)
inlineprivate
464  {
465  try {
466  JwtSigner jwtSigner = new JwtSigner(appConfiguration, webKeysConfiguration, SignatureAlgorithm.RS512, audience);
467  Jwt jwt = jwtSigner.newJwt();
468 
469  // claims
470  jwt.getClaims().setClaim("id", sessionId.getId());
471  jwt.getClaims().setClaim("authentication_time", sessionId.getAuthenticationTime());
472  jwt.getClaims().setClaim("user_dn", sessionId.getUserDn());
473  jwt.getClaims().setClaim("state", sessionId.getState() != null ?
474  sessionId.getState().getValue() : "");
475 
476  jwt.getClaims().setClaim("session_attributes", JwtSubClaimObject.fromMap(sessionId.getSessionAttributes()));
477 
478  jwt.getClaims().setClaim("last_used_at", sessionId.getLastUsedAt());
479  jwt.getClaims().setClaim("permission_granted", sessionId.getPermissionGranted());
480  jwt.getClaims().setClaim("permission_granted_map", JwtSubClaimObject.fromBooleanMap(sessionId.getPermissionGrantedMap().getPermissionGranted()));
481  jwt.getClaims().setClaim("involved_clients_map", JwtSubClaimObject.fromBooleanMap(sessionId.getInvolvedClients().getPermissionGranted()));
482 
483  // sign
484  return jwtSigner.sign();
485  } catch (Exception e) {
486  log.error("Failed to sign session jwt! " + e.getMessage(), e);
487  throw new RuntimeException(e);
488  }
489  }
WebKeysConfiguration webKeysConfiguration
Definition: SessionIdService.java:95
Logger log
Definition: SessionIdService.java:77
AppConfiguration appConfiguration
Definition: SessionIdService.java:89

◆ generateSessionId()

SessionId org.xdi.oxauth.service.SessionIdService.generateSessionId ( String  userDn,
Date  authenticationDate,
SessionIdState  state,
Map< String, String >  sessionIdAttributes,
boolean  persist 
)
inlineprivate
414  {
415  final String sid = UUID.randomUUID().toString();
416  final String sessionState = UUID.randomUUID().toString();
417  final String dn = dn(sid);
418 
419  if (StringUtils.isBlank(dn)) {
420  return null;
421  }
422 
423  if (SessionIdState.AUTHENTICATED == state) {
424  if (StringUtils.isBlank(userDn)) {
425  return null;
426  }
427  }
428 
429  final SessionId sessionId = new SessionId();
430  sessionId.setId(sid);
431  sessionId.setDn(dn);
432  sessionId.setUserDn(userDn);
433  sessionId.setSessionState(sessionState);
434 
435  Boolean sessionAsJwt = appConfiguration.getSessionAsJwt();
436  sessionId.setIsJwt(sessionAsJwt != null && sessionAsJwt);
437 
438  if (authenticationDate != null) {
439  sessionId.setAuthenticationTime(authenticationDate);
440  }
441 
442  if (state != null) {
443  sessionId.setState(state);
444  }
445 
446  sessionId.setSessionAttributes(sessionIdAttributes);
447  sessionId.setLastUsedAt(new Date());
448 
449  if (sessionId.getIsJwt()) {
450  sessionId.setJwt(generateJwt(sessionId, userDn).asString());
451  }
452 
453  boolean persisted = false;
454  if (persist) {
455  persisted = persistSessionId(sessionId);
456  }
457 
458  auditLogging(sessionId);
459 
460  log.trace("Generated new session, id = '{}', state = '{}', asJwt = '{}', persisted = '{}'", sessionId.getId(), sessionId.getState(), sessionId.getIsJwt(), persisted);
461  return sessionId;
462  }
Logger log
Definition: SessionIdService.java:77
boolean persistSessionId(final SessionId sessionId)
Definition: SessionIdService.java:510
String dn(String p_id)
Definition: SessionIdService.java:643
Boolean getSessionAsJwt()
Definition: AppConfiguration.java:229
Jwt generateJwt(SessionId sessionId, String audience)
Definition: SessionIdService.java:464
void auditLogging(SessionId sessionId)
Definition: SessionIdService.java:770
AppConfiguration appConfiguration
Definition: SessionIdService.java:89

◆ generateUnauthenticatedSessionId() [1/2]

SessionId org.xdi.oxauth.service.SessionIdService.generateUnauthenticatedSessionId ( String  userDn)
inline
405  {
406  Map<String, String> sessionIdAttributes = new HashMap<String, String>();
407  return generateSessionId(userDn, new Date(), SessionIdState.UNAUTHENTICATED, sessionIdAttributes, true);
408  }
SessionId generateSessionId(String userDn, Date authenticationDate, SessionIdState state, Map< String, String > sessionIdAttributes, boolean persist)
Definition: SessionIdService.java:414

◆ generateUnauthenticatedSessionId() [2/2]

SessionId org.xdi.oxauth.service.SessionIdService.generateUnauthenticatedSessionId ( String  userDn,
Date  authenticationDate,
SessionIdState  state,
Map< String, String >  sessionIdAttributes,
boolean  persist 
)
inline
410  {
411  return generateSessionId(userDn, authenticationDate, state, sessionIdAttributes, persist);
412  }
SessionId generateSessionId(String userDn, Date authenticationDate, SessionIdState state, Map< String, String > sessionIdAttributes, boolean persist)
Definition: SessionIdService.java:414

◆ getAcr()

String org.xdi.oxauth.service.SessionIdService.getAcr ( SessionId  session)
inline
109  {
110  if (session == null || session.getSessionAttributes() == null) {
111  return null;
112  }
113 
114  String acr = session.getSessionAttributes().get(JwtClaimName.AUTHENTICATION_CONTEXT_CLASS_REFERENCE);
115  if (StringUtils.isBlank(acr)) {
116  acr = session.getSessionAttributes().get("acr_values");
117  }
118  return acr;
119  }

◆ getBaseDn()

String org.xdi.oxauth.service.SessionIdService.getBaseDn ( )
inlineprivate
679  {
681  }
StaticConfiguration staticConfiguration
Definition: SessionIdService.java:92
String getSessionId()
Definition: BaseDnConfiguration.java:125
BaseDnConfiguration getBaseDn()
Definition: StaticConfiguration.java:32

◆ getConsentSessionIdFromCookie()

String org.xdi.oxauth.service.SessionIdService.getConsentSessionIdFromCookie ( HttpServletRequest  request)
inline
245  {
247  }
static final String CONSENT_SESSION_ID_COOKIE_NAME
Definition: SessionIdService.java:73
String getSessionIdFromCookie()
Definition: SessionIdService.java:266

◆ getCurrentSessionAttributes()

Map<String, String> org.xdi.oxauth.service.SessionIdService.getCurrentSessionAttributes ( Map< String, String >  sessionAttributes)
inlineprivate
216  {
217  // Update from request
218  if (facesContext != null) {
219  // Clone before replacing new attributes
220  final Map<String, String> currentSessionAttributes = new HashMap<String, String>(sessionAttributes);
221 
222  Map<String, String> parameterMap = externalContext.getRequestParameterMap();
223  Map<String, String> newRequestParameterMap = requestParameterService.getAllowedParameters(parameterMap);
224  for (Entry<String, String> newRequestParameterMapEntry : newRequestParameterMap.entrySet()) {
225  String name = newRequestParameterMapEntry.getKey();
226  if (!StringHelper.equalsIgnoreCase(name, "auth_step")) {
227  currentSessionAttributes.put(name, newRequestParameterMapEntry.getValue());
228  }
229  }
230 
231  return currentSessionAttributes;
232  } else {
233  return sessionAttributes;
234  }
235  }
ExternalContext externalContext
Definition: SessionIdService.java:101
Map< String, String > getAllowedParameters(@Nonnull final Map< String, String > requestParameterMap)
Definition: RequestParameterService.java:81
FacesContext facesContext
Definition: SessionIdService.java:98
RequestParameterService requestParameterService
Definition: SessionIdService.java:107

◆ getFromCache()

SessionId org.xdi.oxauth.service.SessionIdService.getFromCache ( String  sessionId)
inlineprivate
601  {
602  return (SessionId) cacheService.get(null, sessionId);
603  }
CacheService cacheService
Definition: SessionIdService.java:104

◆ getPromptsFromSessionId()

List<Prompt> org.xdi.oxauth.service.SessionIdService.getPromptsFromSessionId ( final SessionId  sessionId)
inlineprivate
723  {
724  String promptParam = sessionId.getSessionAttributes().get("prompt");
725  return Prompt.fromString(promptParam, " ");
726  }

◆ getSessionAttributes()

Map<String, String> org.xdi.oxauth.service.SessionIdService.getSessionAttributes ( SessionId  sessionId)
inline
370  {
371  if (sessionId != null) {
372  return sessionId.getSessionAttributes();
373  }
374 
375  return null;
376  }

◆ getSessionById()

SessionId org.xdi.oxauth.service.SessionIdService.getSessionById ( String  sessionId)
inline
652  {
653  return getFromCache(sessionId);
654  }
SessionId getFromCache(String sessionId)
Definition: SessionIdService.java:601

◆ getSessionId() [1/2]

SessionId org.xdi.oxauth.service.SessionIdService.getSessionId ( )
inline
360  {
361  String sessionId = getSessionIdFromCookie();
362 
363  if (StringHelper.isNotEmpty(sessionId)) {
364  return getSessionId(sessionId);
365  }
366 
367  return null;
368  }
SessionId getSessionId()
Definition: SessionIdService.java:360
String getSessionIdFromCookie()
Definition: SessionIdService.java:266

◆ getSessionId() [2/2]

SessionId org.xdi.oxauth.service.SessionIdService.getSessionId ( String  sessionId)
inline
656  {
657  if (StringHelper.isEmpty(sessionId)) {
658  return null;
659  }
660 
661  try {
662  final SessionId entity = getSessionById(sessionId);
663  log.trace("Try to get session by id: {} ...", sessionId);
664  if (entity != null) {
665  log.trace("Session dn: {}", entity.getDn());
666 
667  if (isSessionValid(entity)) {
668  return entity;
669  }
670  }
671  } catch (Exception ex) {
672  log.trace(ex.getMessage(), ex);
673  }
674 
675  log.trace("Failed to get session by id: {}", sessionId);
676  return null;
677  }
Logger log
Definition: SessionIdService.java:77
SessionId getSessionById(String sessionId)
Definition: SessionIdService.java:652
boolean isSessionValid(SessionId sessionId)
Definition: SessionIdService.java:704

◆ getSessionIdFromCookie() [1/3]

String org.xdi.oxauth.service.SessionIdService.getSessionIdFromCookie ( HttpServletRequest  request)
inline
237  {
239  }
static final String SESSION_ID_COOKIE_NAME
Definition: SessionIdService.java:71
String getSessionIdFromCookie()
Definition: SessionIdService.java:266

◆ getSessionIdFromCookie() [2/3]

String org.xdi.oxauth.service.SessionIdService.getSessionIdFromCookie ( HttpServletRequest  request,
String  cookieName 
)
inline
249  {
250  try {
251  final Cookie[] cookies = request.getCookies();
252  if (cookies != null) {
253  for (Cookie cookie : cookies) {
254  if (cookie.getName().equals(cookieName) /*&& cookie.getSecure()*/) {
255  log.trace("Found session_id cookie: '{}'", cookie.getValue());
256  return cookie.getValue();
257  }
258  }
259  }
260  } catch (Exception e) {
261  log.error(e.getMessage(), e);
262  }
263  return "";
264  }
Logger log
Definition: SessionIdService.java:77

◆ getSessionIdFromCookie() [3/3]

String org.xdi.oxauth.service.SessionIdService.getSessionIdFromCookie ( )
inline
266  {
267  try {
268  if (facesContext == null) {
269  return null;
270  }
271  final HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
272  if (request != null) {
273  return getSessionIdFromCookie(request);
274  } else {
275  log.error("Faces context returns null for http request object.");
276  }
277  } catch (Exception e) {
278  log.error(e.getMessage(), e);
279  }
280 
281  return null;
282  }
ExternalContext externalContext
Definition: SessionIdService.java:101
Logger log
Definition: SessionIdService.java:77
FacesContext facesContext
Definition: SessionIdService.java:98
String getSessionIdFromCookie()
Definition: SessionIdService.java:266

◆ getUmaSessionIdFromCookie()

String org.xdi.oxauth.service.SessionIdService.getUmaSessionIdFromCookie ( HttpServletRequest  request)
inline
241  {
243  }
static final String UMA_SESSION_ID_COOKIE_NAME
Definition: SessionIdService.java:72
String getSessionIdFromCookie()
Definition: SessionIdService.java:266

◆ isNotSessionIdAuthenticated()

boolean org.xdi.oxauth.service.SessionIdService.isNotSessionIdAuthenticated ( )
inline
749  {
750  return !isSessionIdAuthenticated();
751  }
boolean isSessionIdAuthenticated()
Definition: SessionIdService.java:729

◆ isPersisted()

boolean org.xdi.oxauth.service.SessionIdService.isPersisted ( List< Prompt prompts)
inlineprivate
635  {
636  if (prompts != null && prompts.contains(Prompt.NONE)) {
637  final Boolean persistOnPromptNone = appConfiguration.getSessionIdPersistOnPromptNone();
638  return persistOnPromptNone != null && persistOnPromptNone;
639  }
640  return true;
641  }
Boolean getSessionIdPersistOnPromptNone()
Definition: AppConfiguration.java:1041
AppConfiguration appConfiguration
Definition: SessionIdService.java:89

◆ isSessionIdAuthenticated() [1/2]

boolean org.xdi.oxauth.service.SessionIdService.isSessionIdAuthenticated ( )
inline
729  {
730  SessionId sessionId = getSessionId();
731 
732  return isSessionIdAuthenticated(sessionId);
733  }
SessionId getSessionId()
Definition: SessionIdService.java:360
boolean isSessionIdAuthenticated()
Definition: SessionIdService.java:729

◆ isSessionIdAuthenticated() [2/2]

boolean org.xdi.oxauth.service.SessionIdService.isSessionIdAuthenticated ( SessionId  sessionId)
inline
735  {
736  if (sessionId == null) {
737  return false;
738  }
739 
740  SessionIdState sessionIdState = sessionId.getState();
741 
742  if (SessionIdState.AUTHENTICATED.equals(sessionIdState)) {
743  return true;
744  }
745 
746  return false;
747  }

◆ isSessionValid()

boolean org.xdi.oxauth.service.SessionIdService.isSessionValid ( SessionId  sessionId)
inline
704  {
705  if (sessionId == null) {
706  return false;
707  }
708 
709  final long sessionInterval = TimeUnit.SECONDS.toMillis(appConfiguration.getSessionIdUnusedLifetime());
710  final long sessionUnauthenticatedInterval = TimeUnit.SECONDS.toMillis(appConfiguration.getSessionIdUnauthenticatedUnusedLifetime());
711 
712  final long timeSinceLastAccess = System.currentTimeMillis() - sessionId.getLastUsedAt().getTime();
713  if (timeSinceLastAccess > sessionInterval && appConfiguration.getSessionIdUnusedLifetime() != -1) {
714  return false;
715  }
716  if (sessionId.getState() == SessionIdState.UNAUTHENTICATED && timeSinceLastAccess > sessionUnauthenticatedInterval && appConfiguration.getSessionIdUnauthenticatedUnusedLifetime() != -1) {
717  return false;
718  }
719 
720  return true;
721  }
int getSessionIdUnauthenticatedUnusedLifetime()
Definition: AppConfiguration.java:1033
int getSessionIdUnusedLifetime()
Definition: AppConfiguration.java:1025
AppConfiguration appConfiguration
Definition: SessionIdService.java:89

◆ mergeWithRetry()

SessionId org.xdi.oxauth.service.SessionIdService.mergeWithRetry ( final SessionId  sessionId,
int  maxAttempts 
)
inlineprivate
605  {
606  EntryPersistenceException lastException = null;
607  for (int i = 1; i <= maxAttempts; i++) {
608  try {
609  putInCache(sessionId);
610  return sessionId;
611  } catch (EntryPersistenceException ex) {
612  lastException = ex;
613  if (ex.getCause() instanceof LDAPException) {
614  LDAPException parentEx = ((LDAPException) ex.getCause());
615  log.debug("LDAP exception resultCode: '{}'", parentEx.getResultCode().intValue());
616  if ((parentEx.getResultCode().intValue() == ResultCode.NO_SUCH_ATTRIBUTE_INT_VALUE) ||
617  (parentEx.getResultCode().intValue() == ResultCode.ATTRIBUTE_OR_VALUE_EXISTS_INT_VALUE)) {
618  log.warn("Session entry update attempt '{}' was unsuccessfull", i);
619  continue;
620  }
621  }
622 
623  throw ex;
624  }
625  }
626 
627  log.error("Session entry update attempt was unsuccessfull after '{}' attempts", maxAttempts);
628  throw lastException;
629  }
Logger log
Definition: SessionIdService.java:77
void putInCache(SessionId sessionId)
Definition: SessionIdService.java:594

◆ persistSessionId() [1/2]

boolean org.xdi.oxauth.service.SessionIdService.persistSessionId ( final SessionId  sessionId)
inline
510  {
511  return persistSessionId(sessionId, false);
512  }
boolean persistSessionId(final SessionId sessionId)
Definition: SessionIdService.java:510

◆ persistSessionId() [2/2]

boolean org.xdi.oxauth.service.SessionIdService.persistSessionId ( final SessionId  sessionId,
boolean  forcePersistence 
)
inline
514  {
515  List<Prompt> prompts = getPromptsFromSessionId(sessionId);
516 
517  try {
518  final int unusedLifetime = appConfiguration.getSessionIdUnusedLifetime();
519  if ((unusedLifetime > 0 && isPersisted(prompts)) || forcePersistence) {
520  sessionId.setLastUsedAt(new Date());
521 
522  sessionId.setPersisted(true);
523  log.trace("sessionIdAttributes: " + sessionId.getPermissionGrantedMap());
524  putInCache(sessionId);
525  return true;
526  }
527  } catch (Exception e) {
528  log.error(e.getMessage(), e);
529  }
530 
531  return false;
532  }
Logger log
Definition: SessionIdService.java:77
List< Prompt > getPromptsFromSessionId(final SessionId sessionId)
Definition: SessionIdService.java:723
boolean isPersisted(List< Prompt > prompts)
Definition: SessionIdService.java:635
int getSessionIdUnusedLifetime()
Definition: AppConfiguration.java:1025
void putInCache(SessionId sessionId)
Definition: SessionIdService.java:594
AppConfiguration appConfiguration
Definition: SessionIdService.java:89

◆ putInCache()

void org.xdi.oxauth.service.SessionIdService.putInCache ( SessionId  sessionId)
inlineprivate
594  {
595  int expirationInSeconds = sessionId.getState() == SessionIdState.UNAUTHENTICATED ?
597  appConfiguration.getSessionIdLifetime() != null && appConfiguration.getSessionIdLifetime() > 0 ? appConfiguration.getSessionIdLifetime() : Integer.MAX_VALUE; // we don't know for how long we can put it in cache since expiration is not set for session id, so we set it to max integer.
598  cacheService.put(Integer.toString(expirationInSeconds), sessionId.getId(), sessionId); // first parameter is expiration instead of region for memcached
599  }
Integer getSessionIdLifetime()
Definition: AppConfiguration.java:1345
int getSessionIdUnauthenticatedUnusedLifetime()
Definition: AppConfiguration.java:1033
CacheService cacheService
Definition: SessionIdService.java:104
AppConfiguration appConfiguration
Definition: SessionIdService.java:89

◆ refreshSessionId()

void org.xdi.oxauth.service.SessionIdService.refreshSessionId ( )
inline
790  {
791  SessionId sessionId = getSessionId();
792  if (sessionId != null) {
793  updateSessionId(sessionId, true, true, true);
794  }
795  }
SessionId getSessionId()
Definition: SessionIdService.java:360
boolean updateSessionId(final SessionId sessionId)
Definition: SessionIdService.java:534

◆ reinitLogin()

void org.xdi.oxauth.service.SessionIdService.reinitLogin ( SessionId  session,
boolean  force 
)
inline
169  {
170  final Map<String, String> sessionAttributes = session.getSessionAttributes();
171  final Map<String, String> currentSessionAttributes = getCurrentSessionAttributes(sessionAttributes);
172  if (force || !currentSessionAttributes.equals(sessionAttributes)) {
173  sessionAttributes.putAll(currentSessionAttributes);
174 
175  // Reinit login
176  sessionAttributes.put("c", "1");
177 
178  for (Iterator<Entry<String, String>> it = currentSessionAttributes.entrySet().iterator(); it.hasNext(); ) {
179  Entry<String, String> currentSessionAttributesEntry = it.next();
180  String name = currentSessionAttributesEntry.getKey();
181  if (name.startsWith("auth_step_passed_")) {
182  it.remove();
183  }
184  }
185 
186  session.setSessionAttributes(currentSessionAttributes);
187 
188  boolean updateResult = updateSessionId(session, true, true, true);
189  if (!updateResult) {
190  log.debug("Failed to update session entry: '{}'", session.getId());
191  }
192  }
193  }
Logger log
Definition: SessionIdService.java:77
Map< String, String > getCurrentSessionAttributes(Map< String, String > sessionAttributes)
Definition: SessionIdService.java:216
boolean updateSessionId(final SessionId sessionId)
Definition: SessionIdService.java:534

◆ remove() [1/2]

boolean org.xdi.oxauth.service.SessionIdService.remove ( SessionId  sessionId)
inline
683  {
684  try {
685  cacheService.remove(null, sessionId.getId());
686  } catch (Exception e) {
687  log.error(e.getMessage(), e);
688 
689  return false;
690  }
691  return true;
692  }
Logger log
Definition: SessionIdService.java:77
CacheService cacheService
Definition: SessionIdService.java:104

◆ remove() [2/2]

void org.xdi.oxauth.service.SessionIdService.remove ( List< SessionId list)
inline
694  {
695  for (SessionId id : list) {
696  try {
697  remove(id);
698  } catch (Exception e) {
699  log.error("Failed to remove entry", e);
700  }
701  }
702  }
Logger log
Definition: SessionIdService.java:77

◆ removeConsentSessionIdCookie()

void org.xdi.oxauth.service.SessionIdService.removeConsentSessionIdCookie ( HttpServletResponse  httpResponse)
inline
353  {
354  final Cookie cookie = new Cookie(CONSENT_SESSION_ID_COOKIE_NAME, null); // Not necessary, but saves bandwidth.
355  cookie.setPath("/");
356  cookie.setMaxAge(0); // Don't set to -1 or it will become a session cookie!
357  httpResponse.addCookie(cookie);
358  }
static final String CONSENT_SESSION_ID_COOKIE_NAME
Definition: SessionIdService.java:73

◆ removeSessionIdCookie()

void org.xdi.oxauth.service.SessionIdService.removeSessionIdCookie ( HttpServletResponse  httpResponse)
inline
339  {
340  final Cookie cookie = new Cookie(SESSION_ID_COOKIE_NAME, null); // Not necessary, but saves bandwidth.
341  cookie.setPath("/");
342  cookie.setMaxAge(0); // Don't set to -1 or it will become a session cookie!
343  httpResponse.addCookie(cookie);
344  }
static final String SESSION_ID_COOKIE_NAME
Definition: SessionIdService.java:71

◆ removeUmaSessionIdCookie()

void org.xdi.oxauth.service.SessionIdService.removeUmaSessionIdCookie ( HttpServletResponse  httpResponse)
inline
346  {
347  final Cookie cookie = new Cookie(UMA_SESSION_ID_COOKIE_NAME, null); // Not necessary, but saves bandwidth.
348  cookie.setPath("/");
349  cookie.setMaxAge(0); // Don't set to -1 or it will become a session cookie!
350  httpResponse.addCookie(cookie);
351  }
static final String UMA_SESSION_ID_COOKIE_NAME
Definition: SessionIdService.java:72

◆ resetToStep()

void org.xdi.oxauth.service.SessionIdService.resetToStep ( SessionId  session,
int  resetToStep 
)
inline
195  {
196  final Map<String, String> sessionAttributes = session.getSessionAttributes();
197 
198  int currentStep = 1;
199  if (sessionAttributes.containsKey("auth_step")) {
200  currentStep = StringHelper.toInteger(sessionAttributes.get("auth_step"), currentStep);
201  }
202 
203  for (int i = resetToStep; i <= currentStep; i++) {
204  String key = String.format("auth_step_passed_%d", i);
205  sessionAttributes.remove(key);
206  }
207 
208  sessionAttributes.put("auth_step", String.valueOf(resetToStep));
209 
210  boolean updateResult = updateSessionId(session, true, true, true);
211  if (!updateResult) {
212  log.debug("Failed to update session entry: '{}'", session.getId());
213  }
214  }
Logger log
Definition: SessionIdService.java:77
boolean updateSessionId(final SessionId sessionId)
Definition: SessionIdService.java:534
void resetToStep(SessionId session, int resetToStep)
Definition: SessionIdService.java:195

◆ setSessionIdStateAuthenticated()

SessionId org.xdi.oxauth.service.SessionIdService.setSessionIdStateAuthenticated ( HttpServletRequest  httpRequest,
SessionId  sessionId,
String  p_userDn 
)
inline
491  {
492  sessionId.setUserDn(p_userDn);
493  sessionId.setAuthenticationTime(new Date());
494  sessionId.setState(SessionIdState.AUTHENTICATED);
495 
496  boolean persisted = updateSessionId(sessionId, true, true, true);
497 
498  auditLogging(sessionId);
499  log.trace("Authenticated session, id = '{}', state = '{}', persisted = '{}'", sessionId.getId(), sessionId.getState(), persisted);
500 
501  if (externalApplicationSessionService.isEnabled()) {
502  String userName = sessionId.getSessionAttributes().get(Constants.AUTHENTICATED_USER);
503  boolean externalResult = externalApplicationSessionService.executeExternalStartSessionMethods(httpRequest, sessionId);
504  log.info("Start session result for '{}': '{}'", userName, "start", externalResult);
505  }
506 
507  return sessionId;
508  }
boolean executeExternalStartSessionMethods(HttpServletRequest httpRequest, SessionId sessionId)
Definition: ExternalApplicationSessionService.java:54
Logger log
Definition: SessionIdService.java:77
ExternalApplicationSessionService externalApplicationSessionService
Definition: SessionIdService.java:83
void auditLogging(SessionId sessionId)
Definition: SessionIdService.java:770
boolean updateSessionId(final SessionId sessionId)
Definition: SessionIdService.java:534

◆ updateSessionId() [1/3]

boolean org.xdi.oxauth.service.SessionIdService.updateSessionId ( final SessionId  sessionId)
inline
534  {
535  return updateSessionId(sessionId, true);
536  }
boolean updateSessionId(final SessionId sessionId)
Definition: SessionIdService.java:534

◆ updateSessionId() [2/3]

boolean org.xdi.oxauth.service.SessionIdService.updateSessionId ( final SessionId  sessionId,
boolean  updateLastUsedAt 
)
inline
538  {
539  return updateSessionId(sessionId, updateLastUsedAt, false, true);
540  }
boolean updateSessionId(final SessionId sessionId)
Definition: SessionIdService.java:534

◆ updateSessionId() [3/3]

boolean org.xdi.oxauth.service.SessionIdService.updateSessionId ( final SessionId  sessionId,
boolean  updateLastUsedAt,
boolean  forceUpdate,
boolean  modified 
)
inline
542  {
543  List<Prompt> prompts = getPromptsFromSessionId(sessionId);
544 
545  try {
546  final int unusedLifetime = appConfiguration.getSessionIdUnusedLifetime();
547  if ((unusedLifetime > 0 && isPersisted(prompts)) || forceUpdate) {
548  boolean update = modified;
549 
550  if (updateLastUsedAt) {
551  Date lastUsedAt = new Date();
552  if (sessionId.getLastUsedAt() != null) {
553  long diff = lastUsedAt.getTime() - sessionId.getLastUsedAt().getTime();
554  if (diff > 500) { // update only if diff is more than 500ms
555  update = true;
556  sessionId.setLastUsedAt(lastUsedAt);
557  }
558  } else {
559  update = true;
560  sessionId.setLastUsedAt(lastUsedAt);
561  }
562  }
563 
564  if (!sessionId.isPersisted()) {
565  update = true;
566  sessionId.setPersisted(true);
567  }
568 
569  if (sessionId.getAuthenticationTime() != null) {
570  final long currentLifetimeInSeconds = (System.currentTimeMillis() - sessionId.getAuthenticationTime().getTime()) / 1000;
572  if (currentLifetimeInSeconds > appConfiguration.getSessionIdLifetime()) {
573  log.debug("Session id expired: {}, remove it.", sessionId.getId());
574  remove(sessionId); // expired
575  update = false;
576  }
577  } else {
578  log.debug("Session id lifetime configuration is null.");
579  }
580  }
581 
582  if (update) {
583  mergeWithRetry(sessionId, 3);
584  }
585  }
586  } catch (Exception e) {
587  log.error(e.getMessage(), e);
588  return false;
589  }
590 
591  return true;
592  }
Integer getSessionIdLifetime()
Definition: AppConfiguration.java:1345
Logger log
Definition: SessionIdService.java:77
List< Prompt > getPromptsFromSessionId(final SessionId sessionId)
Definition: SessionIdService.java:723
SessionId mergeWithRetry(final SessionId sessionId, int maxAttempts)
Definition: SessionIdService.java:605
boolean isPersisted(List< Prompt > prompts)
Definition: SessionIdService.java:635
int getSessionIdUnusedLifetime()
Definition: AppConfiguration.java:1025
AppConfiguration appConfiguration
Definition: SessionIdService.java:89

◆ updateSessionIdIfNeeded()

void org.xdi.oxauth.service.SessionIdService.updateSessionIdIfNeeded ( SessionId  sessionId,
boolean  modified 
)
inline
631  {
632  updateSessionId(sessionId, true, false, modified);
633  }
boolean updateSessionId(final SessionId sessionId)
Definition: SessionIdService.java:534

メンバ詳解

◆ appConfiguration

AppConfiguration org.xdi.oxauth.service.SessionIdService.appConfiguration
private

◆ applicationAuditLogger

ApplicationAuditLogger org.xdi.oxauth.service.SessionIdService.applicationAuditLogger
private

◆ cacheService

CacheService org.xdi.oxauth.service.SessionIdService.cacheService
private

◆ CONSENT_SESSION_ID_COOKIE_NAME

final String org.xdi.oxauth.service.SessionIdService.CONSENT_SESSION_ID_COOKIE_NAME = "consent_session_id"
static

◆ externalApplicationSessionService

ExternalApplicationSessionService org.xdi.oxauth.service.SessionIdService.externalApplicationSessionService
private

◆ externalAuthenticationService

ExternalAuthenticationService org.xdi.oxauth.service.SessionIdService.externalAuthenticationService
private

◆ externalContext

ExternalContext org.xdi.oxauth.service.SessionIdService.externalContext
private

◆ facesContext

FacesContext org.xdi.oxauth.service.SessionIdService.facesContext
private

◆ log

Logger org.xdi.oxauth.service.SessionIdService.log
private

◆ requestParameterService

RequestParameterService org.xdi.oxauth.service.SessionIdService.requestParameterService
private

◆ SESSION_CUSTOM_STATE

final String org.xdi.oxauth.service.SessionIdService.SESSION_CUSTOM_STATE = "session_custom_state"
static

◆ SESSION_ID_COOKIE_NAME

final String org.xdi.oxauth.service.SessionIdService.SESSION_ID_COOKIE_NAME = "session_id"
static

◆ SESSION_STATE_COOKIE_NAME

final String org.xdi.oxauth.service.SessionIdService.SESSION_STATE_COOKIE_NAME = "session_state"
static

◆ staticConfiguration

StaticConfiguration org.xdi.oxauth.service.SessionIdService.staticConfiguration
private

◆ UMA_SESSION_ID_COOKIE_NAME

final String org.xdi.oxauth.service.SessionIdService.UMA_SESSION_ID_COOKIE_NAME = "uma_session_id"
static

◆ webKeysConfiguration

WebKeysConfiguration org.xdi.oxauth.service.SessionIdService.webKeysConfiguration
private

このクラス詳解は次のファイルから抽出されました: