@Test
  public void patch_user_to_inactive_then_login() throws Exception {
    ScimUser user = setUpScimUser();
    user.setVerified(true);
    boolean active = true;
    user.setActive(active);
    getMockMvc()
        .perform(
            patch("/Users/" + user.getId())
                .header("Authorization", "Bearer " + scimReadWriteToken)
                .header("If-Match", "\"" + user.getVersion() + "\"")
                .contentType(APPLICATION_JSON)
                .content(JsonUtils.writeValueAsString(user)))
        .andExpect(status().isOk())
        .andExpect(jsonPath("$.active", equalTo(active)));

    performAuthentication(user, true);

    active = false;
    user.setActive(active);
    getMockMvc()
        .perform(
            patch("/Users/" + user.getId())
                .header("Authorization", "Bearer " + scimReadWriteToken)
                .header("If-Match", "\"" + (user.getVersion() + 1) + "\"")
                .contentType(APPLICATION_JSON)
                .content(JsonUtils.writeValueAsString(user)))
        .andExpect(status().isOk())
        .andExpect(jsonPath("$.active", equalTo(active)));

    performAuthentication(user, false);
  }
 private ScimUser deactivateUser(ScimUser user, int version) {
   logger.debug("Deactivating user: "******" and version=?",
             false,
             user.getId(),
             IdentityZoneHolder.get().getId(),
             version);
   }
   if (updated == 0) {
     throw new OptimisticLockingFailureException(
         String.format(
             "Attempt to update a user (%s) with wrong version: expected=%d but found=%d",
             user.getId(), user.getVersion(), version));
   }
   if (updated > 1) {
     throw new IncorrectResultSizeDataAccessException(1);
   }
   user.setActive(false);
   return user;
 }
 @Test(expected = ScimResourceAlreadyExistsException.class)
 public void cannotDeactivateExistingUserAndThenCreateHimAgain() {
   String tmpUserId = createUserForDelete();
   ScimUser deletedUser = db.delete(tmpUserId, 0);
   deletedUser.setActive(true);
   try {
     db.createUser(deletedUser, "foobarspam1234");
   } catch (ScimResourceAlreadyExistsException e) {
     removeUser(tmpUserId);
     throw e;
   }
 }
  @Test
  // (expected = ScimResourceAlreadyExistsException.class)
  public void canDeleteExistingUserAndThenCreateHimAgain() {
    String tmpUserId = createUserForDelete();
    db.setDeactivateOnDelete(false);
    ScimUser deletedUser = db.delete(tmpUserId, 0);
    assertEquals(0, template.queryForList("select * from users where id=?", tmpUserId).size());

    deletedUser.setActive(true);
    ScimUser user = db.createUser(deletedUser, "foobarspam1234");
    assertNotNull(user);
    assertNotNull(user.getId());
    assertNotSame(tmpUserId, user.getId());
    assertEquals(1, db.query("username eq \"" + tmpUserId + "\"").size());
    removeUser(user.getId());
  }
Example #5
0
 protected ScimUser findOrCreateUser(String email, String origin) {
   email = email.trim().toLowerCase();
   List<ScimUser> results =
       users.query(String.format("email eq \"%s\" and origin eq \"%s\"", email, origin));
   if (results == null || results.size() == 0) {
     ScimUser user = new ScimUser(null, email, "", "");
     user.setPrimaryEmail(email.toLowerCase());
     user.setOrigin(origin);
     user.setVerified(false);
     user.setActive(true);
     return users.createUser(user, new RandomValueStringGenerator(12).generate());
   } else if (results.size() == 1) {
     return results.get(0);
   } else {
     throw new ScimResourceConflictException(
         String.format("Ambiguous users found for email:%s with origin:%s", email, origin));
   }
 }
Example #6
0
  private ScimUser createUnapprovedUser() throws Exception {
    String userName = "******" + new RandomValueStringGenerator().generate();
    String userEmail = userName + "@example.com";

    RestOperations restTemplate = serverRunning.getRestTemplate();

    ScimUser user = new ScimUser();
    user.setUserName(userName);
    user.setPassword("s3Cretsecret");
    user.addEmail(userEmail);
    user.setActive(true);
    user.setVerified(true);

    ResponseEntity<ScimUser> result =
        restTemplate.postForEntity(serverRunning.getUrl("/Users"), user, ScimUser.class);
    assertEquals(HttpStatus.CREATED, result.getStatusCode());

    return user;
  }
 @Override
 public ScimUser mapRow(ResultSet rs, int rowNum) throws SQLException {
   String id = rs.getString(1);
   int version = rs.getInt(2);
   Date created = rs.getTimestamp(3);
   Date lastModified = rs.getTimestamp(4);
   String userName = rs.getString(5);
   String email = rs.getString(6);
   String givenName = rs.getString(7);
   String familyName = rs.getString(8);
   boolean active = rs.getBoolean(9);
   String phoneNumber = rs.getString(10);
   boolean verified = rs.getBoolean(11);
   String origin = rs.getString(12);
   String externalId = rs.getString(13);
   String zoneId = rs.getString(14);
   String salt = rs.getString(15);
   Date passwordLastModified = rs.getTimestamp(16);
   ScimUser user = new ScimUser();
   user.setId(id);
   ScimMeta meta = new ScimMeta();
   meta.setVersion(version);
   meta.setCreated(created);
   meta.setLastModified(lastModified);
   user.setMeta(meta);
   user.setUserName(userName);
   user.addEmail(email);
   if (phoneNumber != null) {
     user.addPhoneNumber(phoneNumber);
   }
   Name name = new Name();
   name.setGivenName(givenName);
   name.setFamilyName(familyName);
   user.setName(name);
   user.setActive(active);
   user.setVerified(verified);
   user.setOrigin(origin);
   user.setExternalId(externalId);
   user.setZoneId(zoneId);
   user.setSalt(salt);
   user.setPasswordLastModified(passwordLastModified);
   return user;
 }