/**
 * JBoss, Home of Professional Open Source
 * Copyright Red Hat, Inc., and individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.aerogear.unifiedpush.users;

import org.picketlink.idm.IdentityManager;
import org.picketlink.idm.PartitionManager;
import org.picketlink.idm.RelationshipManager;
import org.picketlink.idm.credential.Password;
import org.picketlink.idm.model.sample.Role;
import org.picketlink.idm.model.sample.SampleModel;
import org.picketlink.idm.model.sample.User;

import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;
import java.util.Calendar;
import java.util.Date;

@Singleton
@Startup
/**
 * Preload a default user into the database
 */
public class PicketLinkDefaultUsers {

    @Inject
    private IdentityManager identityManager;
    @Inject
    private PartitionManager partitionManager;

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

        final String DEFAULT_PASSWORD = "123";

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

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

        Role roleDeveloper = new Role(UserRoles.DEVELOPER);

        this.identityManager.add(roleDeveloper);

        grantRoles(adminUser, roleDeveloper);

    }

    // We only create the Admin, if there is none
    private User buildUser() {
        final String DEFAULT_USER = "admin";
        User user = SampleModel.getUser(identityManager, DEFAULT_USER);
        if (user == null) {
            user = new User(DEFAULT_USER);
            identityManager.add(user);
        }
        return user;
    }

    private void grantRoles(User user, Role role) {
        RelationshipManager relationshipManager = partitionManager.createRelationshipManager();
        SampleModel.grantRole(relationshipManager, user, role);
    }

    //Expiration date of the password
    private Calendar expirationDate() {
        int EXPIRATION_TIME = -5;
        Calendar expirationDate = Calendar.getInstance();
        expirationDate.add(Calendar.MINUTE, EXPIRATION_TIME);
        return expirationDate;
    }
}

@@ -1317,32 +1317,80 @@
  %7B%0A%0A    @Inject%0A
+    private PartitionManager partitionManager;%0A%0A
     private Iden
@@ -1418,28 +1418,16 @@
 anager;%0A
-    @Inject%0A
     priv
@@ -1434,34 +1434,40 @@
 ate 
-PartitionManager partition
+RelationshipManager relationship
 Mana
@@ -1600,24 +1600,179 @@
 create() %7B%0A%0A
+        this.identityManager = partitionManager.createIdentityManager();%0A        this.relationshipManager = partitionManager.createRelationshipManager();%0A%0A
         fina
@@ -2123,37 +2123,32 @@
 OPER);%0A%0A        
-this.
 identityManager.
@@ -2624,104 +2624,8 @@
 ) %7B%0A
-        RelationshipManager relationshipManager = partitionManager.createRelationshipManager();%0A
     

Update with the initialization method to be compatible with the latest changes on the IDM