use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class CopyUtils method copy.
/**
* Copy data from GluuCustomPerson object to ScimPerson object "Reda"
*
* @param source
* @param destination
* @return
* @throws Exception
*/
public ScimPerson copy(GluuCustomPerson source, ScimPerson destination) throws Exception {
if (source == null) {
return null;
}
if (destination == null) {
log.trace(" creating a new GluuCustomPerson instant ");
destination = new ScimPerson();
}
destination.getSchemas().add(Constants.SCIM1_CORE_SCHEMA_ID);
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(OX_TRUST_EXTERNAL_ID) != null) {
destination.setExternalId(source.getAttribute(OX_TRUST_EXTERNAL_ID));
}
log.trace(" setting givenname ");
if (source.getGivenName() != null) {
destination.getName().setGivenName(source.getGivenName());
}
log.trace(" getting family name ");
if (source.getSurname() != null) {
destination.getName().setFamilyName(source.getSurname());
}
log.trace(" getting middlename ");
if (source.getAttribute(OX_TRUST_MIDDLE_NAME) != null) {
destination.getName().setMiddleName(source.getAttribute(OX_TRUST_MIDDLE_NAME));
}
;
log.trace(" getting honorificPrefix ");
if (source.getAttribute(OX_TRUSTHONORIFIC_PREFIX) != null) {
destination.getName().setHonorificPrefix(source.getAttribute(OX_TRUSTHONORIFIC_PREFIX));
}
;
log.trace(" getting honorificSuffix ");
if (source.getAttribute(OX_TRUSTHONORIFIC_SUFFIX) != null) {
destination.getName().setHonorificSuffix(source.getAttribute(OX_TRUSTHONORIFIC_SUFFIX));
}
;
log.trace(" getting displayname ");
if (source.getDisplayName() != null) {
destination.setDisplayName(source.getDisplayName());
}
log.trace(" getting nickname ");
if (source.getAttribute(OX_TRUST_NICK_NAME) != null) {
destination.setNickName(source.getAttribute(OX_TRUST_NICK_NAME));
}
log.trace(" getting profileURL ");
if (source.getAttribute(OX_TRUST_PROFILE_URL) != null) {
destination.setProfileUrl(source.getAttribute(OX_TRUST_PROFILE_URL));
}
log.trace(" getting emails ");
// if (source.getAttribute(OX_TRUST_EMAIL) != null) {
if (source.getAttributeArray(OX_TRUST_EMAIL) != null) {
// List<ScimPersonEmails> listOfEmails = mapper.readValue(source.getAttribute(OX_TRUST_EMAIL), new TypeReference<List<ScimPersonEmails>>(){});
/*
* List<ScimPersonEmails> emails = new
* ArrayList<ScimPersonEmails>(); String[] listEmails =
* source.getAttributes("oxTrustEmail"); String[] listEmailTyps =
* source.getAttributes("oxTrustEmailType"); String[]
* listEmailPrimary = source.getAttributes("oxTrustEmailPrimary");
* for(int i = 0 ; i<listEmails.length ; i++ ){ ScimPersonEmails
* oneEmail = new ScimPersonEmails();
* oneEmail.setValue(listEmails[i]);
* oneEmail.setType(listEmailTyps[i]);
* oneEmail.setPrimary(listEmailPrimary[i]); emails.add(oneEmail); }
*/
// destination.setEmails(listOfEmails);
/*
String[] emailArray = source.getAttributeArray(OX_TRUST_EMAIL);
List<ScimPersonEmails> emails = new ArrayList<ScimPersonEmails>();
for (String emailStr : emailArray) {
ScimPersonEmails email = mapper.readValue(emailStr, ScimPersonEmails.class);
emails.add(email);
}
*/
List<ScimPersonEmails> emails = getAttributeListValue(source, ScimPersonEmails.class, OX_TRUST_EMAIL);
destination.setEmails(emails);
}
log.trace(" getting addresses ");
// getting addresses
if (source.getAttribute(OX_TRUST_ADDRESSES) != null) {
// List<ScimPersonAddresses> listOfAddresses = mapper.readValue(source.getAttribute(OX_TRUST_ADDRESSES), new TypeReference<List<ScimPersonAddresses>>(){});
/*
* List<ScimPersonAddresses> addresses = new
* ArrayList<ScimPersonAddresses>(); String[] listStreets =
* source.getAttributes("oxTrustStreet"); String[] listAddressTypes
* = source.getAttributes("oxTrustAddressType"); String[]
* listLocalities = source.getAttributes("oxTrustLocality");
* String[] listRegions = source.getAttributes("oxTrustRegion");
* String[] listPostalCodes =
* source.getAttributes("oxTrustPostalCode"); String[] listCountries
* = source.getAttributes("oxTrustCountry"); String[]
* listAddressFormatted =
* source.getAttributes("oxTrustAddressFormatted"); String[]
* listAddressPrimary =
* source.getAttributes("oxTrustAddressPrimary");
* if(listStreets.length > 0){ for(int i = 0 ; i <
* listStreets.length ; i++ ){ ScimPersonAddresses address = new
* ScimPersonAddresses();
*
* if(!listAddressFormatted[i].equalsIgnoreCase("empty")){address.
* setFormatted
* (listAddressFormatted[i]);}else{address.setFormatted("");}
* if(!listStreets
* [i].equalsIgnoreCase("empty")){address.setStreetAddress
* (listStreets[i]);}else{address.setStreetAddress("");}
* if(!listAddressTypes
* [i].equalsIgnoreCase("empty")){address.setType
* (listAddressTypes[i]);}else{address.setType("");}
* if(!listLocalities
* [i].equalsIgnoreCase("empty")){address.setLocality
* (listLocalities[i]);}else{address.setLocality("");}
* if(!listRegions
* [i].equalsIgnoreCase("empty")){address.setRegion(listRegions
* [i]);}else{address.setRegion("");}
* if(!listPostalCodes[i].equalsIgnoreCase
* ("empty")){address.setPostalCode
* (listPostalCodes[i]);}else{address.setPostalCode("");}
* if(!listCountries
* [i].equalsIgnoreCase("empty")){address.setCountry
* (listCountries[i]);}else{address.setCountry("");}
* if(!listAddressPrimary
* [i].equalsIgnoreCase("empty")){address.setPrimary
* (listAddressPrimary[i]);}else{address.setPrimary("");}
* addresses.add(address);
*
* } }
*/
// destination.setAddresses(listOfAddresses);
List<ScimPersonAddresses> addresses = getAttributeListValue(source, ScimPersonAddresses.class, OX_TRUST_ADDRESSES);
destination.setAddresses(addresses);
}
log.trace(" setting phoneNumber ");
// getting user's PhoneNumber
if (source.getAttribute(OX_TRUST_PHONE_VALUE) != null) {
// List<ScimPersonPhones> listOfPhones = mapper.readValue(source.getAttribute(OX_TRUST_PHONE_VALUE), new TypeReference<List<ScimPersonPhones>>(){});
/*
* List<ScimPersonPhones> phones = new
* ArrayList<ScimPersonPhones>(); String[] listNumbers =
* source.getAttributes("oxTrustPhoneValue"); String[]
* listPhoneTypes = source.getAttributes("oxTrustPhoneType");
* if(listNumbers.length > 0){ for(int i = 0 ; i <
* listNumbers.length ; i++){ ScimPersonPhones phone = new
* ScimPersonPhones();
* if(!listNumbers[i].equalsIgnoreCase("empty")){
* phone.setValue(listNumbers[i]);}else{phone.setValue("");}
* if(!listPhoneTypes
* [i].equalsIgnoreCase("empty")){phone.setType(listPhoneTypes
* [i]);}else{phone.setType("");} phones.add(phone);
*
* } }
*/
// destination.setPhoneNumbers(listOfPhones);
List<ScimPersonPhones> phoneNumbers = getAttributeListValue(source, ScimPersonPhones.class, OX_TRUST_PHONE_VALUE);
destination.setPhoneNumbers(phoneNumbers);
}
log.trace(" getting ims ");
// getting ims
if (source.getAttribute(OX_TRUST_IMS_VALUE) != null) {
// List<ScimPersonIms> listOfIms = mapper.readValue(source.getAttribute(OX_TRUST_IMS_VALUE), new TypeReference<List<ScimPersonIms>>(){});
/*
* List<ScimPersonIms> ims = new ArrayList<ScimPersonIms>();
* String[] imValues = source.getAttributes("oxTrustImsValue");
* String[] imTypes = source.getAttributes("oxTrustImsType");
* if(imValues.length > 0){ for(int i = 0 ; i < imValues.length ;
* i++){ ScimPersonIms im = new ScimPersonIms(); if(imValues[i] !=
* null){im.setValue(imValues[i]);im.setType(imTypes[i]);}
* ims.add(im); } }
*/
// destination.setIms(listOfIms);
List<ScimPersonIms> ims = getAttributeListValue(source, ScimPersonIms.class, OX_TRUST_IMS_VALUE);
destination.setIms(ims);
}
log.trace(" setting photos ");
// getting photos
if (source.getAttribute(OX_TRUST_PHOTOS) != null) {
// List<ScimPersonPhotos> listOfPhotos = mapper.readValue(source.getAttribute(OX_TRUST_PHOTOS), new TypeReference<List<ScimPersonPhotos>>(){});
/*
* List<ScimPersonPhotos> photos = new
* ArrayList<ScimPersonPhotos>(); String[] photoList =
* source.getAttributes("oxTrustPhotos"); String[] photoTypes =
* source.getAttributes("oxTrustPhotosType");
*
* if(photoList.length > 0){ for(int i = 0 ; i < photoList.length ;
* i++){
*
* ScimPersonPhotos photo = new ScimPersonPhotos(); if(photoList[i]
* !=
* null){photo.setValue(photoList[i]);photo.setType(photoTypes[i]);}
* photos.add(photo); } }
*/
// destination.setPhotos(listOfPhotos);
List<ScimPersonPhotos> photos = getAttributeListValue(source, ScimPersonPhotos.class, OX_TRUST_PHOTOS);
destination.setPhotos(photos);
}
log.trace(" setting userType ");
if (source.getAttribute(OX_TRUST_USER_TYPE) != null) {
destination.setUserType(source.getAttribute(OX_TRUST_USER_TYPE));
}
log.trace(" setting title ");
if (source.getAttribute(OX_TRUST_TITLE) != null) {
destination.setTitle(source.getAttribute(OX_TRUST_TITLE));
}
log.trace(" setting Locale ");
if (source.getAttribute(OX_TRUST_LOCALE) != null) {
destination.setLocale(source.getAttribute(OX_TRUST_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(OX_TRUST_ACTIVE) != null) {
destination.setActive(source.getAttribute(OX_TRUST_ACTIVE));
}
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<ScimPersonGroups> groupsList = new ArrayList<ScimPersonGroups>();
for (String groupDN : listOfGroups) {
ScimPersonGroups group = new ScimPersonGroups();
GluuGroup gluuGroup = groupService.getGroupByDn(groupDN);
group.setValue(gluuGroup.getInum());
group.setDisplay(gluuGroup.getDisplayName());
groupsList.add(group);
}
destination.setGroups(groupsList);
}
// getting roles
if (source.getAttribute(OX_TRUST_ROLE) != null) {
// List<ScimRoles> listOfRoles = mapper.readValue(source.getAttribute(OX_TRUST_ROLE), new TypeReference<List<ScimRoles>>(){});
/*
* List<ScimRoles> roles = new ArrayList<ScimRoles>(); String[]
* listRoles = source.getAttributes("oxTrustRole");
* if(listRoles.length > 0){ for(int i = 0 ; i < listRoles.length
* ;i++){ ScimRoles role = new ScimRoles(); if(listRoles[i] !=
* null){role.setValue(listRoles[i]);} roles.add(role); } }
*/
// destination.setRoles(listOfRoles);
List<ScimRoles> roles = getAttributeListValue(source, ScimRoles.class, OX_TRUST_ROLE);
destination.setRoles(roles);
}
log.trace(" getting entitlements ");
// getting entitlements
if (source.getAttribute(OX_TRUST_ENTITLEMENTS) != null) {
// List<ScimEntitlements> listOfEnts = mapper.readValue(source.getAttribute(OX_TRUST_ENTITLEMENTS), new TypeReference<List<ScimEntitlements>>(){});
/*
* List<ScimEntitlements> entitlements = new
* ArrayList<ScimEntitlements>(); String[] listEntitlements =
* source.getAttributes("oxTrustEntitlements");
* if(listEntitlements.length > 0){ for(int i = 0 ; i <
* listEntitlements.length ; i++ ){ ScimEntitlements ent = new
* ScimEntitlements(); if(listEntitlements[i] !=
* null){ent.setValue(listEntitlements[i]);} entitlements.add(ent);
* } }
*/
// destination.setEntitlements(listOfEnts);
List<ScimEntitlements> entitlements = getAttributeListValue(source, ScimEntitlements.class, OX_TRUST_ENTITLEMENTS);
destination.setEntitlements(entitlements);
}
// getting x509Certificates
log.trace(" setting certs ");
if (source.getAttribute(OX_TRUSTX509_CERTIFICATE) != null) {
// List<Scimx509Certificates> listOfCerts = mapper.readValue(source.getAttribute(OX_TRUSTX509_CERTIFICATE), new TypeReference<List<Scimx509Certificates>>(){});
/*
* List<Scimx509Certificates> certificates = new
* ArrayList<Scimx509Certificates>(); String[] listCertif =
* source.getAttributes("oxTrustx509Certificate");
* if(listCertif.length > 0){ for(int i = 0 ; i < listCertif.length
* ; i++){ Scimx509Certificates cert = new Scimx509Certificates();
* if(listCertif[i] != null){cert.setValue(listCertif[i]);}
* certificates.add(cert);
*
* } }
*/
// destination.setX509Certificates(listOfCerts);
List<Scimx509Certificates> x509Certificates = getAttributeListValue(source, Scimx509Certificates.class, OX_TRUSTX509_CERTIFICATE);
destination.setX509Certificates(x509Certificates);
}
log.trace(" setting meta ");
// getting meta data
if (source.getAttribute(OX_TRUST_META_CREATED) != null) {
destination.getMeta().setCreated(source.getAttribute(OX_TRUST_META_CREATED));
}
if (source.getAttribute(OX_TRUST_META_LAST_MODIFIED) != null) {
destination.getMeta().setLastModified(source.getAttribute(OX_TRUST_META_LAST_MODIFIED));
}
if (source.getAttribute(OX_TRUST_META_VERSION) != null) {
destination.getMeta().setVersion(source.getAttribute(OX_TRUST_META_VERSION));
}
// if (source.getAttribute(OX_TRUST_META_LOCATION) != null) {
// destination.getMeta().setLocation(source.getAttribute(OX_TRUST_META_LOCATION));
String location = source.getAttribute(OX_TRUST_META_LOCATION);
if (location != null && !location.isEmpty()) {
if (!location.startsWith("https://") && !location.startsWith("http://")) {
location = appConfiguration.getBaseEndpoint() + location;
}
} else {
location = appConfiguration.getBaseEndpoint() + "/scim/v1/Users/" + source.getInum();
}
destination.getMeta().setLocation(location);
// }
log.trace(" getting custom Attributes ");
// getting custom Attributes
List<GluuAttribute> listOfAttr = attributeService.getSCIMRelatedAttributes();
if (listOfAttr != null && listOfAttr.size() > 0) {
List<ScimCustomAttributes> listOfCustomAttr = new ArrayList<ScimCustomAttributes>();
for (GluuAttribute attr : listOfAttr) {
boolean isEmpty = attr.getOxMultivaluedAttribute() == null;
if (!isEmpty && attr.getOxMultivaluedAttribute().getValue().equalsIgnoreCase("true")) {
boolean isAttrEmpty = source.getAttributes(attr.getName()) == null;
if (!isAttrEmpty) {
String[] arrayValues = source.getAttributes(attr.getName());
List<String> values = new ArrayList<String>(Arrays.asList(arrayValues));
ScimCustomAttributes scimAttr = new ScimCustomAttributes();
scimAttr.setName(attr.getName());
scimAttr.setValues(values);
listOfCustomAttr.add(scimAttr);
}
} else {
boolean isAttrEmpty = source.getAttributes(attr.getName()) == null;
if (!isAttrEmpty) {
List<String> values = new ArrayList<String>();
values.add(source.getAttribute(attr.getName()));
ScimCustomAttributes scimAttr = new ScimCustomAttributes();
scimAttr.setName(attr.getName());
scimAttr.setValues(values);
listOfCustomAttr.add(scimAttr);
}
}
}
if (listOfCustomAttr.size() > 0) {
destination.setCustomAttributes(listOfCustomAttr);
}
}
log.trace(" returning destination ");
return destination;
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
public GluuGroup copy(ScimGroup source, GluuGroup destination, List<GluuGroup> attributes) throws Exception {
if (source == null) {
return null;
}
if (destination == null) {
destination = new GluuGroup();
}
destination.setInum(source.getId());
destination.setDisplayName(source.getDisplayName());
List<ScimGroupMembers> mapMembers = source.getMembers();
List<String> listMembers = new ArrayList<String>();
for (String dn : listMembers) {
GluuCustomPerson gluuPerson = personService.getPersonByDn(dn);
ScimGroupMembers member = new ScimGroupMembers();
member.setDisplay(gluuPerson.getDisplayName());
member.setValue(gluuPerson.getInum());
mapMembers.add(member);
}
destination.setMembers(listMembers);
return destination;
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class BulkWebService method createGroup.
private boolean createGroup(ScimGroup group) throws Exception {
log.debug(" copying gluuGroup ");
GluuGroup gluuGroup = copyUtils.copy(group, null, false);
if (gluuGroup == null) {
return false;
}
try {
log.debug(" generating inum ");
String inum = groupService.generateInumForNewGroup();
log.debug(" getting DN ");
String dn = groupService.getDnForGroup(inum);
log.debug(" getting iname ");
String iname = groupService.generateInameForNewGroup(group.getDisplayName().replaceAll(" ", ""));
log.debug(" setting dn ");
gluuGroup.setDn(dn);
log.debug(" setting inum ");
gluuGroup.setInum(inum);
log.debug(" setting iname ");
gluuGroup.setIname(iname);
log.debug("adding new GluuGroup");
if (group.getMembers().size() > 0) {
serviceUtil.personMembersAdder(gluuGroup, dn);
}
// For custom script: create group
if (externalScimService.isEnabled()) {
externalScimService.executeScimCreateGroupMethods(gluuGroup);
}
groupService.addGroup(gluuGroup);
return true;
} catch (Exception ex) {
log.error("Failed to add user", ex);
return false;
}
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class BulkWebService method updateGroup.
private boolean updateGroup(String id, ScimGroup group) throws Exception {
try {
GluuGroup gluuGroup = groupService.getGroupByInum(id);
if (gluuGroup == null) {
return false;
}
GluuGroup newGluuGroup = copyUtils.copy(group, gluuGroup, true);
if (group.getMembers().size() > 0) {
serviceUtil.personMembersAdder(newGluuGroup, groupService.getDnForGroup(id));
}
// For custom script: update group
if (externalScimService.isEnabled()) {
externalScimService.executeScimUpdateGroupMethods(newGluuGroup);
}
groupService.updateGroup(newGluuGroup);
log.debug(" group updated ");
return true;
} catch (EntryPersistenceException ex) {
log.error("Exception: ", ex);
return false;
} catch (Exception ex) {
log.error("Exception: ", ex);
ex.printStackTrace();
return false;
}
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupWebService method searchGroups.
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@HeaderParam("Accept")
@DefaultValue(MediaType.APPLICATION_JSON)
public Response searchGroups(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
Response authorizationResponse = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
if (count > getMaxCount()) {
String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
return getErrorResponse(detail, Response.Status.BAD_REQUEST.getStatusCode());
} else {
log.info(" Searching groups from LDAP ");
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuGroup> gluuGroups = search(groupService.getDnForGroup(null), GluuGroup.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
// List<GluuGroup> groupList = groupService.getAllGroupsList();
GluuGroupList groupsList = new GluuGroupList();
List<String> schema = new ArrayList<String>();
schema.add(Constants.SCIM1_CORE_SCHEMA_ID);
log.info(" setting schema");
groupsList.setSchemas(schema);
// Set total
groupsList.setTotalResults(vlvResponse.getTotalResults());
if (count > 0 && gluuGroups != null && !gluuGroups.isEmpty()) {
for (GluuGroup gluuGroup : gluuGroups) {
ScimGroup group = copyUtils.copy(gluuGroup, null);
log.info(" group to be added displayName : " + group.getDisplayName());
groupsList.getResources().add(group);
log.info(" group added? : " + groupsList.getResources().contains(group));
}
// Set the rest of results info
groupsList.setItemsPerPage(vlvResponse.getItemsPerPage());
groupsList.setStartIndex(vlvResponse.getStartIndex());
}
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v1/Groups");
// Serialize to JSON
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule customScimFilterModule = new SimpleModule("CustomScim1GroupFilterModule", new Version(1, 0, 0, ""));
GluuGroupListSerializer serializer = new GluuGroupListSerializer();
serializer.setAttributesArray(attributesArray);
customScimFilterModule.addSerializer(ScimGroup.class, serializer);
mapper.registerModule(customScimFilterModule);
String json = mapper.writeValueAsString(groupsList);
return Response.ok(json).location(location).build();
}
} catch (Exception ex) {
log.error("Error in searchGroups", ex);
ex.printStackTrace();
return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
Aggregations