use of com.enonic.xp.security.UpdateIdProviderParams in project xp by enonic.
the class SecurityServiceImplTest method testUpdateIdProvider.
@Test
public void testUpdateIdProvider() throws Exception {
runAsAdmin(() -> {
// setup
final PrincipalKey userKey = PrincipalKey.ofUser(SYSTEM, "User1");
final PrincipalKey groupKey1 = PrincipalKey.ofGroup(SYSTEM, "Group-a");
final PrincipalKey groupKey2 = PrincipalKey.ofGroup(SYSTEM, "group-b");
final IdProviderAccessControlList permissions = IdProviderAccessControlList.of(IdProviderAccessControlEntry.create().principal(userKey).access(CREATE_USERS).build(), IdProviderAccessControlEntry.create().principal(groupKey1).access(ADMINISTRATOR).build(), IdProviderAccessControlEntry.create().principal(groupKey2).access(WRITE_USERS).build());
final CreateIdProviderParams createIdProvider = CreateIdProviderParams.create().key(IdProviderKey.from("enonic")).displayName("Enonic Id Provider").permissions(permissions).description("old id provider description").build();
final IdProvider idProviderCreated = securityService.createIdProvider(createIdProvider);
// exercise
final IdProviderAccessControlList updatePermissions = IdProviderAccessControlList.of(IdProviderAccessControlEntry.create().principal(userKey).access(CREATE_USERS).build(), IdProviderAccessControlEntry.create().principal(groupKey1).access(ADMINISTRATOR).build());
final UpdateIdProviderParams updateIdProvider = UpdateIdProviderParams.create().key(IdProviderKey.from("enonic")).displayName("Enonic Id Provider updated").permissions(updatePermissions).description("new id provider description").build();
final IdProvider idProviderUpdated = securityService.updateIdProvider(updateIdProvider);
// verify
assertNotNull(idProviderUpdated);
assertEquals("enonic", idProviderUpdated.getKey().toString());
assertEquals("Enonic Id Provider updated", idProviderUpdated.getDisplayName());
assertEquals("new id provider description", idProviderUpdated.getDescription());
final IdProviderAccessControlList updatedPermissions = securityService.getIdProviderPermissions(IdProviderKey.from("enonic"));
assertNotNull(idProviderCreated);
assertEquals(CREATE_USERS, updatedPermissions.getEntry(userKey).getAccess());
assertEquals(ADMINISTRATOR, updatedPermissions.getEntry(groupKey1).getAccess());
assertNull(updatedPermissions.getEntry(groupKey2));
});
}
use of com.enonic.xp.security.UpdateIdProviderParams in project xp by enonic.
the class SecurityServiceImplTest method testUpdateIdProviderWithEditor.
@Test
public void testUpdateIdProviderWithEditor() throws Exception {
runAsAdmin(() -> {
// setup
final CreateIdProviderParams createIdProvider = CreateIdProviderParams.create().key(IdProviderKey.from("enonic")).displayName("Enonic Id Provider").description("old id provider description").build();
final IdProvider idProviderCreated = securityService.createIdProvider(createIdProvider);
// exercise
final UpdateIdProviderParams updateIdProvider = UpdateIdProviderParams.create(idProviderCreated).editor(edit -> {
edit.key = IdProviderKey.from("newEnonic");
edit.displayName = "Enonic Id Provider updated";
edit.description = "new id provider description";
}).displayName("Display name from parameters").description("Description from parameters").build();
final IdProvider idProviderUpdated = securityService.updateIdProvider(updateIdProvider);
// verify
assertNotNull(idProviderUpdated);
assertEquals("enonic", idProviderUpdated.getKey().toString());
assertEquals("Enonic Id Provider updated", idProviderUpdated.getDisplayName());
assertEquals("new id provider description", idProviderUpdated.getDescription());
});
}
Aggregations