2 Replies Latest reply on Jul 20, 2016 9:46 AM by enginm

    partitionmanager add does not work

    enginm

      hi,

       

      i try to implemet custom idm feature, but i cant,

      here is the code,

      @ApplicationScoped

      public class IDMConfiguration {

       

       

        @Inject @PicketLink

        private EntityManager em;

       

       

        private IdentityConfiguration identityConfig = null;

       

       

        protected static final String APPLICATION_TEST_NAME = "Test Application";

       

       

        private PartitionManager partitionManager;

        private Realm acmeRealm;

        private Application spApplication;

        private ApplicationRealm spApplicationPartition;

       

       

        @Inject

        private Logger log;

       

       

        @Produces

        public IdentityConfiguration createConfig() throws Exception {

        if (identityConfig == null) {

        log.log(Level.INFO, "createConfig initconfig");

        initConfig();

       

       

        createDefaultRealm();

        createSPApplication();

        }

        return identityConfig;

        }

       

       

        @Produces

        public void initConfig() throws Exception {

        IdentityConfigurationBuilder builder = new IdentityConfigurationBuilder();

       

       

        builder.named("default").stores().jpa()

        .supportType(User.class, Role.class, Group.class, Realm.class, Application.class,

        ApplicationRealm.class)

        .supportGlobalRelationship(Grant.class, GroupMembership.class, ApplicationAccess.class)

        .supportCredentials(true)

        .mappedEntity(ApplicationAccessTypeEntity.class, ApplicationTypeEntity.class,

        ApplicationRealmTypeEntity.class, PartitionTypeEntity.class, GrantTypeEntity.class,

        GroupMembershipTypeEntity.class, GroupTypeEntity.class, RealmTypeEntity.class,

        RoleTypeEntity.class, UserTypeEntity.class, PasswordCredentialTypeEntity.class,

        RelationshipTypeEntity.class, RelationshipIdentityTypeEntity.class)

        .addContextInitializer(new ContextInitializer() {

        @Override

        public void initContextForStore(IdentityContext context, IdentityStore<?> store) {

        if (store instanceof JPAIdentityStore) {

        // EntityManager entityManager = em;// get the

        // EntityManager

        context.setParameter(JPAIdentityStore.INVOCATION_CTX_ENTITY_MANAGER, em);

       

       

        }

        }

        });

       

       

        identityConfig = builder.build();

        partitionManager = new DefaultPartitionManager(builder.buildAll());

        // Partition defaultPartition = new Realm(Resources.REALM_ACME_NAME);

        // partitionManager.add(defaultPartition,"default");

        }

       

       

        private void createSPApplication() throws Exception {

        Partition partition = partitionManager.getPartition(ApplicationRealm.class, APPLICATION_TEST_NAME);

        if (partition == null) {

        this.spApplication = new Application(APPLICATION_TEST_NAME);

       

       

        IdentityManager identityManager = partitionManager.createIdentityManager(acmeRealm);

       

       

        identityManager.add(spApplication);

       

       

        this.spApplicationPartition = new ApplicationRealm(APPLICATION_TEST_NAME);

       

       

        partitionManager.add(this.spApplicationPartition);

        }

        }

       

       

        private void createDefaultRealm() throws NoSuchAlgorithmException {

        Partition partition = getDefaultPartition();

        if (partition == null) {

        acmeRealm = new Realm(Resources.REALM_ACME_NAME);

       

       

        acmeRealm.setEnforceSSL(true);

       

       

        KeyPair keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();

       

       

        acmeRealm.setPrivateKey(keyPair.getPrivate().getEncoded());

        acmeRealm.setPublickKey(keyPair.getPublic().getEncoded());

       

       

        acmeRealm.setNumberFailedLoginAttempts(3);

       

       

      partitionManager.add(acmeRealm,"default");

        log.log(Level.INFO,"acmeRealm id:" + acmeRealm.getId());// i can see this output at console

        }

        partition = partitionManager.getPartition(Realm.class, Resources.REALM_ACME_NAME);//null pointer

        log.log(Level.INFO, partition.getId());

        }

       

       

        @Produces

        @PicketLink

        public Partition getDefaultPartition() {

        log.log(Level.INFO, "zz  getDefaultPartition");

        return partitionManager.getPartition(Realm.class, Resources.REALM_ACME_NAME);

        }

       

       

      i copied many codes from examples,

      but am getting null pointer exception on this line,

       

      partition = partitionManager.getPartition(Realm.class, Resources.REALM_ACME_NAME);

       

      this line executed in createDefaultRealm() procedure,

       

      what is wrong, i think partitionManager.add(acmeRealm,"default"); lines doesnt persist to db newly created realm, but why?

        • 1. Re: partitionmanager add does not work
          enginm

          i still spending my hours:(

           

          i switched from wildfly 8.2.1 to 10.0 but problem still exists,

           

          i developed new class like this,

          public class JpaSecurityConfiguration {

           

           

            @Inject

            private Logger log;

           

            @SuppressWarnings("unchecked")

            public void onInit(@Observes SecurityConfigurationEvent event) {

           

           

            log.info("Before SecurityConfigurationEvent");

           

           

            SecurityConfigurationBuilder builder = event.getBuilder();

            builder.idmConfig().named("default").stores().jpa()

            .supportType(MyUser.class)

            .supportAllFeatures();

            }

          }

           

           

          and this one initializer

           

          @Stateless

          public class JpaPartitionInitializer {

           

           

            @Inject

              private Logger log;

           

          // @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

              public void initPartition(@Observes PartitionManagerCreateEvent event) throws Exception {

              log.info("Before PartitionManagerCreateEvent");

              PartitionManager partitionManager = event.getPartitionManager(); 

                 

                  if (partitionManager.getPartition(Realm.class, "default") == null) { 

                  log.info("No Part , add new one PartitionManagerCreateEvent ");

                  Realm rdefault = new Realm("default");

                      partitionManager.add(rdefault);

                      partitionManager.createIdentityManager();

                  }

                  createusers(partitionManager);

              } 

          }

           

          but i still getting exception,

           

          PLIDM000406: Partition [class org.picketlink.idm.model.basic.Realm] not found with the given name [default].

           

          why picket link doesn't add the realm partition to partition list????

          • 2. Re: partitionmanager add does not work
            enginm

            is there anyone who follows this threads?