/** * Immediately delegates to the underlying proxied session. */ public Object getAttribute(Object key) throws InvalidSessionException { return delegate.getAttribute(key); }
private byte[] serializeSessionData(final Session session) throws IOException { final Map<Object, Object> sessionAttributes = new HashMap<Object, Object>(); for (final Object key : session.getAttributeKeys()) { sessionAttributes.put(key, session.getAttribute(key)); } return serializer.serialize(sessionAttributes); } }
@SuppressWarnings({"unchecked"}) private T castSessionAttribute(Session session) { return (T) session.getAttribute(key); }
@Override protected Serializable doCreate(Session session) { final Serializable id = generateSessionId(session); assignSessionId(session, id); Map<String, Object> fields = Maps.newHashMap(); fields.put("session_id", id); fields.put("host", session.getHost()); fields.put("start_timestamp", session.getStartTimestamp()); fields.put("last_access_time", session.getLastAccessTime()); fields.put("timeout", session.getTimeout()); Map<String, Object> attributes = Maps.newHashMap(); for (Object key : session.getAttributeKeys()) { attributes.put(key.toString(), session.getAttribute(key)); } fields.put("attributes", attributes); final MongoDbSession dbSession = new MongoDbSession(fields); final String objectId = mongoDBSessionService.saveWithoutValidation(dbSession); LOG.debug("Created session {}", objectId); return id; }
public void onStop(Session session) { stopped[0] = true; value[0] = (String)session.getAttribute("foo"); } };
public Object getAttribute(String s) { try { return getSession().getAttribute(s); } catch (InvalidSessionException e) { throw new IllegalStateException(e); } }
public static SavedRequest getSavedRequest(ServletRequest request) { SavedRequest savedRequest = null; Subject subject = SecurityUtils.getSubject(); Session session = subject.getSession(false); if (session != null) { savedRequest = (SavedRequest) session.getAttribute(SAVED_REQUEST_KEY); } return savedRequest; }
@SuppressWarnings("unchecked") private List<PrincipalCollection> getRunAsPrincipalsStack() { Session session = getSession(false); if (session != null) { return (List<PrincipalCollection>) session.getAttribute(RUN_AS_PRINCIPALS_SESSION_KEY); } return null; }
/** * 获取shiro指定的sessionKey */ @SuppressWarnings("unchecked") public static <T> T getSessionAttr(String key) { Session session = getSession(); return session != null ? (T) session.getAttribute(key) : null; }
@Override protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { Session session = getSubject(request, response).getSession(false); if(session == null) { return true; } boolean forceout = session.getAttribute("FORCE_LOGOUT") == null; return forceout; }
public Object getAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException { return lookupRequiredSession(sessionKey).getAttribute(attributeKey); }
public static BiMap<UUID, String> getOrganizations() { Subject currentUser = getSubject(); if ( !isOrganizationAdmin() ) { return null; } Session session = currentUser.getSession(); BiMap<UUID, String> organizations = HashBiMap.create(); Map map = (Map)session.getAttribute( "organizations" ); organizations.putAll(map); return organizations; }
public static OrganizationInfo getOrganization() { Subject currentUser = getSubject(); if ( currentUser == null ) { return null; } if ( !currentUser.hasRole( ROLE_ORGANIZATION_ADMIN ) ) { return null; } Session session = currentUser.getSession(); OrganizationInfo organization = ( OrganizationInfo ) session.getAttribute( "organization" ); return organization; }
public boolean resolveAuthenticated() { Boolean authc = getTypedValue(AUTHENTICATED, Boolean.class); if (authc == null) { //see if there is an AuthenticationInfo object. If so, the very presence of one indicates a successful //authentication attempt: AuthenticationInfo info = getAuthenticationInfo(); authc = info != null; } if (!authc) { //fall back to a session check: Session session = resolveSession(); if (session != null) { Boolean sessionAuthc = (Boolean) session.getAttribute(AUTHENTICATED_SESSION_KEY); authc = sessionAuthc != null && sessionAuthc; } } return authc; }
@SuppressWarnings( "unchecked" ) public static BiMap<UUID, String> getApplications() { Subject currentUser = getSubject(); if ( currentUser == null ) { return null; } if ( !currentUser.hasRole( ROLE_APPLICATION_ADMIN ) && !currentUser.hasRole( ROLE_APPLICATION_USER ) ) { return null; } Session session = currentUser.getSession(); BiMap<UUID, String> applications = HashBiMap.create(); Map map = (Map)session.getAttribute( "applications" ); applications.putAll(map); return applications; }
@Override protected void doDelete(Session session) { String sessionId = session.getId().toString(); String upmsType = ObjectUtils.toString(session.getAttribute(UpmsConstant.UPMS_TYPE)); if ("client".equals(upmsType)) {
public static String getOrganizationName() { Subject currentUser = getSubject(); if ( currentUser == null ) { return null; } if ( !currentUser.hasRole( ROLE_ORGANIZATION_ADMIN ) ) { return null; } Session session = currentUser.getSession(); OrganizationInfo organization = ( OrganizationInfo ) session.getAttribute( "organization" ); if ( organization == null ) { return null; } return organization.getName(); }
public static UUID getOrganizationId() { Subject currentUser = getSubject(); if ( currentUser == null ) { return null; } if ( !currentUser.hasRole( ROLE_ORGANIZATION_ADMIN ) ) { return null; } Session session = currentUser.getSession(); OrganizationInfo organization = ( OrganizationInfo ) session.getAttribute( "organization" ); if ( organization == null ) { return null; } return organization.getUuid(); }
@Test public void testSessionStopThenStart() { String key = "testKey"; String value = "testValue"; DefaultSecurityManager sm = new DefaultSecurityManager(); DelegatingSubject subject = new DelegatingSubject(sm); Session session = subject.getSession(); session.setAttribute(key, value); assertTrue(session.getAttribute(key).equals(value)); Serializable firstSessionId = session.getId(); assertNotNull(firstSessionId); session.stop(); session = subject.getSession(); assertNotNull(session); assertNull(session.getAttribute(key)); Serializable secondSessionId = session.getId(); assertNotNull(secondSessionId); assertFalse(firstSessionId.equals(secondSessionId)); subject.logout(); sm.destroy(); }
@Test public void testDefaultConfig() { Subject subject = SecurityUtils.getSubject(); AuthenticationToken token = new UsernamePasswordToken("guest", "guest"); subject.login(token); assertTrue(subject.isAuthenticated()); assertTrue("guest".equals(subject.getPrincipal())); assertTrue(subject.hasRole("guest")); Session session = subject.getSession(); session.setAttribute("key", "value"); assertEquals(session.getAttribute("key"), "value"); subject.logout(); assertNull(subject.getSession(false)); assertNull(subject.getPrincipal()); assertNull(subject.getPrincipals()); }