6 Replies Latest reply on Nov 10, 2014 5:51 PM by fenoloco

    picketlink idm + jpa, not loading identity model

    Arthur Gregório Newbie

      hello,

       

      I'm using picketlink to take care of the security of my application, but I have a problem that no longer know how to solve...

       

      When I initialize my application, everything went fine, until i hit the login method from the identity instance...

       

       

      final AuthenticationResult result = this.identity.login();
      

       

      this method show to me the fellowing error on the wildfly console:

       

      17:31:51,027 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-36) javax.faces.el.EvaluationException: org.picketlink.idm.IdentityManagementException: PLIDM000006: Could not initialize Partition Manager [class org.picketlink.idm.internal.DefaultPartitionManager].
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
        at javax.faces.component.UICommand.broadcast(UICommand.java:315)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
        at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
        at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
        at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
        at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
        at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)
        at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
        at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
        at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)
        at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
        at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
        at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
        at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
        at io.undertow.servlet.handlers.ServletInitialHandler.jrHandle(ServletInitialHandler.java)
        at org.zeroturnaround.javarebel.integration.servlet.undertow.cbp.ServletInitialHandlerCBP.handleRequest(ServletInitialHandlerCBP.java:76)
        at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)
        at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
        at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)
        at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)
        at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177)
        at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
      Caused by: org.picketlink.idm.IdentityManagementException: PLIDM000006: Could not initialize Partition Manager [class org.picketlink.idm.internal.DefaultPartitionManager].
        at org.picketlink.idm.internal.DefaultPartitionManager.<init>(DefaultPartitionManager.java:240)
        at org.picketlink.idm.internal.DefaultPartitionManager.<init>(DefaultPartitionManager.java:161)
        at org.picketlink.producer.IdentityManagementProducer.createEmbeddedPartitionManager(IdentityManagementProducer.java:142)
        at org.picketlink.producer.IdentityManagementProducer.init(IdentityManagementProducer.java:99)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.jboss.weld.injection.MethodInjectionPoint.invokeWithSpecialValue(MethodInjectionPoint.java:72)
        at org.jboss.weld.injection.MethodInjectionPoint.invoke(MethodInjectionPoint.java:66)
        at org.jboss.weld.util.Beans.callInitializers(Beans.java:382)
        at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:370)
        at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:72)
        at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:60)
        at org.jboss.weld.injection.producer.DefaultInjector$1.proceed(DefaultInjector.java:66)
        at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
        at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:64)
        at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:90)
        at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:150)
        at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)
        at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:733)
        at org.jboss.weld.injection.producer.AbstractMemberProducer.getReceiver(AbstractMemberProducer.java:128)
        at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:148)
        at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:183)
        at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:69)
        at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:733)
        at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:789)
        at org.jboss.weld.injection.ParameterInjectionPointImpl.getValueToInject(ParameterInjectionPointImpl.java:76)
        at org.jboss.weld.injection.MethodInjectionPoint.getParameterValues(MethodInjectionPoint.java:127)
        at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:93)
        at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstance(MethodInjectionPoint.java:86)
        at org.jboss.weld.injection.producer.ProducerMethodProducer.produce(ProducerMethodProducer.java:96)
        at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:151)
        at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:183)
        at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:69)
        at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:733)
        at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:753)
        at org.jboss.weld.bean.builtin.InstanceImpl.getBeanInstance(InstanceImpl.java:86)
        at org.jboss.weld.bean.builtin.InstanceImpl.access$100(InstanceImpl.java:58)
        at org.jboss.weld.bean.builtin.InstanceImpl$InstanceImplIterator.next(InstanceImpl.java:205)
        at org.picketlink.producer.PermissionResolverProducer.init(PermissionResolverProducer.java:50)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.jboss.weld.injection.MethodInjectionPoint.invokeWithSpecialValue(MethodInjectionPoint.java:72)
        at org.jboss.weld.injection.MethodInjectionPoint.invoke(MethodInjectionPoint.java:66)
        at org.jboss.weld.util.Beans.callInitializers(Beans.java:382)
        at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:370)
        at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:72)
        at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:60)
        at org.jboss.weld.injection.producer.DefaultInjector$1.proceed(DefaultInjector.java:66)
        at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
        at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:64)
        at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:90)
        at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:150)
        at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)
        at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:733)
        at org.jboss.weld.injection.producer.AbstractMemberProducer.getReceiver(AbstractMemberProducer.java:128)
        at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:148)
        at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:183)
        at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:69)
        at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:733)
        at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:789)
        at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
        at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:358)
        at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:369)
        at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:72)
        at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:60)
        at org.jboss.weld.injection.producer.DefaultInjector$1.proceed(DefaultInjector.java:66)
        at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
        at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:64)
        at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:90)
        at org.picketlink.internal.IdentityBeanDefinition.create(IdentityBeanDefinition.java:139)
        at org.picketlink.internal.IdentityBeanDefinition.create(IdentityBeanDefinition.java:51)
        at org.jboss.weld.util.bean.IsolatedForwardingBean.create(IsolatedForwardingBean.java:44)
        at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)
        at org.jboss.weld.context.PassivatingContextWrapper$AbstractPassivatingContextWrapper.get(PassivatingContextWrapper.java:76)
        at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:98)
        at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:99)
        at org.jboss.weld.proxies.Identity$1509662680$Proxy$_$$_WeldClientProxy.login(Unknown Source)
        at br.org.pti.portalreservas.application.controller.AuthenticationBean.doLogin(AuthenticationBean.java:51)
        at br.org.pti.portalreservas.application.controller.AuthenticationBean$Proxy$_$$_WeldClientProxy.doLogin(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at javax.el.ELUtil.invokeMethod(ELUtil.java:308)
        at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
        at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
        at com.sun.el.parser.AstValue.invoke(AstValue.java:269)
        at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
        at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
        at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
        at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
        at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
        at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
        ... 36 more
      Caused by: org.picketlink.idm.config.SecurityConfigurationException: Error while creating IdentityStore [class org.picketlink.idm.jpa.internal.JPAIdentityStore] instance for configuration [org.picketlink.idm.config.JPAIdentityStoreConfiguration@4912f53d].
        at org.picketlink.idm.internal.DefaultPartitionManager.createIdentityStore(DefaultPartitionManager.java:844)
        at org.picketlink.idm.internal.DefaultPartitionManager.<init>(DefaultPartitionManager.java:225)
        ... 133 more
      Caused by: org.picketlink.idm.config.SecurityConfigurationException: Invalid mapping for type [class org.picketlink.idm.model.basic.User]. No entity found with a field annotated with interface org.picketlink.idm.jpa.annotations.Identifier.
        at org.picketlink.idm.jpa.internal.JPAIdentityStore.checkIfAnnotationIsDefined(JPAIdentityStore.java:2017)
        at org.picketlink.idm.jpa.internal.JPAIdentityStore.validateTypeMapping(JPAIdentityStore.java:1983)
        at org.picketlink.idm.jpa.internal.JPAIdentityStore.validateConfiguration(JPAIdentityStore.java:1936)
        at org.picketlink.idm.jpa.internal.JPAIdentityStore.setup(JPAIdentityStore.java:150)
        at org.picketlink.idm.jpa.internal.JPAIdentityStore.setup(JPAIdentityStore.java:120)
        at org.picketlink.idm.internal.DefaultPartitionManager.createIdentityStore(DefaultPartitionManager.java:840)
        ... 134 more
      

       

      before this appears on console, my method that produces the IdentityConfiguration is called

       

      @Produces
          IdentityConfiguration produceIdentityConfiguration() {
              
              final IdentityConfigurationBuilder builder = new IdentityConfigurationBuilder();
      
      
              builder.named("jpa.config")
                      .stores()
                      .jpa()
                      .supportType(
                              User.class,
                              Role.class,
                              Group.class,
                              Realm.class)
                      .supportGlobalRelationship(
                              Grant.class,
                              GroupMembership.class)
                      .supportCredentials(true)
                      .mappedEntity(
                              PartitionTypeEntity.class,
                              GrantTypeEntity.class,
                              GroupMembershipTypeEntity.class,
                              GroupTypeEntity.class,
                              RealmTypeEntity.class,
                              RoleTypeEntity.class,
                              UserTypeEntity.class,
                              PasswordCredentialTypeEntity.class,
                              RelationshipTypeEntity.class,
                              RelationshipIdentityTypeEntity.class)
                      .addContextInitializer(this.contextInitializer)
                      .supportAllFeatures();
              
              return builder.build();
          }
      

      but the mthod with the partition configurations is not called...

       

          public void configureDefaultPartition(@Observes PartitionManagerCreateEvent event) {
             
              final PartitionManager partitionManager = event.getPartitionManager();
              
              final IdentityManager identityManager = partitionManager.createIdentityManager();
              
              this.checkForDefaultRealm(partitionManager);
              this.checkForDefaultGroups(identityManager);
              this.checkForDefaultRoles(identityManager);
              this.checkForDefaultUsers(partitionManager, identityManager);
          }
      

      is my configurations wrong? i'm using Plink 2.7.0 Beta 2 and i'm following the samples in picketlink quickstarts but it seems I'm missing or doing something wrong ...

       

      any help?

        • 1. Re: picketlink idm + jpa, not loading identity model
          Arthur Gregório Newbie

          maybe i found something...

          erro.png

          this classes from org.picketlink.id.model.basic.* are not mapped in my configuration, but appears here and are creating errors on the configuration phase.

           

          any idea how to remove them?

           

          my configuration:

           

          @ApplicationScoped
          public class SecurityConfiguration {
          
          
              @PersistenceContext
              private EntityManager entityManager;
            
              @Inject
              private EntityManagerContextInitializer contextInitializer;
          
          
              /**
               *
               * @return
               */
              @Produces
              @PicketLink
              public EntityManager produceEntityManager() {
                  return this.entityManager;
              }
            
              /**
               *
               * @return
               */
              @Produces
              @PicketLink
              public PartitionManager producePartitionManager() {
          
          
                  final IdentityConfigurationBuilder builder = new IdentityConfigurationBuilder();
                
                  builder.named("jpa.store")
                          .stores()
                          .jpa()
                          .mappedEntity(
                                  PartitionTypeEntity.class,
                                  GrantTypeEntity.class,
                                  GroupMembershipTypeEntity.class,
                                  GroupTypeEntity.class,
                                  RealmTypeEntity.class,
                                  RoleTypeEntity.class,
                                  UserTypeEntity.class,
                                  PasswordCredentialTypeEntity.class,
                                  RelationshipTypeEntity.class,
                                  RelationshipIdentityTypeEntity.class)
                          .addContextInitializer(this.contextInitializer)
                          .supportType(
                                  User.class,
                                  Role.class,
                                  Group.class,
                                  Realm.class)
                          .supportGlobalRelationship(
                                  Grant.class,
                                  GroupMembership.class)
                          .supportCredentials(true)
                          .supportAllFeatures();
                
                  return new DefaultPartitionManager(builder.buildAll());
              }
          }
          
          

           

          pcraveiro pode dar uma ajuda? estou seguindo seus materiais do quickstart...

          • 2. Re: picketlink idm + jpa, not loading identity model
            Arthur Gregório Newbie

            news about the problem...

            when i provide my configurations, the classes from basic model are still loaded and when the application try to use them, the error appears...

             

            the following image show the with plink.model.basic.user on checkIfAnnotationIsDefined method of JPAIdentityStore

            erro_idm.png

            any idea how to solve this?

            • 3. Re: picketlink idm + jpa, not loading identity model
              Pedro Igor Master

              Hey Arthur,

               

                  When you call supportsAllFeatures in the configuration PL will add all the types from the basic identity model. When using JPA you must also configure your META-INF/persistence.xml with the entities that are mapping all your supported types.

               

                  I would suggest you to review your persistence configuration. Also, you don't need to specify the mappedEntity, PL will read your entities from the persistence.xml.

               

              Regards.

              • 4. Re: picketlink idm + jpa, not loading identity model
                fenoloco Newbie

                Hi,

                 

                I have a EAR package where I have a EJB module with the persistence.xml and all database access clases. In other .war module I have the Rest services

                How can I configure the mapping to say to PL takes the configuration from the EJB persistance.xml, PL only finds in the war package.

                • 5. Re: picketlink idm + jpa, not loading identity model
                  Pedro Igor Master

                  Hi,

                   

                      I think you just need to provide a producer to your EntityManager instances. I don't know how are you inject the EntityManager in your WAR, but once you do that is just a matter of creating a producer. You can also annotate your producer to @PicketLink in order to tell which EntityManager should be used if you have many.

                   

                  Regards.

                  • 6. Re: Re: picketlink idm + jpa, not loading identity model
                    fenoloco Newbie

                    Hi,

                    Thanks for the response, the problem was exactly what you indicate.

                    However I think that a logging message with a warning to indicate that the resource is was not found could be useful for users. What do you think?

                     

                    An example that solve the problem.

                     

                       @Produces
                       @PicketLink
                       @PersistenceContext(name = "XXXXX")
                       private EntityManager entityManager;
                    

                     

                    Thanks again,

                    Mauricio