use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class CopyUtilsTestCreate method testCopyScim1FilledCreate.
@Test
public void testCopyScim1FilledCreate() throws Exception {
GluuCustomPerson destination = new GluuCustomPerson();
ScimPerson source = new ScimPerson();
source.setActive("true");
ScimPersonAddresses address = new ScimPersonAddresses();
address.setCountry("country");
address.setFormatted("formatted");
address.setLocality("locality");
address.setPostalCode("postalCode");
address.setPrimary("address_primary");
address.setRegion("region");
address.setStreetAddress("streetAddress");
address.setType("address_type");
List<ScimPersonAddresses> addresses = new ArrayList<ScimPersonAddresses>();
addresses.add(address);
source.setAddresses(addresses);
List<ScimCustomAttributes> customAttributes = new ArrayList<ScimCustomAttributes>();
ScimCustomAttributes customattribute = new ScimCustomAttributes();
customattribute.setName("custom_name");
List<String> values = new ArrayList<String>();
String value = "value";
values.add(value);
customattribute.setValues(values);
customAttributes.add(customattribute);
source.setCustomAttributes(customAttributes);
source.setDisplayName("displayName");
ScimPersonEmails email = new ScimPersonEmails();
email.setPrimary("email_primary");
email.setType("email_type");
email.setValue("email_value");
List<ScimPersonEmails> emails = new ArrayList<ScimPersonEmails>();
emails.add(email);
source.setEmails(emails);
ScimEntitlements entitlement = new ScimEntitlements();
entitlement.setValue("entitlement_value");
List<ScimEntitlements> entitlements = new ArrayList<ScimEntitlements>();
entitlements.add(entitlement);
source.setEntitlements(entitlements);
source.setExternalId("externalId");
ScimPersonGroups group = new ScimPersonGroups();
group.setDisplay("group_display");
group.setValue("group_value");
List<ScimPersonGroups> groups = new ArrayList<ScimPersonGroups>();
groups.add(group);
source.setGroups(groups);
source.setId("id");
ScimPersonIms personims = new ScimPersonIms();
personims.setType("ims_type");
personims.setValue("ims_value");
List<ScimPersonIms> ims = new ArrayList<ScimPersonIms>();
ims.add(personims);
source.setIms(ims);
source.setLocale("locale");
PersonMeta meta = new PersonMeta();
meta.setCreated("created");
meta.setLastModified("lastModified");
meta.setLocation("location");
meta.setVersion("version");
source.setMeta(meta);
ScimName name = new ScimName();
name.setFamilyName("familyName");
name.setGivenName("givenName");
name.setHonorificPrefix("honorificPrefix");
name.setHonorificSuffix("honorificSuffix");
name.setMiddleName("middleName");
source.setName(name);
source.setNickName("nickName");
source.setPassword("password");
ScimPersonPhones phonenumber = new ScimPersonPhones();
phonenumber.setType("phone_type");
phonenumber.setValue("phone_value");
List<ScimPersonPhones> phoneNumbers = new ArrayList<ScimPersonPhones>();
phoneNumbers.add(phonenumber);
source.setPhoneNumbers(phoneNumbers);
ScimPersonPhotos photo = new ScimPersonPhotos();
photo.setType("photo_type");
photo.setValue("photo_value");
List<ScimPersonPhotos> photos = new ArrayList<ScimPersonPhotos>();
photos.add(photo);
source.setPhotos(photos);
source.setPreferredLanguage("preferredLanguage");
source.setProfileUrl("profileUrl");
ScimRoles role = new ScimRoles();
role.setValue("role_value");
List<ScimRoles> roles = new ArrayList<ScimRoles>();
roles.add(role);
source.setRoles(roles);
List<String> schemas = new ArrayList<String>();
schemas.add("shema");
source.setSchemas(schemas);
source.setTimezone("timezone");
source.setTitle("title");
source.setUserName("userName");
source.setUserType("userType");
Scimx509Certificates cert = new Scimx509Certificates();
cert.setValue("cert_value");
List<Scimx509Certificates> x509Certificates = new ArrayList<Scimx509Certificates>();
x509Certificates.add(cert);
source.setX509Certificates(x509Certificates);
GluuCustomPerson copy = copyUtils.copy(source, destination, false);
assertNotNull(copy);
assertEquals(copy.getUid(), "userName");
assertEquals(copy.getGivenName(), "givenName");
assertEquals(copy.getSurname(), "familyName");
assertEquals(copy.getDisplayName(), "displayName");
assertEquals(copy.getPreferredLanguage(), "preferredLanguage");
assertEquals(copy.getTimezone(), "timezone");
assertEquals(copy.getUserPassword(), "password");
assertNotNull(copy.getMemberOf());
assertEquals(copy.getMemberOf().size(), 1);
assertEquals(copy.getMemberOf().get(0), "Mocked DN");
assertEquals(copy.getAttribute(GLUU_STATUS), "true");
assertNull(copy.getAttribute(OX_TRUST_PHOTOS_TYPE));
assertNull(copy.getAttribute(OX_TRUST_PHONE_TYPE));
assertNull(copy.getAttribute(OX_TRUST_ADDRESS_PRIMARY));
assertNull(copy.getAttribute(OX_TRUST_ADDRESS_TYPE));
assertNull(copy.getAttribute(OX_TRUST_COUNTRY));
assertNull(copy.getAttribute(OX_TRUST_POSTAL_CODE));
assertNull(copy.getAttribute(OX_TRUST_REGION));
assertNull(copy.getAttribute(OX_TRUST_LOCALITY));
assertNull(copy.getAttribute(OX_TRUST_ADDRESS_FORMATTED));
assertNull(copy.getAttribute(OX_TRUST_STREET));
assertNull(copy.getAttribute(OX_TRUST_EMAIL_PRIMARY));
assertNull(copy.getAttribute(OX_TRUST_EMAIL_TYPE));
assertEquals(copy.getAttribute(OX_TRUST_META_LOCATION), "location");
assertEquals(copy.getAttribute(OX_TRUST_META_VERSION), "version");
assertEquals(copy.getAttribute(OX_TRUST_META_LAST_MODIFIED), "lastModified");
assertEquals(copy.getAttribute(OX_TRUST_META_CREATED), "created");
assertEquals(copy.getAttribute(OX_TRUSTX509_CERTIFICATE), "[{\"value\":\"cert_value\"}]");
assertEquals(copy.getAttribute(OX_TRUST_ENTITLEMENTS), "[{\"value\":\"entitlement_value\"}]");
assertEquals(copy.getAttribute(OX_TRUST_ROLE), "[{\"value\":\"role_value\"}]");
assertEquals(copy.getAttribute(OX_TRUST_ACTIVE), "true");
assertEquals(copy.getAttribute(OX_TRUST_LOCALE), "locale");
assertEquals(copy.getAttribute(OX_TRUST_TITLE), "title");
assertEquals(copy.getAttribute(OX_TRUST_USER_TYPE), "userType");
assertEquals(copy.getAttribute(OX_TRUST_PHOTOS), "[{\"value\":\"photo_value\",\"type\":\"photo_type\"}]");
assertEquals(copy.getAttribute(OX_TRUST_IMS_VALUE), "[{\"value\":\"ims_value\",\"type\":\"ims_type\"}]");
assertEquals(copy.getAttribute(OX_TRUST_PHONE_VALUE), "[{\"value\":\"phone_value\",\"type\":\"phone_type\"}]");
assertEquals(copy.getAttribute(OX_TRUST_ADDRESSES), "[{\"type\":\"address_type\",\"streetAddress\":\"streetAddress\",\"locality\":\"locality\",\"region\":\"region\",\"postalCode\":\"postalCode\",\"country\":\"country\",\"formatted\":\"formatted\",\"primary\":\"address_primary\"}]");
assertEquals(copy.getAttribute(OX_TRUST_EMAIL), "[{\"value\":\"email_value\",\"type\":\"email_type\",\"primary\":\"email_primary\"}]");
assertEquals(copy.getAttribute(OX_TRUST_PROFILE_URL), "profileUrl");
assertEquals(copy.getAttribute(OX_TRUST_NICK_NAME), "nickName");
assertEquals(copy.getAttribute(OX_TRUST_EXTERNAL_ID), "externalId");
assertEquals(copy.getAttribute(OX_TRUSTHONORIFIC_SUFFIX), "honorificSuffix");
assertEquals(copy.getAttribute(OX_TRUSTHONORIFIC_PREFIX), "honorificPrefix");
assertEquals(copy.getAttribute(OX_TRUST_MIDDLE_NAME), "middleName");
assertNull(copy.getAssociatedClient());
assertNull(copy.getBaseDn());
assertNull(copy.getCommonName());
List<GluuCustomAttribute> customAttributes2 = copy.getCustomAttributes();
assertNotNull(customAttributes2);
assertEquals(customAttributes2.size(), 32);
assertEquals(copy.getDisplayName(), "displayName");
assertNull(copy.getDn());
assertEquals(copy.getGivenName(), "givenName");
assertNull(copy.getGluuAllowPublication());
GluuCustomAttribute gluuCustomAttribute = copy.getGluuCustomAttribute("custom_name");
assertNotNull(gluuCustomAttribute);
assertEquals(gluuCustomAttribute.getName(), "custom_name");
assertEquals(gluuCustomAttribute.getValue(), "value");
assertNull(gluuCustomAttribute.getDate());
assertEquals(gluuCustomAttribute.getDisplayValue(), "value");
assertNull(gluuCustomAttribute.getMetadata());
assertEquals(gluuCustomAttribute.getValues()[0], "value");
assertNull(copy.getGluuOptOuts());
assertNull(copy.getIname());
assertNull(copy.getMail());
assertEquals(copy.getMemberOf().get(0), "Mocked DN");
assertNull(copy.getNetworkPoken());
assertNull(copy.getCreationDate());
assertEquals(copy.getPreferredLanguage(), "preferredLanguage");
assertNull(copy.getSLAManager());
assertNull(copy.getSourceServerName());
assertNull(copy.getStatus());
assertEquals(copy.getSurname(), "familyName");
assertEquals(copy.getTimezone(), "timezone");
assertEquals(copy.getUid(), "userName");
assertEquals(copy.getUserPassword(), "password");
}
use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class ConfigureCacheRefreshAction method validateInterceptorScript.
public void validateInterceptorScript() {
String result = update();
if (!OxTrustConstants.RESULT_SUCCESS.equals(result)) {
return;
}
// Reinit dialog
init();
this.showInterceptorValidationDialog = true;
boolean loadedScripts = externalCacheRefreshService.getCustomScriptConfigurations().size() > 0;
if (!loadedScripts) {
String message = "Can't load Cache Refresh scripts. Using default script";
log.error(message);
this.interceptorValidationMessage = message;
return;
}
// Prepare data for dummy entry
String targetInum = inumService.generateInums(OxTrustConstants.INUM_TYPE_PEOPLE_SLUG, false);
String targetPersonDn = personService.getDnForPerson(targetInum);
String[] targetCustomObjectClasses = appConfiguration.getPersonObjectClassTypes();
// Collect all attributes
String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
// Merge all attributes into one set
Set<String> allAttributes = new HashSet<String>();
for (String attribute : keyAttributesWithoutValues) {
allAttributes.add(attribute);
}
for (String attribute : sourceAttributes) {
allAttributes.add(attribute);
}
// Prepare source person entry with default attributes values
GluuSimplePerson sourcePerson = new GluuSimplePerson();
List<GluuCustomAttribute> customAttributes = sourcePerson.getCustomAttributes();
for (String attribute : allAttributes) {
customAttributes.add(new GluuCustomAttribute(attribute, "Test value"));
}
// Prepare target person
GluuCustomPerson targetPerson = new GluuCustomPerson();
targetPerson.setDn(targetPersonDn);
targetPerson.setInum(targetInum);
targetPerson.setStatus(GluuStatus.ACTIVE);
targetPerson.setCustomObjectClasses(targetCustomObjectClasses);
// Execute mapping according to configuration
Map<String, String> targetServerAttributesMapping = getTargetServerAttributesMapping(cacheRefreshConfiguration);
cacheRefreshService.setTargetEntryAttributes(sourcePerson, targetServerAttributesMapping, targetPerson);
// Execute interceptor script
boolean executionResult = externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
if (!executionResult) {
String message = "Can't execute Cache Refresh scripts.";
log.error(message);
this.interceptorValidationMessage = message;
return;
}
log.info("Script has been executed successfully.\n\nSample source entry is:\n'{}'.\n\nSample result entry is:\n'{}'", getGluuSimplePersonAttributesWithValues(sourcePerson), getGluuCustomPersonAttributesWithValues(targetPerson));
this.interceptorValidationMessage = String.format("Script has been executed successfully.\n\nSample source entry is:\n%s.\n\nSample result entry is:\n%s", getGluuSimplePersonAttributesWithValues(sourcePerson), getGluuCustomPersonAttributesWithValues(targetPerson));
}
use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class RegisterPersonAction method initAttributes.
private void initAttributes() {
List<GluuAttribute> allPersonAttributes = attributeService.getAllActivePersonAttributes(GluuUserRole.ADMIN);
List<String> allAttributOrigins = attributeService.getAllAttributeOrigins(allPersonAttributes);
GluuOrganization organization = organizationService.getOrganization();
List<GluuCustomAttribute> customAttributes = this.person.getCustomAttributes();
boolean isNewPerson = (customAttributes == null) || customAttributes.isEmpty();
if (isNewPerson) {
customAttributes = new ArrayList<GluuCustomAttribute>();
this.person.setCustomAttributes(customAttributes);
}
String[] personOCs = appConfiguration.getPersonObjectClassTypes();
String[] personOCDisplayNames = appConfiguration.getPersonObjectClassDisplayNames();
customAttributeAction.initCustomAttributes(allPersonAttributes, customAttributes, allAttributOrigins, personOCs, personOCDisplayNames);
List<GluuCustomAttribute> mandatoryAttributes = new ArrayList<GluuCustomAttribute>();
RegistrationConfiguration config = organization.getOxRegistrationConfiguration();
boolean registrationCustomized = config != null;
boolean registrationAttributesCustomized = registrationCustomized && config.getAdditionalAttributes() != null && !config.getAdditionalAttributes().isEmpty();
if (registrationAttributesCustomized) {
for (String attributeInum : config.getAdditionalAttributes()) {
GluuAttribute attribute = attributeService.getAttributeByInum(attributeInum);
GluuCustomAttribute customAttribute = new GluuCustomAttribute(attribute.getName(), "", false, false);
mandatoryAttributes.add(customAttribute);
}
}
for (GluuCustomAttribute attribute : personService.getMandatoryAtributes()) {
if (!mandatoryAttributes.contains(attribute)) {
mandatoryAttributes.add(attribute);
}
}
mandatoryAttributes.addAll(personService.getMandatoryAtributes());
if (isNewPerson) {
customAttributeAction.addCustomAttributes(mandatoryAttributes);
}
hiddenAttributes = new ArrayList<String>();
hiddenAttributes.add("inum");
hiddenAttributes.add("iname");
hiddenAttributes.add("userPassword");
hiddenAttributes.add("gluuStatus");
hiddenAttributes.add("oxExternalUid");
hiddenAttributes.add("oxLastLogonTime");
}
use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class RegisterPersonAction method register.
public String register() throws CloneNotSupportedException {
boolean registrationFormValid = StringHelper.equals(password, repeatPassword);
if (!captchaDisabled) {
boolean reCaptchaResponse = recaptchaService.verifyRecaptchaResponse();
registrationFormValid &= reCaptchaResponse;
}
if (registrationFormValid) {
GluuCustomPerson archivedPerson = (GluuCustomPerson) person.clone();
String customObjectClass = attributeService.getCustomOrigin();
this.person.setCustomObjectClasses(new String[] { customObjectClass });
// Save person
if (person.getInum() == null) {
String inum = personService.generateInumForNewPerson();
this.person.setInum(inum);
}
if (person.getIname() == null) {
String iname = personService.generateInameForNewPerson(this.person.getUid());
this.person.setIname(iname);
}
if (person.getDn() == null) {
String dn = personService.getDnForPerson(this.person.getInum());
this.person.setDn(dn);
}
List<GluuCustomAttribute> personAttributes = this.person.getCustomAttributes();
if (!personAttributes.contains(new GluuCustomAttribute("cn", ""))) {
List<GluuCustomAttribute> changedAttributes = new ArrayList<GluuCustomAttribute>();
changedAttributes.addAll(personAttributes);
changedAttributes.add(new GluuCustomAttribute("cn", this.person.getGivenName() + " " + this.person.getSurname()));
this.person.setCustomAttributes(changedAttributes);
} else {
this.person.setCommonName(this.person.getCommonName());
}
// save password
this.person.setUserPassword(password);
this.person.setCreationDate(new Date());
this.person.setMail(email);
try {
// Set default message
this.postRegistrationInformation = "You have successfully registered with oxTrust. Login to begin your session.";
boolean result = externalUserRegistrationService.executeExternalPreRegistrationMethods(this.person, requestParameters);
if (!result) {
this.person = archivedPerson;
return OxTrustConstants.RESULT_FAILURE;
}
if (this.inum != null) {
personService.updatePerson(this.person);
} else {
personService.addPerson(this.person);
}
result = externalUserRegistrationService.executeExternalPostRegistrationMethods(this.person, requestParameters);
if (!result) {
this.person = archivedPerson;
return OxTrustConstants.RESULT_FAILURE;
}
} catch (Exception ex) {
log.error("Failed to add new person {}", ex, this.person.getInum());
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to add new person");
this.person = archivedPerson;
return OxTrustConstants.RESULT_FAILURE;
}
return OxTrustConstants.RESULT_SUCCESS;
}
return OxTrustConstants.RESULT_CAPTCHA_VALIDATION_FAILED;
}
use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class Shibboleth3ConfService method initAttributeParamMap.
private HashMap<String, Object> initAttributeParamMap(List<GluuSAMLTrustRelationship> trustRelationships) {
HashMap<String, Object> attrParams = new HashMap<String, Object>();
// Collect attributes
List<GluuAttribute> attributes = new ArrayList<GluuAttribute>();
List<String> attributeNames = new ArrayList<String>();
for (GluuSAMLTrustRelationship trustRelationship : trustRelationships) {
for (GluuCustomAttribute customAttribute : trustRelationship.getReleasedCustomAttributes()) {
GluuAttribute metadata = customAttribute.getMetadata();
if (!attributes.contains(metadata)) {
attributes.add(metadata);
String attributeName = metadata.getName();
attributeNames.add(attributeName);
}
}
}
SchemaEntry schemaEntry = shemaService.getSchema();
List<AttributeTypeDefinition> attributeTypes = shemaService.getAttributeTypeDefinitions(schemaEntry, attributeNames);
Map<String, String> attributeSAML1Strings = new HashMap<String, String>();
Map<String, String> attributeSAML2Strings = new HashMap<String, String>();
for (GluuAttribute metadata : attributes) {
String attributeName = metadata.getName();
AttributeTypeDefinition attributeTypeDefinition = shemaService.getAttributeTypeDefinition(attributeTypes, attributeName);
if (attributeTypeDefinition == null) {
log.error("Failed to get OID for attribute name {}", attributeName);
return null;
}
//
// urn::dir:attribute-def:$attribute.name
// urn:oid:$attrParams.attributeOids.get($attribute.name)
String saml1String = metadata.getSaml1Uri();
if (StringHelper.isEmpty(saml1String)) {
boolean standard = metadata.isCustom() || StringHelper.isEmpty(metadata.getUrn()) || (!StringHelper.isEmpty(metadata.getUrn()) && metadata.getUrn().startsWith("urn:gluu:dir:attribute-def:"));
saml1String = String.format("urn:%s:dir:attribute-def:%s", standard ? "gluu" : "mace", attributeName);
}
attributeSAML1Strings.put(attributeName, saml1String);
String saml2String = metadata.getSaml2Uri();
if (StringHelper.isEmpty(saml2String)) {
saml2String = String.format("urn:oid:%s", attributeTypeDefinition.getOID());
}
attributeSAML2Strings.put(attributeName, saml2String);
}
attrParams.put("attributes", attributes);
attrParams.put("attributeSAML1Strings", attributeSAML1Strings);
attrParams.put("attributeSAML2Strings", attributeSAML2Strings);
return attrParams;
}
Aggregations