Search in sources :

Example 31 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class SecurityAuditLogSupportImpl method createRole.

@Override
public void createRole(final CreateRoleParams params) {
    if (isEnabledAuditLogs) {
        PropertyTree data = new PropertyTree();
        PropertySet paramsSet = data.addSet("params");
        paramsSet.setString("key", params.getKey().toString());
        paramsSet.setString("displayName", params.getDisplayName());
        paramsSet.setString("description", params.getDescription());
        log("system.security.principal.create", data, AuditLogUris.from(params.getKey().toString()));
    }
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet)

Example 32 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class SecurityAuditLogSupportImpl method removeRelationship.

@Override
public void removeRelationship(final PrincipalRelationship relationship) {
    if (isEnabledAuditLogs) {
        PropertyTree data = new PropertyTree();
        PropertySet paramsSet = data.addSet("params");
        paramsSet.setString("principal", relationship.getTo().toString());
        paramsSet.setString("leaves", relationship.getFrom().toString());
        AuditLogUris auditLogUris = AuditLogUris.from(relationship.getTo().toString(), relationship.getFrom().toString());
        log("system.security.principal.removeRelationship", data, auditLogUris);
    }
}
Also used : AuditLogUris(com.enonic.xp.audit.AuditLogUris) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet)

Example 33 with PropertyTree

use of com.enonic.xp.data.PropertyTree 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 34 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class PrincipalKeyNodeTranslator method toKey.

public static PrincipalKey toKey(final Node node) {
    final String principalId = node.name().toString();
    final PropertyTree rootDataSet = node.data();
    final String principalType = rootDataSet.getString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY);
    final String idProviderKey = rootDataSet.getString(PrincipalPropertyNames.ID_PROVIDER_KEY);
    final PrincipalType type = PrincipalType.valueOf(principalType);
    switch(type) {
        case USER:
            return PrincipalKey.ofUser(IdProviderKey.from(idProviderKey), principalId);
        case GROUP:
            return PrincipalKey.ofGroup(IdProviderKey.from(idProviderKey), principalId);
        case ROLE:
            return PrincipalKey.ofRole(principalId);
    }
    throw new IllegalArgumentException("Invalid principal type in node: " + type);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PrincipalType(com.enonic.xp.security.PrincipalType)

Example 35 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class PrincipalNodeTranslator method toCreateNodeParams.

public static CreateNodeParams toCreateNodeParams(final Principal principal) {
    Preconditions.checkNotNull(principal);
    final CreateNodeParams.Builder builder = CreateNodeParams.create().name(PrincipalKeyNodeTranslator.toNodeName(principal.getKey()).toString()).parent(principal.getKey().toPath().getParentPath()).setNodeId(NodeId.from(principal.getKey().toString().toLowerCase())).inheritPermissions(true).indexConfigDocument(PrincipalIndexConfigFactory.create());
    final PropertyTree data = new PropertyTree();
    data.setString(PrincipalPropertyNames.DISPLAY_NAME_KEY, principal.getDisplayName());
    data.setString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY, principal.getKey().getType().toString());
    if (!principal.getKey().isRole()) {
        data.setString(PrincipalPropertyNames.ID_PROVIDER_KEY, principal.getKey().getIdProviderKey().toString());
    }
    switch(principal.getKey().getType()) {
        case USER:
            populateUserData(data.getRoot(), (User) principal);
            break;
        case ROLE:
            populateRoleData(data.getRoot(), (Role) principal);
            break;
        case GROUP:
            populateGroupData(data.getRoot(), (Group) principal);
            break;
    }
    builder.data(data);
    return builder.build();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Aggregations

PropertyTree (com.enonic.xp.data.PropertyTree)660 Test (org.junit.jupiter.api.Test)405 PropertySet (com.enonic.xp.data.PropertySet)150 Content (com.enonic.xp.content.Content)126 Node (com.enonic.xp.node.Node)112 CreateContentParams (com.enonic.xp.content.CreateContentParams)64 Form (com.enonic.xp.form.Form)37 Page (com.enonic.xp.page.Page)32 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)31 DescriptorKey (com.enonic.xp.page.DescriptorKey)30 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)30 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)28 PrincipalKey (com.enonic.xp.security.PrincipalKey)28 BinaryReference (com.enonic.xp.util.BinaryReference)28 Property (com.enonic.xp.data.Property)26 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)24 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)23 ByteSource (com.google.common.io.ByteSource)22 ExtraData (com.enonic.xp.content.ExtraData)21 Instant (java.time.Instant)21