use of com.enonic.xp.security.User in project xp by enonic.
the class ContextScriptTest method initialize.
@Override
protected void initialize() throws Exception {
super.initialize();
final SecurityService securityService = Mockito.mock(SecurityService.class);
addService(SecurityService.class, securityService);
final User user = User.create().login(PrincipalKey.ofSuperUser().getId()).displayName("Super User").key(PrincipalKey.ofSuperUser()).build();
final AuthenticationInfo authInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN, RoleKeys.EVERYONE).build();
Mockito.when(securityService.authenticate(Mockito.any())).thenReturn(authInfo);
}
use of com.enonic.xp.security.User 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.User in project xp by enonic.
the class AuthResourceTest method testAuthenticated_authenticated.
@Test
public void testAuthenticated_authenticated() throws Exception {
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("User 1").modifiedTime(Instant.now(clock)).email("user1@enonic.com").login("user1").build();
final LocalScope localScope = ContextAccessor.current().getLocalScope();
final AuthenticationInfo authInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN_LOGIN).build();
localScope.setAttribute(authInfo);
localScope.setSession(new SessionMock());
String jsonString = request().path("auth/authenticated").get().getAsString();
assertJson("authenticated_success.json", jsonString);
}
use of com.enonic.xp.security.User in project xp by enonic.
the class LogAuditLogParams method getUserKey.
private PrincipalKey getUserKey() {
final Context context = ContextAccessor.current();
final User user = context.getAuthInfo().getUser() != null ? context.getAuthInfo().getUser() : User.ANONYMOUS;
return user.getKey();
}
use of com.enonic.xp.security.User in project xp by enonic.
the class AuthenticationInfoTest method testSerialization.
@Test
void testSerialization() throws Exception {
final User user = User.create().login("userlogin").displayName("my user").key(PrincipalKey.ofUser(IdProviderKey.from("myidprovider"), "userid")).email("user@email").description("description").modifiedTime(Instant.now(clock)).build();
final IdProviderKey idProvider = IdProviderKey.from("myStore");
final PrincipalKey group1 = PrincipalKey.ofGroup(idProvider, "group1");
final PrincipalKey group2 = PrincipalKey.from("group:myStore:group2");
final PrincipalKey role1 = PrincipalKey.from("role:administrators");
final AuthenticationInfo info = AuthenticationInfo.create().user(user).principals(group1).principals(PrincipalKeys.from(group2, role1)).build();
final byte[] serializedObject = serialize(info);
final AuthenticationInfo deserializedObject = (AuthenticationInfo) deserialize(serializedObject);
assertEquals(deserializedObject, info);
}
Aggregations