コード例 #1
0
  @PostConstruct
  public void create() throws Exception {
    Realm cd = new Realm(REALM_CD_NAME);
    Realm storedRealm = partitionManager.getPartition(Realm.class, cd.getName());
    if (storedRealm == null) {
      cd.setEnforceSSL(true);
      KeyPair keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
      cd.setPrivateKey(keyPair.getPrivate().getEncoded());
      cd.setPublickKey(keyPair.getPublic().getEncoded());
      cd.setNumberFailedLoginAttempts(3);
      partitionManager.add(cd);

      IdentityManager cdIdentityManager = partitionManager.createIdentityManager(cd);

      Role Administrator = new Role("Administrator");
      Role Customer = new Role("Customer");
      Role Consumer = new Role("Consumer");
      Role Vendor = new Role("Vendor");
      Role Contacts = new Role("Contacts");

      cdIdentityManager.add(Administrator);
      cdIdentityManager.add(Customer);
      cdIdentityManager.add(Consumer);
      cdIdentityManager.add(Vendor);
      cdIdentityManager.add(Contacts);

      User user = new User("admin");
      cdIdentityManager.add(user);
      Password password = new Password("admin");
      cdIdentityManager.updateCredential(user, password);

      RelationshipManager relationshipManager = partitionManager.createRelationshipManager();
      relationshipManager.add(new Grant(user, Administrator));

      Realm cdcustomer = new Realm(REALM_CDCustomer_NAME);
      Realm customerRealm = partitionManager.getPartition(Realm.class, cdcustomer.getName());

      if (customerRealm == null) {
        cdcustomer.setEnforceSSL(true);
        KeyPair keyPaircustomer = KeyPairGenerator.getInstance("RSA").generateKeyPair();
        cdcustomer.setPrivateKey(keyPaircustomer.getPrivate().getEncoded());
        cdcustomer.setPublickKey(keyPaircustomer.getPublic().getEncoded());
        cdcustomer.setNumberFailedLoginAttempts(3);
        partitionManager.add(cdcustomer);

        IdentityManager cdIdentityManagercst = partitionManager.createIdentityManager(cdcustomer);

        User customer = new User("customer");
        cdIdentityManagercst.add(customer);
        Password demo = new Password("demo");
        cdIdentityManagercst.updateCredential(customer, demo);
        relationshipManager.add(new Grant(customer, Customer));

        User consumer = new User("consumer");
        cdIdentityManagercst.add(consumer);
        cdIdentityManagercst.updateCredential(consumer, demo);
        relationshipManager.add(new Grant(consumer, Consumer));
      }
    }
  }
コード例 #2
0
  /** 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);
    }
  }
コード例 #3
0
 protected IdentityManager getIdm() {
   if (idm == null) idm = partitionManager.createIdentityManager(applicationData);
   return idm;
 }
コード例 #4
0
ファイル: LDAPUtils.java プロジェクト: hoangbt/keycloak
 private static IdentityManager getIdentityManager(PartitionManager partitionManager) {
   return partitionManager.createIdentityManager();
 }