Package org.sonatype.security.model

Examples of org.sonatype.security.model.CUser


      return null;
    }
  }

  public boolean removeUserById(final String id) {
    final CUser user = getUserById(id, false);
    if (user != null) {
      delegate.removeUser(user);
      return id2users.remove(id) != null;
    }
    else {
View Full Code Here


    role.setSessionTimeout(50);
    role.addPrivilege("priv");

    configurationManager.createRole(role);

    testUser = new CUser();
    testUser.setEmail("dummyemail@somewhere");
    testUser.setFirstName("dummyFirstName");
    testUser.setLastName("dummyLastName");
    testUser.setStatus(status);
    testUser.setId("username");
View Full Code Here

    role.setSessionTimeout(60);
    role.addPrivilege(priv.getId());

    configurationManager.createRole(role);

    CUser user = new CUser();
    user.setEmail("dummyemail@foo");
    user.setFirstName("dummyFirstName");
    user.setLastName("dummyLastName");
    user.setStatus(UserStatus.active.toString());
    user.setId(userId);
    user.setPassword("password");

    Set<String> roles = new HashSet<String>();
    roles.add(role.getId());

    configurationManager.createUser(user, roles);
View Full Code Here

  protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
      throws AuthenticationException
  {
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;

    CUser user;
    try {
      user = configuration.readUser(upToken.getUsername());
    }
    catch (UserNotFoundException e) {
      throw new AccountException("User '" + upToken.getUsername() + "' cannot be retrieved.", e);
    }

    if (user.getPassword() == null) {
      throw new AccountException("User '" + upToken.getUsername() + "' has no password, cannot authenticate.");
    }

    if (CUser.STATUS_ACTIVE.equals(user.getStatus())) {
      //Check for legacy user that has unsalted password hash
      //Update if legacy user, and valid credentials were specified
      if (this.isLegacyUser(user) && this.isValidCredentials(upToken, user)) {
        this.reHashPassword(user, new String(upToken.getPassword()));
      }

      return this.createAuthenticationInfo(user);
    }
    else if (CUser.STATUS_DISABLED.equals(user.getStatus())) {
      throw new DisabledAccountException("User '" + upToken.getUsername() + "' is disabled.");
    }
    else {
      throw new AccountException("User '" + upToken.getUsername() + "' is in illegal status '"
          + user.getStatus() + "'.");
    }
  }
View Full Code Here

  protected CUser toUser(User user) {
    if (user == null) {
      return null;
    }

    CUser secUser = new CUser();

    secUser.setId(user.getUserId());
    secUser.setFirstName(user.getFirstName());
    secUser.setLastName(user.getLastName());
    secUser.setEmail(user.getEmailAddress());
    secUser.setStatus(user.getStatus().name());
    // secUser.setPassword( password )// DO NOT set the users password!

    return secUser;
  }
View Full Code Here

  }

  public User addUser(final User user, String password)
      throws InvalidConfigurationException
  {
    final CUser secUser = this.toUser(user);
    secUser.setPassword(this.hashPassword(password));

    try {
      this.configuration.runWrite(new ConfigurationManagerAction()
      {
        public void run() throws Exception {
View Full Code Here

  {
    try {
      this.configuration.runWrite(new ConfigurationManagerAction()
      {
        public void run() throws Exception {
          final CUser secUser = configuration.readUser(userId);
          secUser.setPassword(hashPassword(newPassword));
          configuration.updateUser(secUser);
          saveConfiguration();
        }
      });
    }
View Full Code Here

    try {
      this.configuration.runWrite(new ConfigurationManagerAction()
      {
        public void run() throws Exception {
          // we need to pull the users password off off the old user object
          CUser oldSecUser = configuration.readUser(user.getUserId());
          CUser newSecUser = toUser(user);
          newSecUser.setPassword(oldSecUser.getPassword());

          configuration.updateUser(newSecUser, getRoleIdsFromUser(user));
          saveConfiguration();
        }
      });
View Full Code Here

    userManager.addUser(user, "my-password");

    ConfigurationManager config = this.getConfigurationManager();

    CUser secUser = config.readUser(user.getUserId());
    Assert.assertEquals(secUser.getId(), user.getUserId());
    Assert.assertEquals(secUser.getEmail(), user.getEmailAddress());
    Assert.assertEquals(secUser.getFirstName(), user.getFirstName());
    Assert.assertEquals(secUser.getLastName(), user.getLastName());
    assertThat(this.passwordService.passwordsMatch("my-password", secUser.getPassword()), is(true));

    Assert.assertEquals(secUser.getStatus(), user.getStatus().name());

    CUserRoleMapping roleMapping = config.readUserRoleMapping("testCreateUser", "default");

    Assert.assertTrue(roleMapping.getRoles().contains("role1"));
    Assert.assertTrue(roleMapping.getRoles().contains("role3"));
View Full Code Here

      throws Exception
  {
    UserManager userManager = this.getUserManager();
    userManager.changePassword("test-user", "new-user-password");

    CUser user = this.getConfigurationManager().readUser("test-user");
    assertThat(this.passwordService.passwordsMatch("new-user-password", user.getPassword()), is(true));
  }
View Full Code Here

TOP

Related Classes of org.sonatype.security.model.CUser

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.