/** Loads some users during the <b>first</b> construction. */
  @PostConstruct
  public void create() {

    this.identityManager = partitionManager.createIdentityManager();
    this.relationshipManager = partitionManager.createRelationshipManager();

    final String DEFAULT_PASSWORD = "******";
    final String DEFAULT_DEVELOPER = "developer";
    final String DEFAULT_ADMIN = "admin";

    User developerUser = BasicModel.getUser(identityManager, DEFAULT_DEVELOPER);

    // We only create the Developer user, if there is none;
    // if present, there is also no need to add the same 'Developer' user again.
    if (developerUser == null) {
      developerUser = new User(DEFAULT_DEVELOPER);
      identityManager.add(developerUser);

      Calendar calendar = expirationDate();
      Password password = new Password(DEFAULT_PASSWORD.toCharArray());

      identityManager.updateCredential(developerUser, password, new Date(), calendar.getTime());

      Role roleDeveloper = new Role(UserRoles.DEVELOPER);

      identityManager.add(roleDeveloper);

      grantRoles(developerUser, roleDeveloper);
    }

    // Temp hack to add user with admin rights
    User adminUser = BasicModel.getUser(identityManager, DEFAULT_ADMIN);

    // We only create the Admin user, if there is none;
    // if present, there is also no need to apply the same 'Admin' user again.
    if (adminUser == null) {
      adminUser = new User(DEFAULT_ADMIN);
      identityManager.add(adminUser);

      Calendar calendar = expirationDate();
      Password password = new Password(DEFAULT_PASSWORD.toCharArray());

      identityManager.updateCredential(adminUser, password, new Date(), calendar.getTime());

      Role roleAdmin = new Role(UserRoles.ADMIN);

      identityManager.add(roleAdmin);

      grantRoles(adminUser, roleAdmin);
    }
  }
  @Override
  public void updateCredential(UserCredentialModel cred) {
    if (!provider.getSupportedCredentialTypes(delegate).contains(cred.getType())) {
      delegate.updateCredential(cred);
      return;
    }
    IdentityManager identityManager = provider.getIdentityManager();

    try {
      User picketlinkUser = BasicModel.getUser(identityManager, getUsername());
      if (picketlinkUser == null) {
        logger.debugf("User '%s' doesn't exists. Skip password update", getUsername());
        throw new IllegalStateException("User doesn't exist in LDAP storage");
      }
      if (cred.getType().equals(UserCredentialModel.PASSWORD)) {
        identityManager.updateCredential(
            picketlinkUser, new Password(cred.getValue().toCharArray()));
      } else if (cred.getType().equals(UserCredentialModel.TOTP)) {
        TOTPCredential credential = new TOTPCredential(cred.getValue());
        credential.setDevice(cred.getDevice());
        identityManager.updateCredential(picketlinkUser, credential);
      }
    } catch (IdentityManagementException ie) {
      throw new ModelException(ie);
    }
  }
Example #3
0
 public static boolean removeUser(PartitionManager partitionManager, String username) {
   IdentityManager idmManager = getIdentityManager(partitionManager);
   User picketlinkUser = BasicModel.getUser(idmManager, username);
   if (picketlinkUser == null) {
     return false;
   }
   idmManager.remove(picketlinkUser);
   return true;
 }
Example #4
0
 public static User updateUser(
     PartitionManager partitionManager,
     String username,
     String firstName,
     String lastName,
     String email) {
   IdentityManager idmManager = getIdentityManager(partitionManager);
   User picketlinkUser = BasicModel.getUser(idmManager, username);
   picketlinkUser.setFirstName(firstName);
   picketlinkUser.setLastName(lastName);
   picketlinkUser.setEmail(email);
   idmManager.update(picketlinkUser);
   return picketlinkUser;
 }
  @Override
  public void setFirstName(String first) {
    IdentityManager identityManager = provider.getIdentityManager();

    try {
      User picketlinkUser = BasicModel.getUser(identityManager, delegate.getUsername());
      if (picketlinkUser == null) {
        throw new IllegalStateException("User not found in LDAP storage!");
      }
      picketlinkUser.setFirstName(first);
      identityManager.update(picketlinkUser);
    } catch (IdentityManagementException ie) {
      throw new ModelException(ie);
    }
    delegate.setFirstName(first);
  }
Example #6
0
  public static User addUser(
      PartitionManager partitionManager,
      String username,
      String firstName,
      String lastName,
      String email) {
    IdentityManager identityManager = getIdentityManager(partitionManager);

    if (BasicModel.getUser(identityManager, username) != null) {
      throw new ModelDuplicateException("User with same username already exists");
    }
    if (getUserByEmail(identityManager, email) != null) {
      throw new ModelDuplicateException("User with same email already exists");
    }

    User picketlinkUser = new User(username);
    picketlinkUser.setFirstName(firstName);
    picketlinkUser.setLastName(lastName);
    picketlinkUser.setEmail(email);
    picketlinkUser.setAttribute(
        new Attribute("fullName", getFullName(username, firstName, lastName)));
    identityManager.add(picketlinkUser);
    return picketlinkUser;
  }
Example #7
0
 public static User getUser(PartitionManager partitionManager, String username) {
   IdentityManager idmManager = getIdentityManager(partitionManager);
   return BasicModel.getUser(idmManager, username);
 }