use of com.enonic.xp.security.auth.AuthenticationInfo in project xp by enonic.
the class LoginHandlerTest method testSessionInvalidatedOnLogin.
@Test
public void testSessionInvalidatedOnLogin() {
final AuthenticationInfo authInfo = TestDataFixtures.createAuthenticationInfo();
final IdProviders idProviders = IdProviders.from(IdProvider.create().displayName("system").key(IdProviderKey.from("system")).build());
Mockito.when(this.securityService.authenticate(Mockito.any())).thenReturn(authInfo);
Mockito.when(this.securityService.getIdProviders()).thenReturn(idProviders);
final SessionMock session = Mockito.spy(new SessionMock());
ContextAccessor.current().getLocalScope().setSession(session);
runScript("/lib/xp/examples/auth/login.js");
verify(session, times(5)).invalidate();
}
use of com.enonic.xp.security.auth.AuthenticationInfo in project xp by enonic.
the class ChangePasswordHandlerTest method testExamples.
@Test
public void testExamples() {
final AuthenticationInfo authInfo = AuthenticationInfo.create().user(TestDataFixtures.getTestUser()).principals(RoleKeys.ADMIN_LOGIN).build();
this.session.setAttribute(authInfo);
runScript("/lib/xp/examples/auth/changePassword.js");
Mockito.verify(this.securityService).setPassword(eq(authInfo.getUser().getKey()), eq("new-secret-password"));
}
use of com.enonic.xp.security.auth.AuthenticationInfo in project xp by enonic.
the class NodePermissionsResolverTest method hasPermissionAll.
@Test
public void hasPermissionAll() throws Exception {
final AuthenticationInfo authInfo = AuthenticationInfo.create().user(User.create().key(USER_A).login("usera").build()).principals(USER_A, GROUP_B, ROLE_C).build();
final AccessControlList nodePermissions = AccessControlList.create().add(AccessControlEntry.create().principal(USER_A).allow(READ).build()).add(AccessControlEntry.create().principal(GROUP_B).allow(CREATE).build()).add(AccessControlEntry.create().principal(ROLE_C).allow(READ, MODIFY, CREATE).build()).build();
assertTrue(NodePermissionsResolver.userHasPermission(authInfo, READ, nodePermissions));
assertTrue(NodePermissionsResolver.userHasPermission(authInfo, CREATE, nodePermissions));
assertTrue(NodePermissionsResolver.userHasPermission(authInfo, MODIFY, nodePermissions));
assertFalse(NodePermissionsResolver.userHasPermission(authInfo, PUBLISH, nodePermissions));
}
use of com.enonic.xp.security.auth.AuthenticationInfo in project xp by enonic.
the class NodePermissionsResolverTest method hasPermissionSome.
@Test
public void hasPermissionSome() throws Exception {
final AuthenticationInfo authInfo = AuthenticationInfo.create().user(User.create().key(USER_A).login("usera").build()).principals(USER_A, ROLE_C).build();
final AccessControlList nodePermissions = AccessControlList.create().add(AccessControlEntry.create().principal(USER_A).allow(READ).build()).add(AccessControlEntry.create().principal(GROUP_B).allow(CREATE).build()).add(AccessControlEntry.create().principal(ROLE_C).allow(MODIFY).build()).build();
assertTrue(NodePermissionsResolver.userHasPermission(authInfo, READ, nodePermissions));
assertFalse(NodePermissionsResolver.userHasPermission(authInfo, CREATE, nodePermissions));
assertTrue(NodePermissionsResolver.userHasPermission(authInfo, MODIFY, nodePermissions));
assertFalse(NodePermissionsResolver.userHasPermission(authInfo, PUBLISH, nodePermissions));
}
use of com.enonic.xp.security.auth.AuthenticationInfo in project xp by enonic.
the class HasRoleHandlerTest method testDoesNotHaveRole.
@Test
public void testDoesNotHaveRole() {
final AuthenticationInfo authInfo = AuthenticationInfo.create().user(TestDataFixtures.getTestUser()).principals(RoleKeys.ADMIN_LOGIN).build();
this.session.setAttribute(authInfo);
runFunction("/test/hasRole-test.js", "doesNotHaveRole");
}
Aggregations