Package org.sonatype.security.usermanagement

Examples of org.sonatype.security.usermanagement.User


    if (!userManager.supportsWrite()) {
      throw new InvalidConfigurationException("UserManager: " + userManager.getSource()
          + " does not support writing.");
    }

    final User oldUser = userManager.getUser(user.getUserId());
    userManager.updateUser(user);
    if (oldUser.getStatus() == UserStatus.active && user.getStatus() != oldUser.getStatus()) {
      // clear the realm authc caches as user got disabled
      eventBus.post(new UserPrincipalsExpired(user.getUserId(), user.getSource()));
    }

    // then save the users Roles
View Full Code Here


  }

  public void deleteUser(String userId)
      throws UserNotFoundException
  {
    User user = this.getUser(userId);
    try {
      this.deleteUser(userId, user.getSource());
    }
    catch (NoSuchUserManagerException e) {
      this.logger.error("User manager returned user, but could not be found: " + e.getMessage(), e);
      throw new IllegalStateException("User manager returned user, but could not be found: " + e.getMessage(), e);
    }
View Full Code Here

  }

  public Set<RoleIdentifier> getUsersRoles(String userId, String source)
      throws UserNotFoundException, NoSuchUserManagerException
  {
    User user = this.getUser(userId, source);
    return user.getRoles();
  }
View Full Code Here

      throws UserNotFoundException, NoSuchUserManagerException
  {
    // first get the user
    // this is the UserManager that owns the user
    UserManager userManager = userManagerFacade.getUserManager(source);
    User user = userManager.getUser(userId);

    if (user == null) {
      throw new UserNotFoundException(userId);
    }
View Full Code Here

  }

  public void changePassword(String userId, String newPassword)
      throws UserNotFoundException, InvalidConfigurationException
  {
    User user = this.getUser(userId);

    try {
      UserManager userManager = userManagerFacade.getUserManager(user.getSource());
      userManager.changePassword(userId, newPassword);
    }
    catch (NoSuchUserManagerException e) {
      // this should NEVER happen
      this.logger.warn("User '" + userId + "' with source: '" + user.getSource()
          + "' but could not find the UserManager for that source.");
    }

    // flush authc
    eventBus.post(new UserPrincipalsExpired(userId, user.getSource()));
  }
View Full Code Here

  public void resetPassword(String userId)
      throws UserNotFoundException, InvalidConfigurationException
  {
    String newClearTextPassword = this.generatePassword();

    User user = this.getUser(userId);

    this.changePassword(userId, newClearTextPassword);

    // flush authc
    eventBus.post(new UserPrincipalsExpired(userId, user.getSource()));

    // send email
    this.getSecurityEmailer().sendResetPassword(user.getEmailAddress(), newClearTextPassword);

  }
View Full Code Here

  }

  public void setAnonymousUsername(String anonymousUsername)
      throws InvalidConfigurationException
  {
    User user = null;
    try {
      user = getUser(securityConfiguration.getAnonymousUsername());
    }
    catch (UserNotFoundException e) {
      // ignore
    }
    this.securityConfiguration.setAnonymousUsername(anonymousUsername);
    this.securityConfiguration.save();
    // flush authc, if anon existed before change
    if (user != null) {
      eventBus.post(new UserPrincipalsExpired(user.getUserId(), user.getSource()));
    }
  }
View Full Code Here

  }

  public void setAnonymousPassword(String anonymousPassword)
      throws InvalidConfigurationException
  {
    User user = null;
    try {
      user = getUser(securityConfiguration.getAnonymousUsername());
    }
    catch (UserNotFoundException e) {
      // ignore
    }
    this.securityConfiguration.setAnonymousPassword(anonymousPassword);
    this.securityConfiguration.save();
    if (user != null) {
      // flush authc, if anon exists
      eventBus.post(new UserPrincipalsExpired(user.getUserId(), user.getSource()));
    }
  }
View Full Code Here

  }

  public Set<User> listUsers() {
    Set<User> users = new HashSet<User>();

    User jcohen = new DefaultUser();
    jcohen.setEmailAddress("JamesDCohen@example.com");
    jcohen.setFirstName("James");
    jcohen.setLastName("Cohen");
    // jcohen.setName( "James E. Cohen" );
    // jcohen.setReadOnly( true );
    jcohen.setSource("Mock");
    jcohen.setStatus(UserStatus.active);
    jcohen.setUserId("jcohen");
    jcohen.addRole(new RoleIdentifier("Mock", "mockrole1"));
    users.add(jcohen);

    return users;
  }
View Full Code Here

    UserSearchCriteria criteria = new UserSearchCriteria(null, null, "MockUserManagerA");
    Set<User> users = userManager.searchUsers(criteria);

    Map<String, User> userMap = this.toUserMap(users);

    User user = userMap.get("jcoder");
    Assert.assertNotNull(user);

    // A,B,C,1
    Set<String> roleIds = this.toRoleIdSet(user.getRoles());
    Assert.assertTrue(roleIds.contains("RoleA"));
    Assert.assertTrue(roleIds.contains("RoleB"));
    Assert.assertTrue(roleIds.contains("RoleC"));
    Assert.assertTrue("roles: " + this.toRoleIdSet(user.getRoles()), roleIds.contains("Role1"));

    Assert.assertEquals("roles: " + this.toRoleIdSet(user.getRoles()), 4, user.getRoles().size());

    user = userMap.get("dknudsen");
    Assert.assertNotNull(user);
    Assert.assertEquals(1, user.getRoles().size());

    // Role2
    roleIds = this.toRoleIdSet(user.getRoles());
    Assert.assertTrue(roleIds.contains("Role2"));

    user = userMap.get("cdugas");
    Assert.assertNotNull(user);
    Assert.assertEquals(3, user.getRoles().size());

    // A,B,1
    roleIds = this.toRoleIdSet(user.getRoles());
    Assert.assertTrue(roleIds.contains("RoleA"));
    Assert.assertTrue(roleIds.contains("RoleB"));
    Assert.assertTrue(roleIds.contains("Role1"));

    user = userMap.get("pperalez");
    Assert.assertNotNull(user);
    Assert.assertEquals(0, user.getRoles().size());

  }
View Full Code Here

TOP

Related Classes of org.sonatype.security.usermanagement.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.