Search in sources :

Example 1 with IdProviderConfig

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);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) IdProviderConfig(com.enonic.xp.security.IdProviderConfig) CreateIdProviderParams(com.enonic.xp.security.CreateIdProviderParams)

Example 2 with IdProviderConfig

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());
    }
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) ApplyNodePermissionsParams(com.enonic.xp.node.ApplyNodePermissionsParams) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) IdProviderAlreadyExistsException(com.enonic.xp.security.IdProviderAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) IdProviderConfig(com.enonic.xp.security.IdProviderConfig)

Example 3 with IdProviderConfig

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();
}
Also used : IdProvider(com.enonic.xp.security.IdProvider) IdProviderKey(com.enonic.xp.security.IdProviderKey) PropertySet(com.enonic.xp.data.PropertySet) IdProviderConfig(com.enonic.xp.security.IdProviderConfig)

Example 4 with IdProviderConfig

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);
}
Also used : IdProviderDescriptorService(com.enonic.xp.idprovider.IdProviderDescriptorService) PortalScriptService(com.enonic.xp.portal.script.PortalScriptService) SecurityService(com.enonic.xp.security.SecurityService) IdProvider(com.enonic.xp.security.IdProvider) IdProviderConfig(com.enonic.xp.security.IdProviderConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

IdProviderConfig (com.enonic.xp.security.IdProviderConfig)4 PropertyTree (com.enonic.xp.data.PropertyTree)2 IdProvider (com.enonic.xp.security.IdProvider)2 PropertySet (com.enonic.xp.data.PropertySet)1 IdProviderDescriptorService (com.enonic.xp.idprovider.IdProviderDescriptorService)1 ApplyNodePermissionsParams (com.enonic.xp.node.ApplyNodePermissionsParams)1 Node (com.enonic.xp.node.Node)1 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)1 NodeIdExistsException (com.enonic.xp.node.NodeIdExistsException)1 PortalScriptService (com.enonic.xp.portal.script.PortalScriptService)1 CreateIdProviderParams (com.enonic.xp.security.CreateIdProviderParams)1 IdProviderAlreadyExistsException (com.enonic.xp.security.IdProviderAlreadyExistsException)1 IdProviderKey (com.enonic.xp.security.IdProviderKey)1 SecurityService (com.enonic.xp.security.SecurityService)1 AccessControlList (com.enonic.xp.security.acl.AccessControlList)1 IdProviderAccessControlList (com.enonic.xp.security.acl.IdProviderAccessControlList)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1