2 Replies Latest reply on Mar 13, 2014 10:23 AM by grzegorz_brzeczyszczykiewicz

    complex schema not working out of the box

    grzegorz_brzeczyszczykiewicz

      version 2.5.2

       

      hi,

       

       

      i'm trying to deploy a test app with the complex schema in the same way as the

      simple schema but its not working.

       

       

      i got error like this:

      Could not find mapper for attributes for type [class org.picketlink.idm.jpa.model.sample.complex.Company].

       

       

      could you please find the missing or needless annotation or something?

       

       

      and what is the purpose of an entity having attributes in separate EntityAttribute class?

       

       

      why are entities not recognized automatically and must be listed in persistence.xml?

       

       

       

       

       

       

      this is the relevant code and stack trace below:

       

       

       

       

      @Singleton
      @Startup
      public class IDMInitializer {
      
      
      //    @Inject
      //    private IdentityManager identityManager;
      //
      //    @Inject
      //    private RelationshipManager relationShipManager;
          
          @Inject
          @PicketLink
          private PartitionManager partitionManager;
          
          
          @PostConstruct
          public void create() {
              EmployeeUser john = new EmployeeUser();
              john.setEmail(new Email("john@acme.com"));
              Person joPerson = new Person();
              joPerson.setFirstName("John");
              john.setPerson(joPerson);
              Partition partition = partitionManager.getPartition(Partition.class, "klaus");
              
              IdentityManager identityManager = this.partitionManager.createIdentityManager(partition);
      
      
              identityManager.add(john);
              identityManager.updateCredential(john, new Password("demo"));
        }
      }
      
      
      
      
      @ApplicationScoped
      public class IDMConfiguration {
      
      
      
        @Inject
        EEJPAContextInitializer contextInitializer;
      //
          private IdentityConfiguration identityConfig;
          private PartitionManager partitionManager;
          
          @Produces
          @PicketLink
          public PartitionManager producePartitionManager(){
          System.out.println("produce partition manager");
          if (partitionManager == null) {
        partitionManager = new DefaultPartitionManager(
        produceJPAConfiguration());
        Partition subsidiary = new Company("klaus");
        partitionManager.add(subsidiary, "klaus");
        }
        return partitionManager;
          }
          
      //    @Produces
      //    @PicketLink
          public IdentityConfiguration produceJPAConfiguration() {
          System.out.println("create config");
              if (identityConfig == null) {
                  initConfig();
              }
              return identityConfig;
          }
      
      
          private void initConfig() {
          System.out.println("init config");
          IdentityConfigurationBuilder builder = new IdentityConfigurationBuilder();
              
              identityConfig = builder
                  .named("klaus")
                      .stores()
                          .jpa()
                              .mappedEntity(
                              org.picketlink.idm.jpa.model.sample.complex.entity.Application.class,
                              org.picketlink.idm.jpa.model.sample.complex.entity.ApplicationAuthorization.class,
                              org.picketlink.idm.jpa.model.sample.complex.entity.Company.class,
                              org.picketlink.idm.jpa.model.sample.complex.entity.RelationshipTypeEntity.class,
                              org.picketlink.idm.jpa.model.sample.complex.entity.Customer.class,
                              org.picketlink.idm.jpa.model.sample.complex.entity.Email.class,
                              org.picketlink.idm.jpa.model.sample.complex.entity.Employee.class,
                              org.picketlink.idm.jpa.model.sample.complex.entity.IdentityObject.class,
                              org.picketlink.idm.jpa.model.sample.complex.entity.OrganizationUnit.class,
                              org.picketlink.idm.jpa.model.sample.complex.entity.UserAccount.class,
                              org.picketlink.idm.jpa.model.sample.complex.entity.UserAccountControl.class)
                              //IdentityStoreConfigurationBuilder
                              . supportGlobalRelationship(Relationship.class)// param type also Relationship
                              .addContextInitializer(this.contextInitializer)
                              .supportAllFeatures().build();
          }
      
      
      }
      
      
      
      
      public class Resources {
      
      
          @Produces
          @RequestScoped
          public FacesContext produceFacesContext() {
              return FacesContext.getCurrentInstance();
          }
      
      
          /*
           * Since we are using JPAIdentityStore to store identity-related data, we must provide it with an EntityManager via a
           * producer method or field annotated with the @PicketLink qualifier.
           */
          @Produces
          @PicketLink
          @PersistenceContext(unitName = "forge-default")
          private EntityManager picketLinkEntityManager;
      
      
      }
      

       

       

       

      classes in persistence.xml

       

       

        <class>org.picketlink.idm.jpa.model.sample.complex.entity.Address</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.Application</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.ApplicationAttribute</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.ApplicationAuthorization</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.Company</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.CompanyAttribute</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.RelationshipAttribute</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.RelationshipIdentityTypeEntity</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.RelationshipTypeEntity</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.Country</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.Customer</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.Email</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.Employee</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.IdentityObject</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.OrganizationUnit</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.OrganizationUnitAttribute</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.Person</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.Phone</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.UserAccount</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.UserAccountControl</class>
        <class>org.picketlink.idm.jpa.model.sample.complex.entity.UserAttribute</class>
      

       

       

       

      stacktrace:

       

       

      08:43:49,367 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) JBAS016008: Starting weld service for deployment zeiterfassung.war
      08:43:49,973 INFO  [stdout] (MSC service thread 1-5) produce partition manager
      08:43:49,976 INFO  [stdout] (MSC service thread 1-5) create config
      08:43:49,977 INFO  [stdout] (MSC service thread 1-5) init config
      08:43:49,985 INFO  [org.picketlink.common] (MSC service thread 1-5) Using logger implementation: org.picketlink.common.DefaultPicketLinkLogger
      08:43:49,992 INFO  [org.picketlink.idm] (MSC service thread 1-5) PLIDM001000: Bootstrapping PicketLink Identity Manager
      08:43:50,538 INFO  [stdout] (MSC service thread 1-5) Hibernate: 
      08:43:50,539 INFO  [stdout] (MSC service thread 1-5)     select
      08:43:50,539 INFO  [stdout] (MSC service thread 1-5)         company0_.id as id6_,
      08:43:50,539 INFO  [stdout] (MSC service thread 1-5)         company0_.configurationName as configur2_6_,
      08:43:50,539 INFO  [stdout] (MSC service thread 1-5)         company0_.domain as domain6_,
      08:43:50,540 INFO  [stdout] (MSC service thread 1-5)         company0_.name as name6_,
      08:43:50,540 INFO  [stdout] (MSC service thread 1-5)         company0_.type as type6_ 
      08:43:50,540 INFO  [stdout] (MSC service thread 1-5)     from
      08:43:50,541 INFO  [stdout] (MSC service thread 1-5)         Company company0_ 
      08:43:50,541 INFO  [stdout] (MSC service thread 1-5)     where
      08:43:50,541 INFO  [stdout] (MSC service thread 1-5)         company0_.name=? 
      08:43:50,541 INFO  [stdout] (MSC service thread 1-5)         and company0_.type=?
      08:43:50,592 INFO  [stdout] (MSC service thread 1-5) Hibernate: 
      08:43:50,592 INFO  [stdout] (MSC service thread 1-5)     select
      08:43:50,593 INFO  [stdout] (MSC service thread 1-5)         company0_.id as id6_0_,
      08:43:50,593 INFO  [stdout] (MSC service thread 1-5)         company0_.configurationName as configur2_6_0_,
      08:43:50,593 INFO  [stdout] (MSC service thread 1-5)         company0_.domain as domain6_0_,
      08:43:50,594 INFO  [stdout] (MSC service thread 1-5)         company0_.name as name6_0_,
      08:43:50,594 INFO  [stdout] (MSC service thread 1-5)         company0_.type as type6_0_ 
      08:43:50,594 INFO  [stdout] (MSC service thread 1-5)     from
      08:43:50,595 INFO  [stdout] (MSC service thread 1-5)         Company company0_ 
      08:43:50,595 INFO  [stdout] (MSC service thread 1-5)     where
      08:43:50,595 INFO  [stdout] (MSC service thread 1-5)         company0_.id=?
      08:43:50,649 INFO  [stdout] (MSC service thread 1-5) Hibernate: 
      08:43:50,650 INFO  [stdout] (MSC service thread 1-5)     insert 
      08:43:50,650 INFO  [stdout] (MSC service thread 1-5)     into
      08:43:50,650 INFO  [stdout] (MSC service thread 1-5)         Company
      08:43:50,651 INFO  [stdout] (MSC service thread 1-5)         (configurationName, domain, name, type, id) 
      08:43:50,651 INFO  [stdout] (MSC service thread 1-5)     values
      08:43:50,651 INFO  [stdout] (MSC service thread 1-5)         (?, ?, ?, ?, ?)
      08:43:50,659 INFO  [stdout] (MSC service thread 1-5) Hibernate: 
      08:43:50,659 INFO  [stdout] (MSC service thread 1-5)     update
      08:43:50,659 INFO  [stdout] (MSC service thread 1-5)         Company 
      08:43:50,659 INFO  [stdout] (MSC service thread 1-5)     set
      08:43:50,660 INFO  [stdout] (MSC service thread 1-5)         configurationName=?,
      08:43:50,660 INFO  [stdout] (MSC service thread 1-5)         domain=?,
      08:43:50,660 INFO  [stdout] (MSC service thread 1-5)         name=?,
      08:43:50,660 INFO  [stdout] (MSC service thread 1-5)         type=? 
      08:43:50,661 INFO  [stdout] (MSC service thread 1-5)     where
      08:43:50,661 INFO  [stdout] (MSC service thread 1-5)         id=?
      08:43:50,671 INFO  [stdout] (MSC service thread 1-5) Hibernate: 
      08:43:50,672 INFO  [stdout] (MSC service thread 1-5)     select
      08:43:50,672 INFO  [stdout] (MSC service thread 1-5)         company0_.id as id6_,
      08:43:50,672 INFO  [stdout] (MSC service thread 1-5)         company0_.configurationName as configur2_6_,
      08:43:50,673 INFO  [stdout] (MSC service thread 1-5)         company0_.domain as domain6_,
      08:43:50,673 INFO  [stdout] (MSC service thread 1-5)         company0_.name as name6_,
      08:43:50,674 INFO  [stdout] (MSC service thread 1-5)         company0_.type as type6_ 
      08:43:50,674 INFO  [stdout] (MSC service thread 1-5)     from
      08:43:50,675 INFO  [stdout] (MSC service thread 1-5)         Company company0_ 
      08:43:50,675 INFO  [stdout] (MSC service thread 1-5)     where
      08:43:50,676 INFO  [stdout] (MSC service thread 1-5)         company0_.name=?
      08:43:50,719 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC00001: Failed to start service jboss.deployment.unit."zeiterfassung.war".component.IDMInitializer.START: org.jboss.msc.service.StartException in service jboss.deployment.unit."zeiterfassung.war".component.IDMInitializer.START: Failed to start service
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
        at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
      Caused by: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163)
        at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:85)
        at org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:116)
        at org.jboss.as.ejb3.component.singleton.SingletonComponent.start(SingletonComponent.java:130)
        at org.jboss.as.ee.component.ComponentStartService.start(ComponentStartService.java:44)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
        ... 3 more
      Caused by: javax.ejb.EJBException: org.picketlink.idm.IdentityManagementException: PLIDM000405: Could not load partition for type [interface org.picketlink.idm.model.Partition] and identifier [klaus].
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:230)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:333)
        at org.jboss.as.ejb3.tx.SingletonLifecycleCMTTxInterceptor.processInvocation(SingletonLifecycleCMTTxInterceptor.java:56)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161)
        ... 9 more
      Caused by: org.picketlink.idm.IdentityManagementException: PLIDM000405: Could not load partition for type [interface org.picketlink.idm.model.Partition] and identifier [klaus].
        at org.picketlink.idm.internal.DefaultPartitionManager.getPartition(DefaultPartitionManager.java:369)
        at com.testproject.IDMInitializer.create(IDMInitializer.java:49)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_45]
        at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_45]
        at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptorFactory$ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptorFactory.java:130)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:73)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:95)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228)
        ... 18 more
      Caused by: org.picketlink.idm.IdentityManagementException: Could not find mapper for attributes for type [class org.picketlink.idm.jpa.model.sample.complex.Company].
        at org.picketlink.idm.jpa.internal.JPAIdentityStore.getAttributeMapper(JPAIdentityStore.java:1258)
        at org.picketlink.idm.jpa.internal.JPAIdentityStore.getAttributes(JPAIdentityStore.java:1105)
        at org.picketlink.idm.jpa.internal.JPAIdentityStore.loadAttributes(JPAIdentityStore.java:317)
        at org.picketlink.idm.internal.DefaultPartitionManager.getPartition(DefaultPartitionManager.java:363)
        ... 36 more
      
        • 1. Re: complex schema not working out of the box
          pcraveiro

          Hi,

           

               The complex schema is mostly used during our unit tests, so we can assert some advanced mapping for the JPA store. That is the reason why we're not releasing it.

           

               But from your information, I think the issue is because you're missing to configure the CompanyAttribute entity during the configuration:

           

          .mappedEntity(  
              org.picketlink.idm.jpa.model.sample.complex.entity.CompanyAttribute.class
          )
          
          

           

               I would suggest you to write your own IDM/Entity model, accordingly with your requirements, and then apply the PicketLink annotations, instead.

           

          Regards.

          Pedro Igor

          • 2. Re: Re: complex schema not working out of the box
            grzegorz_brzeczyszczykiewicz

            thanks for your reply.

             

            i'm on the project back again.

             

            i figured out that once i started to customize my data model i have to customize almost everything.

            e.g. in building config:

            .mappedEntity(... ) // its hard not to forget some entity
            .addCredentialHandler(PasswordCredentialHandler.class)// suprised?
            .setCredentialHandlerProperty(CredentialHandler.SUPPORTED_ACCOUNT_TYPES_PROPERTY, ...)
            

             

            application scoped:

            @Produces
                @PicketLink
                public Partition getDefaultPartition() {
                    return partitionManager.getPartition(MyCompany.class, "default");
                }
            

             

            what i did is subclassing the idm.model.basic.* model

            and subclassing the model.sample.simple.* entities.

             

             

            now it works but i'm not sure if this is the best practice to adapt a data model to picketlink.