Search in sources :

Example 1 with IdProviderAccessControlEntry

use of com.enonic.xp.security.acl.IdProviderAccessControlEntry in project xp by enonic.

the class IdProviderNodeTranslator method idProviderPermissionsFromNode.

static IdProviderAccessControlList idProviderPermissionsFromNode(final Node idProviderNode, final Node usersNode, final Node groupsNode) {
    final IdProviderAccessControlList.Builder acl = IdProviderAccessControlList.create();
    final AccessControlList idProviderPermissions = idProviderNode.getPermissions();
    final AccessControlList usersPermissions = usersNode.getPermissions();
    final AccessControlList groupsPermissions = groupsNode.getPermissions();
    final PrincipalKeys principals = PrincipalKeys.from(idProviderPermissions.getAllPrincipals(), usersPermissions.getAllPrincipals(), groupsPermissions.getAllPrincipals());
    for (PrincipalKey principal : principals) {
        if (idProviderPermissions.isAllowedFor(principal, READ, CREATE, MODIFY, DELETE, PUBLISH, READ_PERMISSIONS, WRITE_PERMISSIONS) && usersPermissions.isAllowedFor(principal, READ, CREATE, MODIFY, DELETE, PUBLISH, READ_PERMISSIONS, WRITE_PERMISSIONS) && groupsPermissions.isAllowedFor(principal, READ, CREATE, MODIFY, DELETE, PUBLISH, READ_PERMISSIONS, WRITE_PERMISSIONS)) {
            final IdProviderAccessControlEntry access = IdProviderAccessControlEntry.create().principal(principal).access(ADMINISTRATOR).build();
            acl.add(access);
        } else if (usersPermissions.isAllowedFor(principal, READ, CREATE, MODIFY, DELETE) && groupsPermissions.isAllowedFor(principal, READ, CREATE, MODIFY, DELETE)) {
            final IdProviderAccessControlEntry access = IdProviderAccessControlEntry.create().principal(principal).access(ID_PROVIDER_MANAGER).build();
            acl.add(access);
        } else if (usersPermissions.isAllowedFor(principal, READ, CREATE, MODIFY, DELETE)) {
            final IdProviderAccessControlEntry access = IdProviderAccessControlEntry.create().principal(principal).access(WRITE_USERS).build();
            acl.add(access);
        } else if (usersPermissions.isAllowedFor(principal, CREATE)) {
            final IdProviderAccessControlEntry access = IdProviderAccessControlEntry.create().principal(principal).access(CREATE_USERS).build();
            acl.add(access);
        } else if (usersPermissions.isAllowedFor(principal, READ)) {
            final IdProviderAccessControlEntry access = IdProviderAccessControlEntry.create().principal(principal).access(IdProviderAccess.READ).build();
            acl.add(access);
        }
    }
    return acl.build();
}
Also used : IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) AccessControlList(com.enonic.xp.security.acl.AccessControlList) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) IdProviderAccessControlEntry(com.enonic.xp.security.acl.IdProviderAccessControlEntry) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 2 with IdProviderAccessControlEntry

use of com.enonic.xp.security.acl.IdProviderAccessControlEntry in project xp by enonic.

the class IdProviderNodeTranslator method idProviderPermissionsToUsersNodePermissions.

static AccessControlList idProviderPermissionsToUsersNodePermissions(final IdProviderAccessControlList idProviderPermissions) {
    final List<AccessControlEntry> entries = new ArrayList<>();
    for (IdProviderAccessControlEntry entry : idProviderPermissions) {
        final AccessControlEntry ace;
        switch(entry.getAccess()) {
            case CREATE_USERS:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(CREATE).build();
                entries.add(ace);
                break;
            case WRITE_USERS:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ, CREATE, MODIFY, DELETE).build();
                entries.add(ace);
                break;
            case ID_PROVIDER_MANAGER:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ, CREATE, MODIFY, DELETE).build();
                entries.add(ace);
                break;
            case ADMINISTRATOR:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ, CREATE, MODIFY, DELETE, PUBLISH, READ_PERMISSIONS, WRITE_PERMISSIONS).build();
                entries.add(ace);
                break;
            case READ:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ).build();
                entries.add(ace);
                break;
        }
    }
    return AccessControlList.create().addAll(entries).build();
}
Also used : ArrayList(java.util.ArrayList) IdProviderAccessControlEntry(com.enonic.xp.security.acl.IdProviderAccessControlEntry) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) IdProviderAccessControlEntry(com.enonic.xp.security.acl.IdProviderAccessControlEntry)

Example 3 with IdProviderAccessControlEntry

use of com.enonic.xp.security.acl.IdProviderAccessControlEntry in project xp by enonic.

the class IdProviderNodeTranslator method idProviderPermissionsToGroupsNodePermissions.

static AccessControlList idProviderPermissionsToGroupsNodePermissions(final IdProviderAccessControlList idProviderPermissions) {
    final List<AccessControlEntry> entries = new ArrayList<>();
    for (IdProviderAccessControlEntry entry : idProviderPermissions) {
        final AccessControlEntry ace;
        switch(entry.getAccess()) {
            case ID_PROVIDER_MANAGER:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ, CREATE, MODIFY, DELETE).build();
                entries.add(ace);
                break;
            case ADMINISTRATOR:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ, CREATE, MODIFY, DELETE, PUBLISH, READ_PERMISSIONS, WRITE_PERMISSIONS).build();
                entries.add(ace);
                break;
        }
    }
    return AccessControlList.create().addAll(entries).build();
}
Also used : ArrayList(java.util.ArrayList) IdProviderAccessControlEntry(com.enonic.xp.security.acl.IdProviderAccessControlEntry) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) IdProviderAccessControlEntry(com.enonic.xp.security.acl.IdProviderAccessControlEntry)

Example 4 with IdProviderAccessControlEntry

use of com.enonic.xp.security.acl.IdProviderAccessControlEntry in project xp by enonic.

the class IdProviderNodeTranslator method idProviderPermissionsToIdProviderNodePermissions.

static AccessControlList idProviderPermissionsToIdProviderNodePermissions(final IdProviderAccessControlList idProviderPermissions) {
    final List<AccessControlEntry> entries = new ArrayList<>();
    for (IdProviderAccessControlEntry entry : idProviderPermissions) {
        if (entry.getAccess() == ADMINISTRATOR) {
            final AccessControlEntry ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ, CREATE, MODIFY, DELETE, PUBLISH, READ_PERMISSIONS, WRITE_PERMISSIONS).build();
            entries.add(ace);
        }
    }
    return AccessControlList.create().addAll(entries).build();
}
Also used : ArrayList(java.util.ArrayList) IdProviderAccessControlEntry(com.enonic.xp.security.acl.IdProviderAccessControlEntry) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) IdProviderAccessControlEntry(com.enonic.xp.security.acl.IdProviderAccessControlEntry)

Aggregations

IdProviderAccessControlEntry (com.enonic.xp.security.acl.IdProviderAccessControlEntry)4 AccessControlEntry (com.enonic.xp.security.acl.AccessControlEntry)3 ArrayList (java.util.ArrayList)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)1 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)1 AccessControlList (com.enonic.xp.security.acl.AccessControlList)1 IdProviderAccessControlList (com.enonic.xp.security.acl.IdProviderAccessControlList)1