Search in sources :

Example 1 with AttributePermission

use of org.craftercms.profile.api.AttributePermission in project profile by craftercms.

the class TenantServiceImplTest method getAttribute2Definition.

private AttributeDefinition getAttribute2Definition() {
    AttributePermission permission = new AttributePermission(APP_NAME);
    permission.allow(AttributePermission.ANY_ACTION);
    AttributeDefinition def = new AttributeDefinition();
    def.setName(ATTRIB2_NAME);
    def.setMetadata(Collections.<String, Object>singletonMap(LABEL_KEY, ATTRIB2_LABEL));
    def.addPermission(permission);
    def.setDefaultValue(DEFAULT_ATTRIB_VALUE);
    return def;
}
Also used : AttributePermission(org.craftercms.profile.api.AttributePermission) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition)

Example 2 with AttributePermission

use of org.craftercms.profile.api.AttributePermission in project profile by craftercms.

the class TenantServiceImplTest method assertEqualAttributeDefinitions.

private void assertEqualAttributeDefinitions(AttributeDefinition expected, AttributeDefinition actual) {
    List<AttributePermission> expectedPermissions = expected.getPermissions();
    List<AttributePermission> actualPermissions = actual.getPermissions();
    assertEquals(expected.getName(), actual.getName());
    assertEquals(expected.getMetadata(), actual.getMetadata());
    assertNotNull(actualPermissions);
    assertEquals(expectedPermissions.size(), actualPermissions.size());
    for (int i = 0; i < expectedPermissions.size(); i++) {
        AttributePermission expectedPermission = expectedPermissions.get(i);
        AttributePermission actualPermission = actualPermissions.get(i);
        assertEquals(expectedPermission.getApplication(), actualPermission.getApplication());
        assertEquals(expectedPermission.getAllowedActions(), actualPermission.getAllowedActions());
    }
}
Also used : AttributePermission(org.craftercms.profile.api.AttributePermission)

Example 3 with AttributePermission

use of org.craftercms.profile.api.AttributePermission in project profile by craftercms.

the class ProfileServiceImplTest method getAttributeDefinitions.

private List<AttributeDefinition> getAttributeDefinitions() {
    AttributePermission anyAppCanDoAnything = new AttributePermission(AttributePermission.ANY_APPLICATION);
    anyAppCanDoAnything.allow(AttributePermission.ANY_ACTION);
    AttributeDefinition firstNameDefinition = new AttributeDefinition();
    firstNameDefinition.setName(ATTRIB_NAME_FIRST_NAME);
    firstNameDefinition.addPermission(anyAppCanDoAnything);
    AttributeDefinition lastNameDefinition = new AttributeDefinition();
    lastNameDefinition.setName(ATTRIB_NAME_LAST_NAME);
    lastNameDefinition.addPermission(anyAppCanDoAnything);
    AttributeDefinition genderDefinition = new AttributeDefinition();
    genderDefinition.setName(ATTRIB_NAME_GENDER);
    genderDefinition.addPermission(anyAppCanDoAnything);
    genderDefinition.setDefaultValue(GENDER);
    AttributeDefinition privateDefinition = new AttributeDefinition();
    privateDefinition.setName(ATTRIB_NAME_PRIVATE);
    return Arrays.asList(firstNameDefinition, lastNameDefinition, genderDefinition, privateDefinition);
}
Also used : AttributePermission(org.craftercms.profile.api.AttributePermission) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition)

Example 4 with AttributePermission

use of org.craftercms.profile.api.AttributePermission in project profile by craftercms.

the class TenantServiceIT method getGenderAttributeDefinition.

private AttributeDefinition getGenderAttributeDefinition() {
    AttributePermission permission = new AttributePermission(AttributePermission.ANY_APPLICATION);
    permission.allow(AttributePermission.ANY_ACTION);
    AttributeDefinition definition = new AttributeDefinition();
    definition.setName(GENDER_ATTRIBUTE_NAME);
    definition.addPermission(permission);
    return definition;
}
Also used : AttributePermission(org.craftercms.profile.api.AttributePermission) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition)

Example 5 with AttributePermission

use of org.craftercms.profile.api.AttributePermission in project profile by craftercms.

the class AttributePermissionResolver method getPermission.

@Override
public Permission getPermission(AccessToken token, AttributeDefinition definition) throws PermissionException {
    for (AttributePermission permission : definition.getPermissions()) {
        String app = token.getApplication();
        String permittedApp = permission.getApplication();
        if (permittedApp.equals(AttributePermission.ANY_APPLICATION) || permittedApp.equals(app)) {
            return permission;
        }
    }
    return null;
}
Also used : AttributePermission(org.craftercms.profile.api.AttributePermission)

Aggregations

AttributePermission (org.craftercms.profile.api.AttributePermission)10 AttributeDefinition (org.craftercms.profile.api.AttributeDefinition)7