Search in sources :

Example 1 with Group

use of org.gluu.oxtrust.model.scim2.user.Group in project oxTrust by GluuFederation.

the class CopyUtils2 method copy.

/**
	 * Copy data from ScimGroup object to GluuGroupn object
	 * 
	 * @param source
	 * @param destination
	 * @param isUpdate
	 * @return
	 * @throws IOException
	 * @throws JsonMappingException
	 * @throws JsonGenerationException
	 * @throws Exception
	 */
public GluuGroup copy(Group source, GluuGroup destination, boolean isUpdate) throws Exception {
    if (source == null || !isValidData(source, isUpdate)) {
        return null;
    }
    if (destination == null) {
        log.trace(" creating a new GluuGroup instant ");
        destination = new GluuGroup();
    }
    if (isUpdate) {
        if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
            destination.setDisplayName(source.getDisplayName());
        }
        if (source.getMembers() != null && source.getMembers().size() > 0) {
            Set<MemberRef> members = source.getMembers();
            List<String> listMembers = new ArrayList<String>();
            for (MemberRef member : members) {
                listMembers.add(personService.getDnForPerson(member.getValue()));
            }
            destination.setMembers(listMembers);
        }
    } else {
        log.trace(" creating a new GroupService instant ");
        log.trace(" source.getDisplayName() : ", source.getDisplayName());
        if (groupService.getGroupByDisplayName(source.getDisplayName()) != null) {
            log.trace(" groupService1.getGroupByDisplayName(source.getDisplayName() != null : ");
            return null;
        }
        if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
            destination.setDisplayName(source.getDisplayName());
        }
        log.trace(" source.getMembers() : ", source.getMembers());
        log.trace(" source.getMembers().size() : ", source.getMembers().size());
        if (source.getMembers() != null && source.getMembers().size() > 0) {
            Set<MemberRef> members = source.getMembers();
            List<String> listMembers = new ArrayList<String>();
            for (MemberRef member : members) {
                listMembers.add(personService.getDnForPerson(member.getValue()));
            }
            destination.setMembers(listMembers);
        }
        /*GluuCustomPerson authUser = (GluuCustomPerson) identity.getSessionMap().get(OxTrustConstants.CURRENT_PERSON);
			destination.setOwner(authUser.getDn());
			log.trace(" authUser.getDn() : ", authUser.getDn());*/
        destination.setStatus(GluuStatus.ACTIVE);
        destination.setOrganization(organizationService.getDnForOrganization());
    }
    return destination;
}
Also used : ArrayList(java.util.ArrayList) MemberRef(org.gluu.oxtrust.model.scim2.MemberRef) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 2 with Group

use of org.gluu.oxtrust.model.scim2.user.Group in project oxTrust by GluuFederation.

the class PatchUtil method addPatch.

