use of com.enonic.xp.session.Session in project xp by enonic.
the class AuthResource method isAuthenticated.
@GET
@Path("authenticated")
public LoginResultJson isAuthenticated() {
final Session session = ContextAccessor.current().getLocalScope().getSession();
if (session == null) {
return new LoginResultJson(AuthenticationInfo.unAuthenticated());
}
final AuthenticationInfo authInfo = ContextAccessor.current().getAuthInfo();
return new LoginResultJson(authInfo);
}
use of com.enonic.xp.session.Session in project xp by enonic.
the class LocalScopeImplTest method testAttributeByType_session.
@Test
public void testAttributeByType_session() {
final SampleValue value = new SampleValue();
final Session session = new SessionMock();
session.setAttribute(value);
final LocalScopeImpl context = new LocalScopeImpl();
context.setSession(session);
assertSame(session, context.getSession());
assertSame(value, context.getAttribute(SampleValue.class));
assertEquals(0, context.getAttributes().size());
}
use of com.enonic.xp.session.Session in project xp by enonic.
the class LocalScopeImplTest method testAttributeByKey_session.
@Test
public void testAttributeByKey_session() {
final Session session = new SessionMock();
session.setAttribute("key1", "value1");
final LocalScopeImpl context = new LocalScopeImpl();
context.setSession(session);
assertSame(session, context.getSession());
assertEquals("value1", context.getAttribute("key1"));
assertEquals(0, context.getAttributes().size());
}
use of com.enonic.xp.session.Session in project xp by enonic.
the class LoginHandler method createSession.
private void createSession(final AuthenticationInfo authInfo) {
final LocalScope localScope = this.context.get().getLocalScope();
final Session session = localScope.getSession();
if (session != null) {
final var attributes = session.getAttributes();
session.invalidate();
final Session newSession = localScope.getSession();
if (newSession != null) {
attributes.forEach(newSession::setAttribute);
session.setAttribute(authInfo);
if (this.sessionTimeout != null) {
setSessionTimeout();
}
}
}
}
use of com.enonic.xp.session.Session in project xp by enonic.
the class LoginHandlerTest method testLoginSuccessNoSession.
@Test
public void testLoginSuccessNoSession() {
final AuthenticationInfo authInfo = AuthenticationInfo.create().user(TestDataFixtures.getTestUser()).principals(RoleKeys.ADMIN_LOGIN).build();
Mockito.when(this.securityService.authenticate(Mockito.any())).thenReturn(authInfo);
runFunction("/test/login-test.js", "loginSuccessNoSession");
final AuthenticationInfo localScopeAuth = ContextAccessor.current().getLocalScope().getAttribute(AuthenticationInfo.class);
final Session session = ContextAccessor.current().getLocalScope().getSession();
final AuthenticationInfo sessionAuthInfo = session.getAttribute(AuthenticationInfo.class);
assertEquals(authInfo, localScopeAuth);
assertEquals(null, sessionAuthInfo);
}
Aggregations