Search in sources :

Example 6 with User

use of pl.plajer.villagedefense3.User in project camel by apache.

the class UserProducerTest method updateTest.

@Test
public void updateTest() throws Exception {
    final String id = "myID";
    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.UPDATE);
    when(testOSuser.getId()).thenReturn(id);
    final String newDescription = "ndesc";
    when(testOSuser.getDescription()).thenReturn(newDescription);
    when(userService.update(any(User.class))).thenReturn(testOSuser);
    msg.setBody(testOSuser);
    producer.process(exchange);
    ArgumentCaptor<User> captor = ArgumentCaptor.forClass(User.class);
    verify(userService).update(captor.capture());
    assertEqualsUser(testOSuser, captor.getValue());
    assertNotNull(captor.getValue().getId());
    assertEquals(newDescription, msg.getBody(User.class).getDescription());
}
Also used : User(org.openstack4j.model.identity.v3.User) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 7 with User

use of pl.plajer.villagedefense3.User 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;
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) User(org.gluu.oxtrust.model.scim2.User) Email(org.gluu.oxtrust.model.scim2.Email) Address(org.gluu.oxtrust.model.scim2.Address) Im(org.gluu.oxtrust.model.scim2.Im) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Photo(org.gluu.oxtrust.model.scim2.Photo) DateTime(org.joda.time.DateTime) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuAttributeDataType(org.xdi.model.GluuAttributeDataType) GluuGroup(org.gluu.oxtrust.model.GluuGroup) X509Certificate(org.gluu.oxtrust.model.scim2.X509Certificate) Date(java.util.Date) BigDecimal(java.math.BigDecimal) 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) GluuAttribute(org.xdi.model.GluuAttribute) GluuUserRole(org.xdi.model.GluuUserRole) 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) SimpleDateFormat(java.text.SimpleDateFormat)

Example 8 with User

use of pl.plajer.villagedefense3.User in project oxTrust by GluuFederation.

the class BulkWebService method processUserOperation.

private BulkOperation processUserOperation(BulkOperation operation, Map<String, String> processedBulkIds) throws Exception {
    log.info(" Operation is for User ");
    // Intercept bulkId
    User user = null;
    if (operation.getData() != null) {
        // Required in a request when
        // "method" is "POST", "PUT", or
        // "PATCH".
        String serializedData = serialize(operation.getData());
        for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
            String key = "bulkId:" + entry.getKey();
            serializedData = serializedData.replaceAll(key, entry.getValue());
        }
        user = deserializeToUser(serializedData);
    }
    String userRootEndpoint = appConfiguration.getBaseEndpoint() + "/scim/v2/Users/";
    if (operation.getMethod().equalsIgnoreCase(HttpMethod.POST)) {
        log.info(" Method is POST ");
        try {
            user = scim2UserService.createUser(user);
            GluuCustomPerson gluuPerson = personService.getPersonByUid(user.getUserName());
            String inum = gluuPerson.getInum();
            // String location = (new
            // StringBuilder()).append(domain).append("/Users/").append(inum).toString();
            String location = userRootEndpoint + inum;
            operation.setLocation(location);
            operation.setStatus(String.valueOf(Response.Status.CREATED.getStatusCode()));
            operation.setResponse(user);
            // Set aside successfully-processed bulkId
            // bulkId is only required in POST
            processedBulkIds.put(operation.getBulkId(), user.getId());
        } catch (DuplicateEntryException ex) {
            log.error("DuplicateEntryException", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.CONFLICT.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage()));
        } catch (PersonRequiredFieldsException ex) {
            log.error("PersonRequiredFieldsException: ", ex);
            operation.setStatus(String.valueOf(Response.Status.BAD_REQUEST.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, ex.getMessage()));
        } catch (Exception ex) {
            log.error("Failed to create user", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
        }
    } else if (operation.getMethod().equalsIgnoreCase(HttpMethod.PUT)) {
        log.info(" Method is PUT ");
        String path = operation.getPath();
        String id = getId(path);
        for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
            String key = "bulkId:" + entry.getKey();
            if (id.equalsIgnoreCase(key)) {
                id = id.replaceAll(key, entry.getValue());
                break;
            }
        }
        try {
            user = scim2UserService.updateUser(id, user);
            // String location = (new
            // StringBuilder()).append(domain).append("/Users/").append(personiD).toString();
            String location = userRootEndpoint + id;
            operation.setLocation(location);
            operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
            operation.setResponse(user);
            // bulkId is only required in POST
            if (operation.getBulkId() != null) {
                processedBulkIds.put(operation.getBulkId(), user.getId());
            }
        } catch (EntryPersistenceException ex) {
            log.error("Failed to update user", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found"));
        } catch (DuplicateEntryException ex) {
            log.error("DuplicateEntryException", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.CONFLICT.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage()));
        } catch (Exception ex) {
            log.error("Failed to update user", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
        }
    } else if (operation.getMethod().equalsIgnoreCase(HttpMethod.DELETE)) {
        log.info(" Method is DELETE ");
        String path = operation.getPath();
        String id = getId(path);
        for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
            String key = "bulkId:" + entry.getKey();
            if (id.equalsIgnoreCase(key)) {
                id = id.replaceAll(key, entry.getValue());
                break;
            }
        }
        try {
            scim2UserService.deleteUser(id);
            // Location may be omitted on DELETE
            operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
            operation.setResponse("User " + id + " deleted");
            // bulkId is only required in POST
            if (operation.getBulkId() != null) {
                processedBulkIds.put(operation.getBulkId(), id);
            }
        } catch (EntryPersistenceException ex) {
            log.error("Failed to delete user", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.NOT_FOUND, null, "Resource " + id + " not found"));
        } catch (Exception ex) {
            log.error("Failed to delete user", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
        }
    }
    return operation;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException)

