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);
}
use of com.enonic.xp.session.Session in project xp by enonic.
the class LoginHandlerTest method testLoginNoIdProviders.
@Test
public void testLoginNoIdProviders() {
final IdProviders idProviders = IdProviders.from(IdProvider.create().displayName("system").key(IdProviderKey.from("system")).build());
final AuthenticationInfo authInfo = TestDataFixtures.createAuthenticationInfo();
Mockito.when(this.securityService.authenticate(Mockito.any())).thenReturn(authInfo);
Mockito.when(this.securityService.getIdProviders()).thenReturn(idProviders);
runFunction("/test/login-test.js", "loginNoIdProvider");
final Session session = ContextAccessor.current().getLocalScope().getSession();
final AuthenticationInfo sessionAuthInfo = session.getAttribute(AuthenticationInfo.class);
assertEquals(authInfo, sessionAuthInfo);
}
use of com.enonic.xp.session.Session in project xp by enonic.
the class ContextMapper method getAttributes.
private Map<String, Object> getAttributes() {
LocalScope localScope = this.context.getLocalScope();
Map<String, Object> attributes = this.context.getAttributes();
Map<String, Object> localAttributes = localScope.getAttributes();
Session session = localScope.getSession();
Map<String, Object> sessionAttributes = session == null ? Map.of() : session.getAttributes();
return Stream.of(attributes, localAttributes, sessionAttributes).flatMap(map -> map.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1, HashMap::new));
}
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);
}
Aggregations