use of com.enonic.xp.security.auth.AuthenticationInfo in project xp by enonic.
the class PageHandlerTest method getContentExistsButInsufficientRights.
@Test
public void getContentExistsButInsufficientRights() {
final AuthenticationInfo authenticationInfo = AuthenticationInfo.create().user(User.ANONYMOUS).build();
final Context authenticatedContext = ContextBuilder.from(ContextAccessor.current()).authInfo(authenticationInfo).build();
final ContentPath path = ContentPath.from("/site/somepath/content");
when(this.contentService.getByPath(path)).thenThrow(new ContentNotFoundException(path, Branch.from("draft")));
when(this.contentService.contentExists(path)).thenReturn(true);
this.request.setContentPath(path);
final WebException e = assertThrows(WebException.class, () -> authenticatedContext.callWith(() -> this.handler.handle(this.request, PortalResponse.create().build(), null)));
assertEquals(HttpStatus.FORBIDDEN, e.getStatus());
assertEquals("You don't have permission to access [/site/somepath/content]", e.getMessage());
}
use of com.enonic.xp.security.auth.AuthenticationInfo in project xp by enonic.
the class IdProviderFilterTest method testExecuteAuthenticated.
@Test
public void testExecuteAuthenticated() throws Exception {
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("User 1").email("user1@enonic.com").login("user1").build();
final AuthenticationInfo authenticationInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN_LOGIN).build();
ContextBuilder.create().authInfo(authenticationInfo).build().callWith(() -> {
final HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
final HttpServletResponse httpServletResponse = Mockito.mock(HttpServletResponse.class);
final FilterChain filterChain = Mockito.mock(FilterChain.class);
idProviderFilter.doHandle(httpServletRequest, httpServletResponse, filterChain);
Mockito.verify(idProviderControllerService, Mockito.times(0)).execute(Mockito.any());
return null;
});
}
use of com.enonic.xp.security.auth.AuthenticationInfo in project xp by enonic.
the class SystemRepoInitializer method createAdminContext.
private Context createAdminContext() {
final User admin = User.create().key(SUPER_USER).login(SUPER_USER.getId()).build();
final AuthenticationInfo authInfo = AuthenticationInfo.create().principals(RoleKeys.ADMIN).user(admin).build();
return ContextBuilder.create().branch(SecurityConstants.BRANCH_SECURITY).repositoryId(SystemConstants.SYSTEM_REPO_ID).authInfo(authInfo).build();
}
use of com.enonic.xp.security.auth.AuthenticationInfo in project xp by enonic.
the class WebExceptionTest method forbidden_403_for_authenticated.
@Test
void forbidden_403_for_authenticated() {
// for already authenticated users forbidden must not allow ID Provider to re-authenticate
final AuthenticationInfo authenticationInfo = AuthenticationInfo.create().user(User.ANONYMOUS).build();
final Context authenticatedContext = ContextBuilder.from(ContextAccessor.current()).authInfo(authenticationInfo).build();
final WebException webException = authenticatedContext.callWith(() -> WebException.forbidden("some message"));
assertEquals(HttpStatus.FORBIDDEN, webException.getStatus());
}
use of com.enonic.xp.security.auth.AuthenticationInfo in project xp by enonic.
the class SecurityServiceImplTest method testAuthenticateByUsernamePwd.
@Test
public void testAuthenticateByUsernamePwd() throws Exception {
runAsAdmin(() -> {
final CreateUserParams createUser = CreateUserParams.create().userKey(PrincipalKey.ofUser(SYSTEM, "User1")).displayName("User 1").email("user1@enonic.com").login("User1").password("runar").build();
final User user = securityService.createUser(createUser);
refresh();
final UsernamePasswordAuthToken authToken = new UsernamePasswordAuthToken();
authToken.setUsername("User1");
authToken.setPassword("runar");
authToken.setIdProvider(SYSTEM);
final AuthenticationInfo authInfo = securityService.authenticate(authToken);
assertTrue(authInfo.isAuthenticated());
assertEquals(user.getKey(), authInfo.getUser().getKey());
});
}
Aggregations