use of com.enonic.xp.security.IdProviderConfig 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.IdProviderConfig in project xp by enonic.
the class SecurityServiceImpl method createIdProvider.
@Override
public IdProvider createIdProvider(final CreateIdProviderParams createIdProviderParams) {
final PropertyTree data = new PropertyTree();
data.setString(IdProviderPropertyNames.DISPLAY_NAME_KEY, createIdProviderParams.getDisplayName());
data.setString(IdProviderPropertyNames.DESCRIPTION_KEY, createIdProviderParams.getDescription());
final IdProviderConfig idProviderConfig = createIdProviderParams.getIdProviderConfig();
if (idProviderConfig != null) {
data.setString(IdProviderPropertyNames.ID_PROVIDER_APPLICATION_KEY, idProviderConfig.getApplicationKey().toString());
data.setSet(IdProviderPropertyNames.ID_PROVIDER_CONFIG_FORM_KEY, idProviderConfig.getConfig().getRoot());
}
try {
final Node node = callWithContext(() -> {
final IdProviderAccessControlList permissions = createIdProviderParams.getIdProviderPermissions();
AccessControlList idProviderNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToIdProviderNodePermissions(permissions);
AccessControlList usersNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToUsersNodePermissions(permissions);
AccessControlList groupsNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToGroupsNodePermissions(permissions);
final Node rootNode = nodeService.getRoot();
idProviderNodePermissions = mergeWithRootPermissions(idProviderNodePermissions, rootNode.getPermissions());
usersNodePermissions = mergeWithRootPermissions(usersNodePermissions, rootNode.getPermissions());
groupsNodePermissions = mergeWithRootPermissions(groupsNodePermissions, rootNode.getPermissions());
final Node idProviderNode = nodeService.create(CreateNodeParams.create().parent(IdProviderNodeTranslator.getIdProvidersParentPath()).name(createIdProviderParams.getKey().toString()).data(data).permissions(idProviderNodePermissions).build());
nodeService.create(CreateNodeParams.create().parent(idProviderNode.path()).name(IdProviderNodeTranslator.USER_FOLDER_NODE_NAME).permissions(usersNodePermissions).build());
nodeService.create(CreateNodeParams.create().parent(idProviderNode.path()).name(IdProviderNodeTranslator.GROUP_FOLDER_NODE_NAME).permissions(groupsNodePermissions).build());
final ApplyNodePermissionsParams applyPermissions = ApplyNodePermissionsParams.create().nodeId(rootNode.id()).overwriteChildPermissions(false).build();
nodeService.applyPermissions(applyPermissions);
this.nodeService.refresh(RefreshMode.SEARCH);
return idProviderNode;
});
return IdProviderNodeTranslator.fromNode(node);
} catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
throw new IdProviderAlreadyExistsException(createIdProviderParams.getKey());
}
}
use of com.enonic.xp.security.IdProviderConfig in project xp by enonic.
the class IdProviderNodeTranslator method createIdProviderFromNode.
private static IdProvider createIdProviderFromNode(final Node node) {
if (node.name().toString().equalsIgnoreCase(PrincipalKey.ROLES_NODE_NAME)) {
return null;
}
final PropertySet nodeAsSet = node.data().getRoot();
final IdProviderKey idProviderKey = IdProviderNodeTranslator.toKey(node);
final IdProvider.Builder idProvider = IdProvider.create().displayName(nodeAsSet.getString(IdProviderPropertyNames.DISPLAY_NAME_KEY)).key(idProviderKey).description(nodeAsSet.getString(IdProviderPropertyNames.DESCRIPTION_KEY));
if (nodeAsSet.hasProperty(IdProviderPropertyNames.APPLICATION)) {
final String applicationKey = nodeAsSet.getString(IdProviderPropertyNames.ID_PROVIDER_APPLICATION_KEY);
final PropertySet config = nodeAsSet.getSet(IdProviderPropertyNames.ID_PROVIDER_CONFIG_FORM_KEY);
final IdProviderConfig idProviderConfig = IdProviderConfig.create().applicationKey(ApplicationKey.from(applicationKey)).config(config.toTree()).build();
idProvider.idProviderConfig(idProviderConfig);
} else if (IdProviderKey.system().equals(idProviderKey)) {
// TODO Remove after next dump upgrade
final IdProviderConfig idProviderConfig = IdProviderConfig.create().applicationKey(SYSTEM_ID_PROVIDER_KEY).build();
idProvider.idProviderConfig(idProviderConfig);
}
return idProvider.build();
}
use of com.enonic.xp.security.IdProviderConfig in project xp by enonic.
the class IdProviderControllerServiceImplTest method setup.
@BeforeEach
public void setup() throws Exception {
// Mocks the IdProviderDescriptorService
final IdProviderDescriptorService idProviderDescriptorService = Mockito.mock(IdProviderDescriptorService.class);
Mockito.when(idProviderDescriptorService.getDescriptor(ApplicationKey.from("myapplication"))).thenReturn(IdProviderDescriptor.create().key(ApplicationKey.from("myapplication")).build());
// Mocks the SecurityService
final SecurityService securityService = Mockito.mock(SecurityService.class);
final IdProvider emptyIdProvider = IdProvider.create().build();
final IdProviderConfig idProviderConfig = IdProviderConfig.create().applicationKey(ApplicationKey.from("myapplication")).build();
final IdProvider idProvider = IdProvider.create().idProviderConfig(idProviderConfig).build();
Mockito.when(securityService.getIdProvider(IdProviderKey.from("myemptyidprovider"))).thenReturn(emptyIdProvider);
Mockito.when(securityService.getIdProvider(IdProviderKey.from("myidprovider"))).thenReturn(idProvider);
Mockito.when(securityService.getIdProvider(IdProviderKey.from("myemptyuserstore"))).thenReturn(emptyIdProvider);
Mockito.when(securityService.getIdProvider(IdProviderKey.from("myuserstore"))).thenReturn(idProvider);
// Mocks the PortalScriptService
final PortalScriptService portalScriptService = setupPortalScriptService();
// Creates IdProviderControllerScriptFactoryImpl
final IdProviderControllerScriptFactoryImpl idProviderControllerScriptFactory = new IdProviderControllerScriptFactoryImpl();
idProviderControllerScriptFactory.setScriptService(portalScriptService);
// Creates IdProviderControllerServiceImpl
idProviderControllerService = new IdProviderControllerServiceImpl();
idProviderControllerService.setIdProviderControllerScriptFactory(idProviderControllerScriptFactory);
idProviderControllerService.setIdProviderDescriptorService(idProviderDescriptorService);
idProviderControllerService.setSecurityService(securityService);
}
Aggregations