Example 9 with User

use of pl.plajer.villagedefense3.User in project oxTrust by GluuFederation.

the class UserExtensionsTest method testCreatePersonFromUserObject.

@Test(dependsOnMethods = "testCreatePersonFromJsonString")
@Parameters
public void testCreatePersonFromUserObject() throws Exception {
    System.out.println(" testCreatePersonFromUserObject() ");
    // Create custom attributes
    // String, not
    GluuAttribute scimCustomFirst = null;
    // multi-valued
    if (attributeService.getAttributeByName("scimCustomFirst") == null) {
        scimCustomFirst = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomFirst", "Custom First", "First custom attribute", GluuAttributeDataType.STRING, OxMultivalued.FALSE);
    }
    // Date, multi-valued
    GluuAttribute scimCustomSecond = null;
    if (attributeService.getAttributeByName("scimCustomSecond") == null) {
        scimCustomSecond = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomSecond", "Custom Second", "Second custom attribute", GluuAttributeDataType.DATE, OxMultivalued.TRUE);
    }
    // Numeric, not
    GluuAttribute scimCustomThird = null;
    // multi-valued
    if (attributeService.getAttributeByName("scimCustomThird") == null) {
        scimCustomThird = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomThird", "Custom Third", "Third custom attribute", GluuAttributeDataType.NUMERIC, OxMultivalued.FALSE);
    }
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
    User user = createUserObject();
    // Create Person
    GluuCustomPerson gluuPerson = copyUtils2.copy(user, null, false);
    assertNotNull(gluuPerson, "gluuPerson is null!");
    System.out.println(">>>>>>>>>> gluuPerson.getUid() = " + gluuPerson.getUid());
    String inum = personService.generateInumForNewPerson();
    String dn = personService.getDnForPerson(inum);
    String iname = personService.generateInameForNewPerson(user.getUserName());
    gluuPerson.setDn(dn);
    gluuPerson.setInum(inum);
    gluuPerson.setIname(iname);
    gluuPerson.setCommonName(gluuPerson.getGivenName() + " " + gluuPerson.getSurname());
    personService.addPerson(gluuPerson);
    // Retrieve Person
    GluuCustomPerson retrievedPerson = personService.getPersonByUid(gluuPerson.getUid());
    assertNotNull(retrievedPerson, "Failed to find person.");
    User newPerson = copyUtils2.copy(retrievedPerson, null);
    Extension extension = newPerson.getExtension(Constants.USER_EXT_SCHEMA_ID);
    assertNotNull(extension, "(Persistence) Custom extension not persisted.");
    Extension.Field customFirstField = extension.getFields().get("scimCustomFirst");
    assertNotNull(customFirstField, "(Persistence) \"scimCustomFirst\" field not persisted.");
    assertEquals(customFirstField.getValue(), "customFirstValue");
    System.out.println("##### (Persistence) customFirstField.getValue() = " + customFirstField.getValue());
    Extension.Field customSecondField = extension.getFields().get("scimCustomSecond");
    assertNotNull(customSecondField, "(Persistence) \"scimCustomSecond\" field not persisted.");
    List<Date> dateList = Arrays.asList(mapper.readValue(customSecondField.getValue(), Date[].class));
    assertEquals(dateList.size(), 2);
    System.out.println("##### (Persistence) dateList.get(0) = " + dateList.get(0));
    System.out.println("##### (Persistence) dateList.get(1) = " + dateList.get(1));
    Extension.Field customThirdField = extension.getFields().get("scimCustomThird");
    assertNotNull(customThirdField, "(Persistence) \"scimCustomThird\" field not persisted.");
    assertEquals(new BigDecimal(customThirdField.getValue()), new BigDecimal(3000));
    System.out.println("##### (Persistence) customThirdField.getValue() = " + customThirdField.getValue());
    // Remove Person
    memberService.removePerson(retrievedPerson);
// Remove custom attributes
// schemaService.removeAttributeTypeFromObjectClass(scimCustomFirst.getOrigin(),
// scimCustomFirst.getName());
// schemaService.removeStringAttribute(scimCustomFirst.getName());
// attributeService.removeAttribute(scimCustomFirst);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomSecond.getOrigin(),
// scimCustomSecond.getName());
// schemaService.removeStringAttribute(scimCustomSecond.getName());
// attributeService.removeAttribute(scimCustomSecond);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomThird.getOrigin(),
// scimCustomThird.getName());
// schemaService.removeStringAttribute(scimCustomThird.getName());
// attributeService.removeAttribute(scimCustomThird);
}
Also used : Extension(org.gluu.oxtrust.model.scim2.Extension) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Date(java.util.Date) BigDecimal(java.math.BigDecimal) GluuAttribute(org.xdi.model.GluuAttribute) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.gluu.oxtrust.action.test.BaseTest)