public GluuCustomPerson addPatch(User source, GluuCustomPerson destination) throws Exception {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        log.trace(" creating a new GluuCustomPerson instant ");
        destination = new GluuCustomPerson();
    }
    log.trace(" setting schemas ");
    destination.setSchemas(source.getSchemas());
    personService.addCustomObjectClass(destination);
    // getting emails
    log.trace(" setting emails ");
    if (source.getEmails() != null && source.getEmails().size() > 0) {
        List<Email> emails = copyUtils2.getAttributeListValue(destination, Email.class, "oxTrustEmail");
        if (emails == null) {
            emails = new ArrayList<Email>();
        }
        emails.addAll(source.getEmails());
        copyUtils2.setAttributeListValue(destination, emails, "oxTrustEmail");
    }
    // getting addresses
    log.trace(" setting addresses ");
    if (source.getAddresses() != null && source.getAddresses().size() > 0) {
        List<Address> addresses = copyUtils2.getAttributeListValue(destination, Address.class, "oxTrustAddresses");
        if (addresses == null) {
            addresses = new ArrayList<Address>();
        }
        addresses.addAll(source.getAddresses());
        copyUtils2.setAttributeListValue(destination, addresses, "oxTrustAddresses");
    }
    // getting phone numbers;
    log.trace(" setting phoneNumbers ");
    if (source.getPhoneNumbers() != null && source.getPhoneNumbers().size() > 0) {
        List<PhoneNumber> phoneNumbers = copyUtils2.getAttributeListValue(destination, PhoneNumber.class, "oxTrustPhoneValue");
        if (phoneNumbers == null) {
            phoneNumbers = new ArrayList<PhoneNumber>();
        }
        phoneNumbers.addAll(source.getPhoneNumbers());
        copyUtils2.setAttributeListValue(destination, phoneNumbers, "oxTrustPhoneValue");
    }
    // getting ims
    log.trace(" setting ims ");
    if (source.getIms() != null && source.getIms().size() > 0) {
        List<Im> ims = copyUtils2.getAttributeListValue(destination, Im.class, "oxTrustImsValue");
        if (ims == null) {
            ims = new ArrayList<Im>();
        }
        ims.addAll(source.getIms());
        copyUtils2.setAttributeListValue(destination, ims, "oxTrustImsValue");
    }
    // getting Photos
    log.trace(" setting photos ");
    if (source.getPhotos() != null && source.getPhotos().size() > 0) {
        List<Photo> photos = copyUtils2.getAttributeListValue(destination, Photo.class, "oxTrustPhotos");
        if (photos == null) {
            photos = new ArrayList<Photo>();
        }
        photos.addAll(source.getPhotos());
        copyUtils2.setAttributeListValue(destination, photos, "oxTrustPhotos");
    }
    // getting user groups
    log.trace(" setting groups ");
    if (source.getGroups() != null && source.getGroups().size() > 0) {
        List<String> groupsList = destination.getMemberOf();
        List<GroupRef> listGroups = source.getGroups();
        for (GroupRef group : listGroups) {
            String groupToAdd = groupService.getDnForGroup(group.getValue());
            if (groupToAdd != null || !groupToAdd.trim().equalsIgnoreCase("")) {
                groupsList.add(groupToAdd);
            }
        }
        destination.setMemberOf(groupsList);
    }
    // getting roles
    log.trace(" setting roles ");
    if (source.getRoles() != null && source.getRoles().size() > 0) {
        List<Role> roles = copyUtils2.getAttributeListValue(destination, Role.class, "oxTrustRole");
        if (roles == null) {
            roles = new ArrayList<Role>();
        }
        roles.addAll(source.getRoles());
        copyUtils2.setAttributeListValue(destination, roles, "oxTrustRole");
    }
    // getting entitlements
    log.trace(" setting entitlements ");
    if (source.getEntitlements() != null && source.getEntitlements().size() > 0) {
        List<Entitlement> entitlements = copyUtils2.getAttributeListValue(destination, Entitlement.class, "oxTrustEntitlements");
        if (entitlements == null) {
            entitlements = new ArrayList<Entitlement>();
        }
        entitlements.addAll(source.getEntitlements());
        copyUtils2.setAttributeListValue(destination, entitlements, "oxTrustEntitlements");
    }
    // getting x509Certificates
    log.trace(" setting certs ");
    if (source.getX509Certificates() != null && source.getX509Certificates().size() > 0) {
        List<X509Certificate> X509Certificates = copyUtils2.getAttributeListValue(destination, X509Certificate.class, "oxTrustx509Certificate");
        if (X509Certificates == null) {
            X509Certificates = new ArrayList<X509Certificate>();
        }
        X509Certificates.addAll(source.getX509Certificates());
        copyUtils2.setAttributeListValue(destination, X509Certificates, "oxTrustx509Certificate");
    }
    log.trace(" setting extensions ");
    if (source.getExtensions() != null && (source.getExtensions().size() > 0)) {
        Map<String, Extension> destMap = destination.fetchExtensions();
        if (destMap == null) {
            destMap = new HashMap<String, Extension>();
        }
        destMap.putAll(source.getExtensions());
        destination.setExtensions(destMap);
    }
    if (source.isActive() != null) {
        copyUtils2.setGluuStatus(source, destination);
    }
    return destination;
}
Also used : Email(org.gluu.oxtrust.model.scim2.Email) Address(org.gluu.oxtrust.model.scim2.Address) Im(org.gluu.oxtrust.model.scim2.Im) Photo(org.gluu.oxtrust.model.scim2.Photo) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) X509Certificate(org.gluu.oxtrust.model.scim2.X509Certificate) Role(org.gluu.oxtrust.model.scim2.Role) Extension(org.gluu.oxtrust.model.scim2.Extension) PhoneNumber(org.gluu.oxtrust.model.scim2.PhoneNumber) GroupRef(org.gluu.oxtrust.model.scim2.GroupRef) Entitlement(org.gluu.oxtrust.model.scim2.Entitlement)

Example 3 with Group

use of org.gluu.oxtrust.model.scim2.user.Group in project oxTrust by GluuFederation.

the class GroupWebService method searchGroupsPost.

@Path("/.search")
@POST
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search group POST /.search", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response searchGroupsPost(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) throws Exception {
    try {
        log.info("IN GroupWebService.searchGroupsPost()...");
        // Authorization check is done in searchGroups()
        Response response = searchGroups(authorization, token, searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesArray());
        URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/.search");
        log.info("LEAVING GroupWebService.searchGroupsPost()...");
        return Response.fromResponse(response).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Error in searchGroupsPost", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource not found");
    } catch (Exception ex) {
        log.error("Error in searchGroupsPost", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 4 with Group

use of org.gluu.oxtrust.model.scim2.user.Group 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();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaExtensionHolder(org.gluu.oxtrust.model.scim2.schema.SchemaExtensionHolder) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) ArrayList(java.util.ArrayList) Resource(org.gluu.oxtrust.model.scim2.Resource) ResourceType(org.gluu.oxtrust.model.scim2.provider.ResourceType) URI(java.net.URI) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with Group

use of org.gluu.oxtrust.model.scim2.user.Group 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;
}
Also used : ScimGroup(org.gluu.oxtrust.model.scim.ScimGroup) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Meta(org.gluu.oxtrust.model.scim2.Meta) MemberRef(org.gluu.oxtrust.model.scim2.MemberRef) SimpleDateFormat(java.text.SimpleDateFormat) DateTime(org.joda.time.DateTime) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) HashSet(java.util.HashSet)

Aggregations

GluuGroup (org.gluu.oxtrust.model.GluuGroup)14 DefaultValue (javax.ws.rs.DefaultValue)13 HeaderParam (javax.ws.rs.HeaderParam)13 Produces (javax.ws.rs.Produces)13 Response (javax.ws.rs.core.Response)13 URI (java.net.URI)12 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)12 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)11 ArrayList (java.util.ArrayList)10 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)10 Path (javax.ws.rs.Path)8 Group (org.gluu.oxtrust.model.scim2.Group)8 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)8 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 Consumes (javax.ws.rs.Consumes)7 ListViewResponse (org.gluu.persist.model.ListViewResponse)7 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)6 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)6 GroupResource (org.gluu.oxtrust.model.scim2.group.GroupResource)6 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)6