use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class GetMembershipsHandlerTest method testGetUserMemberships.
@Test
public void testGetUserMemberships() {
final Group group = TestDataFixtures.getTestGroup();
final PrincipalKeys principalKeys = PrincipalKeys.from(group.getKey());
final PrincipalKey pKey = PrincipalKey.from("user:myIdProvider:userId");
Mockito.when(securityService.getMemberships(pKey)).thenReturn(principalKeys);
Mockito.verify(securityService, Mockito.never()).getAllMemberships(pKey);
Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(group));
runFunction("/test/getMemberships-test.js", "getUserMemberships");
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class SetPermissionsHandler method validPrincipals.
private boolean validPrincipals() {
boolean valid = true;
for (PrincipalKey principal : permissions.getAllPrincipals()) {
if (!principalExists(principal)) {
LOG.warn("Principal not found: " + principal);
valid = false;
}
}
return valid;
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class ContextMapper method serializePrincipals.
private void serializePrincipals(final MapGenerator gen, final PrincipalKeys keys) {
if (keys == null) {
return;
}
gen.array("principals");
for (final PrincipalKey key : keys) {
gen.value(key.toString());
}
gen.end();
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class ServiceHandlerTest method testForbiddenService.
@Test
public void testForbiddenService() throws Exception {
final DescriptorKey serviceDescriptorKey = DescriptorKey.from("demo:test");
final Set<PrincipalKey> allowedPrincipals = Collections.singleton(PrincipalKey.from("role:system.admin"));
final ServiceDescriptor serviceDescriptor = ServiceDescriptor.create().key(serviceDescriptorKey).setAllowedPrincipals(allowedPrincipals).build();
Mockito.when(this.serviceDescriptorService.getByKey(serviceDescriptorKey)).thenReturn(serviceDescriptor);
this.request.setEndpointPath("/_/service/demo/test");
boolean forbiddenErrorThrown = false;
try {
this.handler.handle(this.request, PortalResponse.create().build(), null);
} catch (WebException e) {
if (HttpStatus.UNAUTHORIZED == e.getStatus()) {
forbiddenErrorThrown = true;
}
}
assertTrue(forbiddenErrorThrown);
}
Aggregations