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;
}
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());
}
}
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);
}
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;
}
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;
}
Aggregations