use of com.enonic.xp.security.User in project xp by enonic.
the class ContextMapperTest method test.
@Test
public void test() {
User user = User.create().login(PrincipalKey.ofSuperUser().getId()).displayName("Super User").key(PrincipalKey.ofSuperUser()).build();
AuthenticationInfo authInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN, RoleKeys.EVERYONE).build();
Context context = ContextBuilder.create().repositoryId(RepositoryId.from("repository.id")).branch(Branch.create().value("master").build()).authInfo(authInfo).attribute("attrAsString", "value").attribute("attrAsInteger", Integer.MAX_VALUE).attribute("attrAsLong", Long.MIN_VALUE).attribute("attrAsBoolean", true).attribute("authInfoDetails", authInfo).attribute("testMapper", new TestMapper()).build();
context.getLocalScope().setAttribute("attrAsString", "localValue");
context.getLocalScope().setAttribute("attr1", "localValue");
context.getLocalScope().setSession(new SessionMock());
context.getLocalScope().getSession().setAttribute("attrAsString", "sessionValue");
context.getLocalScope().getSession().setAttribute("attr2", "sessionValue");
JsonMapGenerator generator = new JsonMapGenerator();
new ContextMapper(context).serialize(generator);
JsonNode actualJson = (JsonNode) generator.getRoot();
JsonNode attributes = actualJson.get("attributes");
assertNull(attributes.get("authInfoDetails"));
assertNull(attributes.get(Branch.class.getName()));
assertNull(attributes.get(RepositoryId.class.getName()));
assertNull(attributes.get(AuthenticationInfo.class.getName()));
assertEquals("value", attributes.get("attrAsString").asText());
assertEquals(Integer.MAX_VALUE, attributes.get("attrAsInteger").asInt());
assertTrue(attributes.get("attrAsBoolean").asBoolean());
assertEquals(Long.MIN_VALUE, attributes.get("attrAsLong").asLong());
assertNotNull(attributes.get("testMapper"));
assertEquals("localValue", attributes.get("attr1").asText());
assertEquals("sessionValue", attributes.get("attr2").asText());
}
use of com.enonic.xp.security.User in project xp by enonic.
the class WebSocketEventMapper method serializeUser.
private void serializeUser(final MapGenerator gen, Principal principal) {
if (principal instanceof User) {
gen.map("user");
User user = (User) principal;
gen.value("key", user.getKey());
gen.value("displayName", user.getDisplayName());
gen.value("modifiedTime", user.getModifiedTime());
gen.value("disabled", user.isDisabled());
gen.value("email", user.getEmail());
gen.value("login", user.getLogin());
gen.value("idProvider", user.getKey().getIdProviderKey());
gen.end();
}
}
use of com.enonic.xp.security.User in project xp by enonic.
the class BasicAuthFilterTest method rightAuthentication.
private void rightAuthentication() {
final User user = User.create().login("user").key(PrincipalKey.ofUser(IdProviderKey.from("store"), "user")).build();
when(this.securityService.authenticate(Mockito.any())).thenReturn(AuthenticationInfo.create().user(user).build());
}
Aggregations