@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));
      }
    }
  }
Exemplo n.º 2
0
  @Produces
  @PicketLink
  public Partition getDefaultPartition() {
    if (credentials.getCredential() instanceof TokenCredential) {
      return partitionManager.getPartition(Realm.class, "token");
    }

    return partitionManager.getPartition(Realm.class, Realm.DEFAULT_REALM);
  }
Exemplo n.º 3
0
 private void createDefaultPartition(PartitionManager partitionManager) {
   if (partitionManager.getPartition(Realm.class, Realm.DEFAULT_REALM) == null) {
     partitionManager.add(new Realm(Realm.DEFAULT_REALM));
   }
 }