Search in sources :

Example 21 with CustomObjectAttribute

use of io.jans.orm.model.base.CustomObjectAttribute in project jans by JanssenProject.

the class ScimCustomPerson method setCustomAttribute.

public void setCustomAttribute(String attributeName, List<Object> attributeValue) {
    CustomObjectAttribute attribute = new CustomObjectAttribute(attributeName, attributeValue);
    attribute.setMultiValued(true);
    typedCustomAttributes.remove(attribute);
    typedCustomAttributes.add(attribute);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute)

Example 22 with CustomObjectAttribute

use of io.jans.orm.model.base.CustomObjectAttribute in project jans by JanssenProject.

the class ScimCustomPerson method setCustomAttribute.

public void setCustomAttribute(String attributeName, Object attributeValue) {
    CustomObjectAttribute attribute = new CustomObjectAttribute(attributeName, attributeValue);
    typedCustomAttributes.remove(attribute);
    typedCustomAttributes.add(attribute);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute)

Example 23 with CustomObjectAttribute

use of io.jans.orm.model.base.CustomObjectAttribute in project jans by JanssenProject.

the class AttributeService method applyMultiValued.

public void applyMultiValued(List<CustomObjectAttribute> customAttributes) {
    if ((customAttributes == null) || (customAttributes.size() == 0)) {
        return;
    }
    Map<String, GluuAttribute> allAttributesMap = getAllAttributesMap();
    for (CustomObjectAttribute customAttribute : customAttributes) {
        String attributeName = StringHelper.toLowerCase(customAttribute.getName());
        GluuAttribute attribute = allAttributesMap.get(attributeName);
        if (attribute != null) {
            boolean multiValued = Boolean.TRUE.equals(attribute.getOxMultiValuedAttribute());
            customAttribute.setMultiValued(multiValued);
        }
    }
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) GluuAttribute(io.jans.model.GluuAttribute)

Example 24 with CustomObjectAttribute

use of io.jans.orm.model.base.CustomObjectAttribute in project jans by JanssenProject.

the class UserServiceTest method removeUserAttribute_existentAttribute_user.

@Test
private void removeUserAttribute_existentAttribute_user() {
    String userId = "123";
    String baseDn = "dn123";
    User user = spy(getBasicUser("123", "dn123"));
    user.setDn(baseDn);
    CustomObjectAttribute customAttribute1 = new CustomObjectAttribute("attribute1", "value1");
    CustomObjectAttribute customAttribute2 = new CustomObjectAttribute("attribute2", "value2");
    user.setCustomAttributes(new ArrayList<>());
    user.getCustomAttributes().add(customAttribute1);
    user.getCustomAttributes().add(customAttribute2);
    when(dataSourceTypeService.isSpanner(anyString())).thenReturn(true);
    when(persistenceEntryManager.findEntries(anyString(), any(), any(), any())).thenReturn(getListBasicOneUser(user));
    when(persistenceEntryManager.find(anyString(), any(), any())).thenReturn(user);
    doNothing().when(persistenceEntryManager).merge(any());
    User resultUser = userService.removeUserAttributeValue(userId, "attribute1", "value1");
    assertNotNull(resultUser);
    assertTrue(resultUser.getCustomAttributes().get(0).getValues().isEmpty());
// assertTrue(resultUser.getCustomAttributes().size() == 1);
// assertEquals(resultUser.getCustomAttributes().get(0).getName(), "attribute2");
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) User(io.jans.as.common.model.common.User) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 25 with CustomObjectAttribute

use of io.jans.orm.model.base.CustomObjectAttribute in project jans by JanssenProject.

the class UserService method replaceUserAttribute.

public User replaceUserAttribute(String userId, String attributeName, String oldAttributeValue, String newAttributeValue, Boolean multiValued) {
    log.debug("Replace user attribute in LDAP: attributeName = '{}', oldAttributeValue = '{}', newAttributeValue = '{}'", attributeName, oldAttributeValue, newAttributeValue);
    User user = getUser(userId);
    if (user == null) {
        return null;
    }
    CustomObjectAttribute customAttribute = getCustomAttribute(user, attributeName);
    if (customAttribute != null) {
        List<Object> currentAttributeValues = customAttribute.getValues();
        List<Object> newAttributeValues = new ArrayList<>(currentAttributeValues);
        if (currentAttributeValues.contains(oldAttributeValue)) {
            newAttributeValues.remove(oldAttributeValue);
        }
        if (!newAttributeValues.contains(newAttributeValue)) {
            newAttributeValues.add(newAttributeValue);
        }
        customAttribute.setValues(newAttributeValues);
        if (multiValued != null) {
            customAttribute.setMultiValued(multiValued);
        }
    }
    return updateUser(user);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) User(io.jans.as.common.model.common.User) ArrayList(java.util.ArrayList)

Aggregations

CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)32 User (io.jans.as.common.model.common.User)12 Filter (io.jans.orm.search.filter.Filter)9 Test (org.testng.annotations.Test)7 Date (java.util.Date)6 ArrayList (java.util.ArrayList)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 SimpleUser (io.jans.orm.cloud.spanner.model.SimpleUser)4 SimpleUser (io.jans.orm.sql.model.SimpleUser)4 SpannerEntryManager (io.jans.orm.cloud.spanner.impl.SpannerEntryManager)3 SpannerEntryManagerSample (io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample)3 CouchbaseEntryManager (io.jans.orm.couchbase.impl.CouchbaseEntryManager)3 SimpleUser (io.jans.orm.couchbase.model.SimpleUser)3 SqlEntryManager (io.jans.orm.sql.impl.SqlEntryManager)3 SqlEntryManagerSample (io.jans.orm.sql.persistence.SqlEntryManagerSample)3 SimpleUser (io.jans.as.common.model.common.SimpleUser)1 GluuAttribute (io.jans.model.GluuAttribute)1 SimpleAttribute (io.jans.orm.cloud.spanner.model.SimpleAttribute)1 SimpleGrant (io.jans.orm.cloud.spanner.model.SimpleGrant)1 SimpleSession (io.jans.orm.cloud.spanner.model.SimpleSession)1