use of org.gluu.oxtrust.model.scim2.Meta in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
/**
* Copy data from GluuCustomPerson object to ScimPerson object "Reda"
*
* @param source
* @param destination
* @return
* @throws Exception
*/
public User copy(GluuCustomPerson source, User destination) throws Exception {
if (source == null) {
return null;
}
if (destination == null) {
log.trace(" creating a new GluuCustomPerson instant ");
destination = new User();
}
log.trace(" setting ID ");
if (source.getInum() != null) {
destination.setId(source.getInum());
}
log.trace(" setting userName ");
if (source.getUid() != null) {
destination.setUserName(source.getUid());
}
log.trace(" setting ExternalID ");
if (source.getAttribute("oxTrustExternalId") != null) {
destination.setExternalId(source.getAttribute("oxTrustExternalId"));
}
log.trace(" setting givenname ");
if (source.getGivenName() != null) {
org.gluu.oxtrust.model.scim2.Name name = new org.gluu.oxtrust.model.scim2.Name();
name.setGivenName(source.getGivenName());
if (source.getSurname() != null)
name.setFamilyName(source.getSurname());
if (source.getAttribute("middleName") != null)
name.setMiddleName(source.getAttribute("middleName"));
/*
if (source.getAttribute("oxTrustMiddleName") != null)
name.setMiddleName(source.getAttribute("oxTrustMiddleName"));
*/
if (source.getAttribute("oxTrusthonorificPrefix") != null)
name.setHonorificPrefix(source.getAttribute("oxTrusthonorificPrefix"));
if (source.getAttribute("oxTrusthonorificSuffix") != null)
name.setHonorificSuffix(source.getAttribute("oxTrusthonorificSuffix"));
name.setFormatted(name.getFormatted());
destination.setName(name);
}
log.trace(" getting displayname ");
if (source.getDisplayName() != null) {
destination.setDisplayName(source.getDisplayName());
}
log.trace(" getting nickname ");
/*
if (source.getAttribute("oxTrustNickName") != null) {
destination.setNickName(source.getAttribute("oxTrustNickName"));
}
*/
if (source.getAttribute("nickname") != null) {
destination.setNickName(source.getAttribute("nickname"));
}
log.trace(" getting profileURL ");
if (source.getAttribute("oxTrustProfileURL") != null) {
destination.setProfileUrl(source.getAttribute("oxTrustProfileURL"));
}
log.trace(" getting emails ");
// source = Utils.syncEmailReverse(source, true);
if (source.getAttributeArray("oxTrustEmail") != null) {
/*
String[] emailArray = source.getAttributeArray("oxTrustEmail");
List<Email> emails = new ArrayList<Email>();
for (String emailStr : emailArray) {
Email email = mapper.readValue(emailStr, Email.class);
emails.add(email);
}
// List<Email> listOfEmails = mapper.readValue(source.getAttribute("oxTrustEmail"), new TypeReference<List<Email>>(){});
// destination.setEmails(listOfEmails);
*/
List<Email> emails = getAttributeListValue(source, Email.class, "oxTrustEmail");
destination.setEmails(emails);
}
log.trace(" getting addresses ");
// getting addresses
if (source.getAttribute("oxTrustAddresses") != null) {
List<Address> addresses = getAttributeListValue(source, Address.class, "oxTrustAddresses");
destination.setAddresses(addresses);
}
log.trace(" setting phoneNumber ");
// getting user's PhoneNumber
if (source.getAttribute("oxTrustPhoneValue") != null) {
List<PhoneNumber> phoneNumbers = getAttributeListValue(source, PhoneNumber.class, "oxTrustPhoneValue");
destination.setPhoneNumbers(phoneNumbers);
}
if ((source.getOxPPID()) != null) {
destination.setPairwiseIdentitifers(source.getOxPPID());
}
log.trace(" getting ims ");
// getting ims
if (source.getAttribute("oxTrustImsValue") != null) {
List<Im> ims = getAttributeListValue(source, Im.class, "oxTrustImsValue");
destination.setIms(ims);
}
log.trace(" setting photos ");
// getting photos
if (source.getAttribute("oxTrustPhotos") != null) {
List<Photo> photos = getAttributeListValue(source, Photo.class, "oxTrustPhotos");
destination.setPhotos(photos);
}
log.trace(" setting userType ");
if (source.getAttribute("oxTrustUserType") != null) {
destination.setUserType(source.getAttribute("oxTrustUserType"));
}
log.trace(" setting title ");
if (source.getAttribute("oxTrustTitle") != null) {
destination.setTitle(source.getAttribute("oxTrustTitle"));
}
log.trace(" setting Locale ");
/*
if (source.getAttribute("oxTrustLocale") != null) {
destination.setLocale(source.getAttribute("oxTrustLocale"));
}
*/
if (source.getAttribute("locale") != null) {
destination.setLocale(source.getAttribute("locale"));
}
log.trace(" setting preferredLanguage ");
if (source.getPreferredLanguage() != null) {
destination.setPreferredLanguage(source.getPreferredLanguage());
}
log.trace(" setting timeZone ");
if (source.getTimezone() != null) {
destination.setTimezone(source.getTimezone());
}
log.trace(" setting active ");
if (source.getAttribute("oxTrustActive") != null) {
destination.setActive(Boolean.parseBoolean(source.getAttribute("oxTrustActive")));
}
log.trace(" setting password ");
destination.setPassword("Hidden for Privacy Reasons");
// getting user groups
log.trace(" setting groups ");
if (source.getMemberOf() != null) {
List<String> listOfGroups = source.getMemberOf();
List<GroupRef> groupRefList = new ArrayList<GroupRef>();
for (String groupDN : listOfGroups) {
GluuGroup gluuGroup = groupService.getGroupByDn(groupDN);
GroupRef groupRef = new GroupRef();
groupRef.setDisplay(gluuGroup.getDisplayName());
groupRef.setValue(gluuGroup.getInum());
String reference = appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/" + gluuGroup.getInum();
groupRef.setReference(reference);
groupRefList.add(groupRef);
}
destination.setGroups(groupRefList);
}
// getting roles
if (source.getAttribute("oxTrustRole") != null) {
List<Role> roles = getAttributeListValue(source, Role.class, "oxTrustRole");
destination.setRoles(roles);
}
log.trace(" getting entitlements ");
// getting entitlements
if (source.getAttribute("oxTrustEntitlements") != null) {
List<Entitlement> entitlements = getAttributeListValue(source, Entitlement.class, "oxTrustEntitlements");
destination.setEntitlements(entitlements);
}
// getting x509Certificates
log.trace(" setting certs ");
if (source.getAttribute("oxTrustx509Certificate") != null) {
List<X509Certificate> x509Certificates = getAttributeListValue(source, X509Certificate.class, "oxTrustx509Certificate");
destination.setX509Certificates(x509Certificates);
}
log.trace(" setting extensions ");
// List<GluuAttribute> scimCustomAttributes = attributeService.getSCIMRelatedAttributesImpl(attributeService.getCustomAttributes());
List<GluuAttribute> scimCustomAttributes = attributeService.getSCIMRelatedAttributes();
if (scimCustomAttributes != null && !scimCustomAttributes.isEmpty()) {
Map<String, Extension> extensionMap = new HashMap<String, Extension>();
Extension.Builder extensionBuilder = new Extension.Builder(Constants.USER_EXT_SCHEMA_ID);
boolean hasExtension = false;
outer: for (GluuCustomAttribute customAttribute : source.getCustomAttributes()) {
for (GluuAttribute scimCustomAttribute : scimCustomAttributes) {
if (customAttribute.getName().equals(scimCustomAttribute.getName())) {
hasExtension = true;
GluuAttributeDataType scimCustomAttributeDataType = scimCustomAttribute.getDataType();
if ((scimCustomAttribute.getOxMultivaluedAttribute() != null) && scimCustomAttribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE)) {
extensionBuilder.setFieldAsList(customAttribute.getName(), Arrays.asList(customAttribute.getValues()));
} else {
if (scimCustomAttributeDataType.equals(GluuAttributeDataType.STRING) || scimCustomAttributeDataType.equals(GluuAttributeDataType.PHOTO)) {
String value = ExtensionFieldType.STRING.fromString(customAttribute.getValue());
extensionBuilder.setField(customAttribute.getName(), value);
} else if (scimCustomAttributeDataType.equals(GluuAttributeDataType.DATE)) {
Date value = ExtensionFieldType.DATE_TIME.fromString(customAttribute.getValue());
extensionBuilder.setField(customAttribute.getName(), value);
} else if (scimCustomAttributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
BigDecimal value = ExtensionFieldType.DECIMAL.fromString(customAttribute.getValue());
extensionBuilder.setField(customAttribute.getName(), value);
}
}
continue outer;
}
}
}
if (hasExtension) {
extensionMap.put(Constants.USER_EXT_SCHEMA_ID, extensionBuilder.build());
destination.getSchemas().add(Constants.USER_EXT_SCHEMA_ID);
destination.setExtensions(extensionMap);
}
}
log.trace(" getting meta ");
Meta meta = (destination.getMeta() != null) ? destination.getMeta() : new Meta();
if (source.getAttribute("oxTrustMetaVersion") != null) {
meta.setVersion(source.getAttribute("oxTrustMetaVersion"));
}
String location = source.getAttribute("oxTrustMetaLocation");
if (location != null && !location.isEmpty()) {
if (!location.startsWith("https://") && !location.startsWith("http://")) {
location = appConfiguration.getBaseEndpoint() + location;
}
} else {
location = appConfiguration.getBaseEndpoint() + "/scim/v2/Users/" + source.getInum();
}
meta.setLocation(location);
if (source.getAttribute("oxTrustMetaCreated") != null && !source.getAttribute("oxTrustMetaCreated").isEmpty()) {
try {
DateTime dateTimeUtc = new DateTime(source.getAttribute("oxTrustMetaCreated"), DateTimeZone.UTC);
meta.setCreated(dateTimeUtc.toDate());
} catch (Exception e) {
log.error(" Date parse exception (NEW format), continuing...", e);
// For backward compatibility
try {
meta.setCreated(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(source.getAttribute("oxTrustMetaCreated")));
} catch (Exception ex) {
log.error(" Date parse exception (OLD format)", ex);
}
}
}
if (source.getAttribute("oxTrustMetaLastModified") != null && !source.getAttribute("oxTrustMetaLastModified").isEmpty()) {
try {
DateTime dateTimeUtc = new DateTime(source.getAttribute("oxTrustMetaLastModified"), DateTimeZone.UTC);
meta.setLastModified(dateTimeUtc.toDate());
} catch (Exception e) {
log.error(" Date parse exception (NEW format), continuing...", e);
// For backward compatibility
try {
meta.setLastModified(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(source.getAttribute("oxTrustMetaLastModified")));
} catch (Exception ex) {
log.error(" Date parse exception (OLD format)", ex);
}
}
}
destination.setMeta(meta);
return destination;
}
use of org.gluu.oxtrust.model.scim2.Meta in project oxTrust by GluuFederation.
the class ResourceTypeWS method getResourceTypeUser.
@Path("User")
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response getResourceTypeUser(@HeaderParam("Authorization") String authorization) throws Exception {
ResourceType userResourceType = new ResourceType();
userResourceType.setDescription(Constants.USER_CORE_SCHEMA_DESCRIPTION);
userResourceType.setEndpoint("/v2/Users");
userResourceType.setName(Constants.USER_CORE_SCHEMA_NAME);
userResourceType.setId(Constants.USER_CORE_SCHEMA_NAME);
userResourceType.setSchema(Constants.USER_CORE_SCHEMA_ID);
Meta userMeta = new Meta();
userMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
userMeta.setResourceType("ResourceType");
userResourceType.setMeta(userMeta);
List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
userExtensionSchema.setSchema(Constants.USER_EXT_SCHEMA_ID);
userExtensionSchema.setRequired(false);
schemaExtensions.add(userExtensionSchema);
userResourceType.setSchemaExtensions(schemaExtensions);
// ResourceType[] resourceTypes = new ResourceType[]{userResourceType};
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
// return Response.ok(resourceTypes).location(location).build();
return Response.ok(userResourceType).location(location).build();
}
use of org.gluu.oxtrust.model.scim2.Meta in project oxTrust by GluuFederation.
the class ResourceTypeWS method listResources.
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response listResources(@HeaderParam("Authorization") String authorization) throws Exception {
ListResponse listResponse = new ListResponse();
List<String> schemas = new ArrayList<String>();
schemas.add(Constants.LIST_RESPONSE_SCHEMA_ID);
listResponse.setSchemas(schemas);
// START: User
ResourceType userResourceType = new ResourceType();
userResourceType.setDescription(Constants.USER_CORE_SCHEMA_DESCRIPTION);
userResourceType.setEndpoint("/v2/Users");
userResourceType.setName(Constants.USER_CORE_SCHEMA_NAME);
userResourceType.setId(Constants.USER_CORE_SCHEMA_NAME);
userResourceType.setSchema(Constants.USER_CORE_SCHEMA_ID);
Meta userMeta = new Meta();
userMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
userMeta.setResourceType("ResourceType");
userResourceType.setMeta(userMeta);
List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
userExtensionSchema.setSchema(Constants.USER_EXT_SCHEMA_ID);
userExtensionSchema.setRequired(false);
schemaExtensions.add(userExtensionSchema);
userResourceType.setSchemaExtensions(schemaExtensions);
// START: Group
ResourceType groupResourceType = new ResourceType();
groupResourceType.setDescription(Constants.GROUP_CORE_SCHEMA_DESCRIPTION);
groupResourceType.setEndpoint("/v2/Groups");
groupResourceType.setName(Constants.GROUP_CORE_SCHEMA_NAME);
groupResourceType.setId(Constants.GROUP_CORE_SCHEMA_NAME);
groupResourceType.setSchema(Constants.GROUP_CORE_SCHEMA_ID);
Meta groupMeta = new Meta();
groupMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/Group");
groupMeta.setResourceType("ResourceType");
groupResourceType.setMeta(groupMeta);
// START: FidoDevice
ResourceType fidoDeviceResourceType = new ResourceType();
fidoDeviceResourceType.setDescription(Constants.FIDO_DEVICES_CORE_SCHEMA_DESCRIPTION);
fidoDeviceResourceType.setEndpoint("/v2/FidoDevices");
fidoDeviceResourceType.setName(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
fidoDeviceResourceType.setId(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
fidoDeviceResourceType.setSchema(Constants.FIDO_DEVICES_CORE_SCHEMA_ID);
Meta fidoDeviceMeta = new Meta();
fidoDeviceMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/FidoDevice");
fidoDeviceMeta.setResourceType("ResourceType");
fidoDeviceResourceType.setMeta(fidoDeviceMeta);
// ResourceType[] resourceTypes = new ResourceType[]{userResourceType, groupResourceType};
List<Resource> resourceTypes = new ArrayList<Resource>();
resourceTypes.add(userResourceType);
resourceTypes.add(groupResourceType);
resourceTypes.add(fidoDeviceResourceType);
listResponse.setResources(resourceTypes);
listResponse.setTotalResults(resourceTypes.size());
listResponse.setItemsPerPage(10);
listResponse.setStartIndex(1);
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes");
// return Response.ok(resourceTypes).location(location).build();
return Response.ok(listResponse).location(location).build();
}
use of org.gluu.oxtrust.model.scim2.Meta in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
/**
* Copy data from GluuGroup object to ScimGroup object
*
* @param source
* @param destination
* @return
* @throws Exception
*/
public Group copy(GluuGroup source, Group destination) throws Exception {
if (source == null) {
return null;
}
if (destination == null) {
destination = new Group();
}
destination.setDisplayName(source.getDisplayName());
destination.setId(source.getInum());
if (source.getMembers() != null) {
if (source.getMembers().size() > 0) {
Set<MemberRef> memberRefSet = new HashSet<MemberRef>();
List<String> membersList = source.getMembers();
for (String oneMember : membersList) {
if (oneMember != null && !oneMember.isEmpty()) {
GluuCustomPerson gluuCustomPerson = personService.getPersonByDn(oneMember);
MemberRef memberRef = new MemberRef();
memberRef.setValue(gluuCustomPerson.getInum());
memberRef.setDisplay(gluuCustomPerson.getDisplayName());
String reference = appConfiguration.getBaseEndpoint() + "/scim/v2/Users/" + gluuCustomPerson.getInum();
memberRef.setReference(reference);
memberRefSet.add(memberRef);
}
}
destination.setMembers(memberRefSet);
}
}
log.trace(" getting meta ");
Meta meta = (destination.getMeta() != null) ? destination.getMeta() : new Meta();
if (source.getAttribute("oxTrustMetaVersion") != null) {
meta.setVersion(source.getAttribute("oxTrustMetaVersion"));
}
String location = source.getAttribute("oxTrustMetaLocation");
if (location != null && !location.isEmpty()) {
if (!location.startsWith("https://") && !location.startsWith("http://")) {
location = appConfiguration.getBaseEndpoint() + location;
}
} else {
location = appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/" + source.getInum();
}
meta.setLocation(location);
if (source.getAttribute("oxTrustMetaCreated") != null && !source.getAttribute("oxTrustMetaCreated").isEmpty()) {
try {
DateTime dateTimeUtc = new DateTime(source.getAttribute("oxTrustMetaCreated"), DateTimeZone.UTC);
meta.setCreated(dateTimeUtc.toDate());
} catch (Exception e) {
log.error(" Date parse exception (NEW format), continuing...", e);
// For backward compatibility
try {
meta.setCreated(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(source.getAttribute("oxTrustMetaCreated")));
} catch (Exception ex) {
log.error(" Date parse exception (OLD format)", ex);
}
}
}
if (source.getAttribute("oxTrustMetaLastModified") != null && !source.getAttribute("oxTrustMetaLastModified").isEmpty()) {
try {
DateTime dateTimeUtc = new DateTime(source.getAttribute("oxTrustMetaLastModified"), DateTimeZone.UTC);
meta.setLastModified(dateTimeUtc.toDate());
} catch (Exception e) {
log.error(" Date parse exception (NEW format), continuing...", e);
// For backward compatibility
try {
meta.setLastModified(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(source.getAttribute("oxTrustMetaLastModified")));
} catch (Exception ex) {
log.error(" Date parse exception (OLD format)", ex);
}
}
}
destination.setMeta(meta);
return destination;
}
use of org.gluu.oxtrust.model.scim2.Meta in project oxTrust by GluuFederation.
the class ServiceProviderConfigWS method listGroups.
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response listGroups(@HeaderParam("Authorization") String authorization) throws Exception {
ServiceProviderConfig serviceProviderConfig = new ServiceProviderConfig();
Meta meta = new Meta();
meta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ServiceProviderConfig");
meta.setResourceType("ServiceProviderConfig");
serviceProviderConfig.setMeta(meta);
ArrayList<AuthenticationScheme> authenticationSchemes = new ArrayList<AuthenticationScheme>();
if (appConfiguration.isScimTestMode()) {
log.info(" ##### SCIM Test Mode is ACTIVE");
authenticationSchemes.add(AuthenticationScheme.createOAuth2(true));
} else {
authenticationSchemes.add(AuthenticationScheme.createUma(true));
}
serviceProviderConfig.setAuthenticationSchemes(authenticationSchemes);
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ServiceProviderConfig");
return Response.ok(serviceProviderConfig).location(location).build();
}
Aggregations