예제 #1
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);
  }
  /** 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);
    }
  }
  @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));
      }
    }
  }
예제 #4
0
 @Override
 public void updateApplication() {
   partitionManager.update(applicationData);
 }
예제 #5
0
 protected RelationshipManager getRelationshipManager() {
   if (relationshipManager == null)
     relationshipManager = partitionManager.createRelationshipManager();
   return relationshipManager;
 }
예제 #6
0
 protected IdentityManager getIdm() {
   if (idm == null) idm = partitionManager.createIdentityManager(applicationData);
   return idm;
 }
예제 #7
0
 private static IdentityManager getIdentityManager(PartitionManager partitionManager) {
   return partitionManager.createIdentityManager();
 }
예제 #8
0
 private void createDefaultPartition(PartitionManager partitionManager) {
   if (partitionManager.getPartition(Realm.class, Realm.DEFAULT_REALM) == null) {
     partitionManager.add(new Realm(Realm.DEFAULT_REALM));
   }
 }