コード例 #1
0
  /**
   * Put user into realm.
   *
   * @param userName The user to add
   * @param credential The users Credentials
   * @param roles The users roles
   * @return UserIdentity
   */
  public synchronized UserIdentity putUser(String userName, Credential credential, String[] roles) {
    Principal userPrincipal = new KnownUser(userName, credential);
    Subject subject = new Subject();
    subject.getPrincipals().add(userPrincipal);
    subject.getPrivateCredentials().add(credential);

    if (roles != null)
      for (String role : roles) subject.getPrincipals().add(new RolePrincipal(role));

    subject.setReadOnly();
    UserIdentity identity = _identityService.newUserIdentity(subject, userPrincipal, roles);
    _users.put(userName, identity);
    return identity;
  }
コード例 #2
0
  /**
   * Put user into realm. Called by implementations to put the user data loaded from file/db etc
   * into the user structure.
   *
   * @param userName User name
   * @param info a UserIdentity instance, or a String password or Credential instance
   * @return User instance
   */
  protected synchronized UserIdentity putUser(String userName, Object info) {
    final UserIdentity identity;
    if (info instanceof UserIdentity) identity = (UserIdentity) info;
    else {
      Credential credential =
          (info instanceof Credential)
              ? (Credential) info
              : Credential.getCredential(info.toString());

      Principal userPrincipal = new KnownUser(userName, credential);
      Subject subject = new Subject();
      subject.getPrincipals().add(userPrincipal);
      subject.getPrivateCredentials().add(credential);
      subject.setReadOnly();
      identity = _identityService.newUserIdentity(subject, userPrincipal, IdentityService.NO_ROLES);
    }

    _users.put(userName, identity);
    return identity;
  }