Example 10 with User

use of pl.plajer.villagedefense3.User in project oxTrust by GluuFederation.

the class UserExtensionsTest method createUserObject.

private User createUserObject() throws Exception {
    User user = new User();
    user.setUserName("userjson.add.username");
    String testUserName = user.getUserName() + " (" + System.currentTimeMillis() + ")";
    user.setUserName(testUserName);
    user.setPassword("test");
    user.setDisplayName("Scim2DisplayName");
    Email email = new Email();
    email.setValue("scim@gluu.org");
    email.setType(org.gluu.oxtrust.model.scim2.Email.Type.WORK);
    email.setPrimary(true);
    user.getEmails().add(email);
    PhoneNumber phone = new PhoneNumber();
    phone.setType(org.gluu.oxtrust.model.scim2.PhoneNumber.Type.WORK);
    phone.setValue("654-6509-263");
    user.getPhoneNumbers().add(phone);
    org.gluu.oxtrust.model.scim2.Address address = new org.gluu.oxtrust.model.scim2.Address();
    address.setCountry("US");
    address.setStreetAddress("random street");
    address.setLocality("Austin");
    address.setPostalCode("65672");
    address.setRegion("TX");
    address.setPrimary(true);
    address.setType(org.gluu.oxtrust.model.scim2.Address.Type.WORK);
    address.setFormatted(address.getStreetAddress() + " " + address.getLocality() + " " + address.getPostalCode() + " " + address.getRegion() + " " + address.getCountry());
    user.getAddresses().add(address);
    user.setPreferredLanguage("US_en");
    org.gluu.oxtrust.model.scim2.Name name = new org.gluu.oxtrust.model.scim2.Name();
    name.setFamilyName("SCIM");
    name.setGivenName("SCIM");
    user.setName(name);
    // User Extensions
    Extension.Builder extensionBuilder = new Extension.Builder(Constants.USER_EXT_SCHEMA_ID);
    extensionBuilder.setField("scimCustomFirst", "customFirstValue");
    // extensionBuilder.setFieldAsList("scimCustomSecond", Arrays.asList(new
    // String[]{"2016-02-23T03:35:22Z", "2016-02-24T01:52:05Z"}));
    extensionBuilder.setFieldAsList("scimCustomSecond", Arrays.asList(new Date[] { (new DateTime("1969-01-02")).toDate(), (new DateTime("2016-02-27")).toDate() }));
    extensionBuilder.setField("scimCustomThird", new BigDecimal(3000));
    user.addExtension(extensionBuilder.build());
    return user;
}
Also used : User(org.gluu.oxtrust.model.scim2.User) Email(org.gluu.oxtrust.model.scim2.Email) Date(java.util.Date) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Extension(org.gluu.oxtrust.model.scim2.Extension) PhoneNumber(org.gluu.oxtrust.model.scim2.PhoneNumber)

Aggregations

User (pl.plajer.villagedefense3.User)30 Player (org.bukkit.entity.Player)19 User (org.gluu.oxtrust.model.scim2.User)17 EventHandler (org.bukkit.event.EventHandler)11 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)10 ScimPatchUser (org.gluu.oxtrust.model.scim2.ScimPatchUser)10 User (org.openstack4j.model.identity.v3.User)10 Arena (pl.plajer.villagedefense3.arena.Arena)9 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)8 ArrayList (java.util.ArrayList)7 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)7 Date (java.util.Date)6 SimpleUser (me.zhanghai.android.douya.network.api.info.apiv2.SimpleUser)6 User (me.zhanghai.android.douya.network.api.info.apiv2.User)6 ItemStack (org.bukkit.inventory.ItemStack)5 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)5 Test (org.junit.Test)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 BigDecimal (java.math.BigDecimal)4 URI (java.net.URI)4