protected void incrementQueryKey() { queryKey = userSession.getAttribute("_queryKey"); if (queryKey == null) queryKey = 1; else queryKey++; userSession.setAttribute("_queryKey", queryKey); }
protected void setSessionAttributes(Credentials credentials, AuthenticationDetails authenticationDetails) { if (credentials instanceof SessionAttributesProvider) { Map<String, Serializable> sessionAttributes = ((SessionAttributesProvider) credentials).getSessionAttributes(); if (sessionAttributes != null) { UserSession session = authenticationDetails.getSession(); for (Map.Entry<String, Serializable> attribute : sessionAttributes.entrySet()) { session.setAttribute(attribute.getKey(), attribute.getValue()); } } } }
@Override public void setAttribute(String name, Serializable value) { super.setAttribute(name, value); if (authenticated) { UserSessionService uss = AppBeans.get(UserSessionService.NAME); uss.setSessionAttribute(id, name, value); } }
protected int getNextQueryKey() { UserSession userSession = userSessionSource.getUserSession(); Integer queryKey = userSession.getAttribute("_queryKey"); if (queryKey == null) queryKey = 1; else queryKey++; userSession.setAttribute("_queryKey", queryKey); return queryKey; } }
@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 10) @EventListener protected void onSessionSubstituted(UserSessionSubstitutedEvent event) { if (webAuthConfig.getExternalAuthentication() && isLoggedInWithExternalAuth(event.getSourceSession())) { event.getSubstitutedSession().setAttribute(EXTERNAL_AUTH_USER_SESSION_ATTRIBUTE, true); } }
@Override public void userSessionLoggedIn(UserSession session) { RequestContext requestContext = RequestContext.get(); if (requestContext != null) { Principal principal = requestContext.getRequest().getUserPrincipal(); if (principal instanceof IdpSessionPrincipal) { IdpSession idpSession = ((IdpSessionPrincipal) principal).getIdpSession(); session.setAttribute(IdpService.IDP_USER_SESSION_ATTRIBUTE, idpSession.getId()); } } }
@Override public void setSessionAttribute(UUID sessionId, String name, Serializable value) { UserSession userSession = userSessions.getNN(sessionId); checkSession(userSession); userSession.setAttribute(name, value); userSessions.propagate(sessionId); }
protected boolean resultsAlreadySaved(Integer queryKey, LoadContext.Query query) { LinkedHashMap<Integer, QueryHolder> recentQueries = userSessionSource.getUserSession().getAttribute("_recentQueries"); if (recentQueries == null) { recentQueries = new LinkedHashMap<Integer, QueryHolder>() { private static final long serialVersionUID = -901296839279897248L; @Override protected boolean removeEldestEntry(Map.Entry<Integer, QueryHolder> eldest) { return size() > 10; } }; } QueryHolder queryHolder = new QueryHolder(query); QueryHolder oldQueryHolder = recentQueries.put(queryKey, queryHolder); // do not set to session attribute recentQueries directly, it contains reference to QueryResultsManager class // copy data to new LinkedHashMap userSessionSource.getUserSession().setAttribute("_recentQueries", new LinkedHashMap<>(recentQueries)); return queryHolder.equals(oldQueryHolder); }
@Override public void postMessage(List<UUID> sessionIds, String message) { long time = timeSource.currentTimeMillis(); for (UUID sessionId : sessionIds) { UserSession userSession = userSessions.get(sessionId); if (userSession != null && !userSession.isSystem()) { userSession.setAttribute(MESSAGE_ATTR_PREFIX + time, message); userSessions.propagate(sessionId); } } }
@SuppressWarnings("RedundantThrows") @Nullable @Override public AuthenticationDetails login(Credentials credentials) throws LoginException { if (!(credentials instanceof AnonymousUserCredentials)) { throw new ClassCastException("Credentials cannot be cast to AnonymousUserCredentials"); } AnonymousUserCredentials anonymousCredentials = (AnonymousUserCredentials) credentials; UserSession anonymousSession = anonymousSessionHolder.getAnonymousSession(); Locale credentialsLocale = anonymousCredentials.getLocale(); if (credentialsLocale != null) { anonymousSession.setLocale(credentialsLocale); } if (anonymousCredentials.getTimeZone() != null && Boolean.TRUE.equals(anonymousSession.getUser().getTimeZoneAuto())) { anonymousSession.setTimeZone(anonymousCredentials.getTimeZone()); } anonymousSession.setAddress(anonymousCredentials.getIpAddress()); anonymousSession.setClientInfo(anonymousCredentials.getClientInfo()); if (anonymousCredentials.getSessionAttributes() != null) { for (Map.Entry<String, Serializable> attribute : anonymousCredentials.getSessionAttributes().entrySet()) { anonymousSession.setAttribute(attribute.getKey(), attribute.getValue()); } } return new SimpleAuthenticationDetails(anonymousSession); }
protected void compileSessionAttributes(UserSession session, Group group) { List<SessionAttribute> list = new ArrayList<>(group.getSessionAttributes()); EntityManager em = persistence.getEntityManager(); TypedQuery<SessionAttribute> q = em.createQuery("select a from sec$GroupHierarchy h join h.parent.sessionAttributes a " + "where h.group.id = ?1 order by h.level desc", SessionAttribute.class); q.setParameter(1, group.getId()); List<SessionAttribute> attributes = q.getResultList(); list.addAll(attributes); for (SessionAttribute attribute : list) { Datatype datatype = Datatypes.get(attribute.getDatatype()); try { if (session.getAttributeNames().contains(attribute.getName())) { log.warn("Duplicate definition of '{}' session attribute in the group hierarchy", attribute.getName()); } Serializable value = (Serializable) datatype.parse(attribute.getStringValue()); if (value != null) session.setAttribute(attribute.getName(), value); else session.removeAttribute(attribute.getName()); } catch (ParseException e) { throw new RuntimeException("Unable to set session attribute " + attribute.getName(), e); } } }