use of com.enonic.xp.security.CreateIdProviderParams 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.CreateIdProviderParams 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());
});
}
use of com.enonic.xp.security.CreateIdProviderParams in project xp by enonic.
the class SecurityInitializer method initializeSystemIdProvider.
private void initializeSystemIdProvider() {
LOG.info("Initializing id provider [" + IdProviderKey.system() + "]");
final PropertyTree idProviderConfigTree = new PropertyTree();
if (!"false".equalsIgnoreCase(System.getProperty(ADMIN_USER_CREATION_PROPERTY_KEY))) {
idProviderConfigTree.setBoolean("adminUserCreationEnabled", true);
}
final IdProviderConfig idProviderConfig = IdProviderConfig.create().applicationKey(SYSTEM_ID_PROVIDER_KEY).config(idProviderConfigTree).build();
final CreateIdProviderParams createParams = CreateIdProviderParams.create().key(IdProviderKey.system()).displayName(SYSTEM_ID_PROVIDER_DISPLAY_NAME).idProviderConfig(idProviderConfig).permissions(DEFAULT_ID_PROVIDER_ACL).build();
this.securityService.createIdProvider(createParams);
}
use of com.enonic.xp.security.CreateIdProviderParams in project xp by enonic.
the class SecurityServiceImplTest method testCreateIdProvider.
@Test
public void testCreateIdProvider() throws Exception {
runAsAdmin(() -> {
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("id provider description").build();
final IdProvider idProviderCreated = securityService.createIdProvider(createIdProvider);
assertNotNull(idProviderCreated);
assertEquals("enonic", idProviderCreated.getKey().toString());
assertEquals("Enonic Id Provider", idProviderCreated.getDisplayName());
assertEquals("id provider description", idProviderCreated.getDescription());
final IdProviderAccessControlList createdPermissions = securityService.getIdProviderPermissions(IdProviderKey.from("enonic"));
assertNotNull(idProviderCreated);
assertEquals(CREATE_USERS, createdPermissions.getEntry(userKey).getAccess());
assertEquals(ADMINISTRATOR, createdPermissions.getEntry(groupKey1).getAccess());
assertEquals(WRITE_USERS, createdPermissions.getEntry(groupKey2).getAccess());
});
}
Aggregations