Search in sources :

Example 21 with AttributeDefinition

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

the class MellonAutoLoginProcessorTest method getTenant.

private Tenant getTenant() {
    AttributeDefinition firstNameDef = new AttributeDefinition(FIRST_NAME_ATTRIB_NAME);
    AttributeDefinition lastNameDef = new AttributeDefinition(LAST_NAME_ATTRIB_NAME);
    Tenant tenant = new Tenant();
    tenant.setName(TENANT_NAME);
    tenant.setSsoEnabled(true);
    tenant.getAttributeDefinitions().add(firstNameDef);
    tenant.getAttributeDefinitions().add(lastNameDef);
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition)

Example 22 with AttributeDefinition

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

the class TenantServiceImplTest method assertEqualAttributeDefinitions.

private void assertEqualAttributeDefinitions(List<AttributeDefinition> expected, List<AttributeDefinition> actual) {
    assertNotNull(expected);
    assertEquals(expected.size(), actual.size());
    Iterator<AttributeDefinition> expectedIter = expected.iterator();
    Iterator<AttributeDefinition> actualIter = actual.iterator();
    while (expectedIter.hasNext()) {
        AttributeDefinition expectedDefinition = expectedIter.next();
        AttributeDefinition actualDefinition = actualIter.next();
        assertEqualAttributeDefinitions(expectedDefinition, actualDefinition);
    }
}
Also used : AttributeDefinition(org.craftercms.profile.api.AttributeDefinition)

Example 23 with AttributeDefinition

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

the class ProfileServiceImpl method filterAttributeIfReadNotAllowed.

protected void filterAttributeIfReadNotAllowed(Tenant tenant, Iterator<String> attributeNamesIter, List<AttributeDefinition> attributeDefinitions) throws PermissionException, AttributeNotDefinedException {
    String tenantName = tenant.getName();
    String attributeName = attributeNamesIter.next();
    AttributeDefinition definition = findAttributeDefinition(attributeDefinitions, attributeName);
    if (definition != null) {
        if (!isAttributeActionAllowed(definition, AttributeAction.READ_ATTRIBUTE)) {
            attributeNamesIter.remove();
        }
    } else {
        throw new AttributeNotDefinedException(attributeName, tenantName);
    }
}
Also used : AttributeDefinition(org.craftercms.profile.api.AttributeDefinition) AttributeNotDefinedException(org.craftercms.profile.exceptions.AttributeNotDefinedException)

Example 24 with AttributeDefinition

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

the class TenantServiceImplTest method getAttribute1Definition.

private AttributeDefinition getAttribute1Definition() {
    AttributePermission permission = new AttributePermission();
    permission.allow(AttributePermission.ANY_ACTION);
    AttributeDefinition def = new AttributeDefinition();
    def.setName(ATTRIB1_NAME);
    def.setMetadata(Collections.<String, Object>singletonMap(LABEL_KEY, ATTRIB1_LABEL));
    def.addPermission(permission);
    return def;
}
Also used : AttributePermission(org.craftercms.profile.api.AttributePermission) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition)

Example 25 with AttributeDefinition

use of org.craftercms.profile.api.AttributeDefinition in project engine by craftercms.

the class ProfileHeadersAuthenticationFilter method createProfileWithSsoInfo.

protected Profile createProfileWithSsoInfo(String username, Tenant tenant, HttpServletRequest request) throws ProfileException {
    Map<String, Object> attributes = null;
    List<AttributeDefinition> attributeDefinitions = tenant.getAttributeDefinitions();
    String email = request.getHeader(getEmailHeaderName());
    for (AttributeDefinition attributeDefinition : attributeDefinitions) {
        String attributeName = attributeDefinition.getName();
        String attributeValue = request.getHeader(getHeaderPrefix() + attributeName);
        if (StringUtils.isNotEmpty(attributeValue)) {
            if (attributes == null) {
                attributes = new HashMap<>();
            }
            attributes.put(attributeName, attributeValue);
        }
    }
    logger.info("Creating new profile with SSO info: username={}, email={}, tenant={}, attributes={}", username, email, tenant.getName(), attributes);
    return profileService.createProfile(tenant.getName(), username, null, email, true, null, attributes, null);
}
Also used : AttributeDefinition(org.craftercms.profile.api.AttributeDefinition)

Aggregations

AttributeDefinition (org.craftercms.profile.api.AttributeDefinition)25 Tenant (org.craftercms.profile.api.Tenant)8 AttributePermission (org.craftercms.profile.api.AttributePermission)7 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)3 Mockito.anyString (org.mockito.Mockito.anyString)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Profile (org.craftercms.profile.api.Profile)2 VerificationToken (org.craftercms.profile.api.VerificationToken)2 ProfileException (org.craftercms.profile.api.exceptions.ProfileException)2 TenantUpdater (org.craftercms.profile.utils.db.TenantUpdater)2 Collection (java.util.Collection)1 Pattern (java.util.regex.Pattern)1 ObjectId (org.bson.types.ObjectId)1 DuplicateKeyException (org.craftercms.commons.mongo.DuplicateKeyException)1 MongoDataException (org.craftercms.commons.mongo.MongoDataException)1 AttributeNotDefinedException (org.craftercms.profile.exceptions.AttributeNotDefinedException)1 InvalidEmailAddressException (org.craftercms.profile.exceptions.InvalidEmailAddressException)1