Unable to obtain instance from null - PicketLink

991 views Asked by At

We are getting this error:

[ERROR] Caused by: java.lang.Throwable: WELD-000044 Unable to obtain instance from null
[ERROR]     at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:48)
[ERROR]     at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
[ERROR]     at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105)
[ERROR]     at org.jboss.weldx.persistence.EntityManager$1841842027$Proxy$_$$_Weld$Proxy$.getCriteriaBuilder(EntityManager$1841842027$Proxy$_$$_Weld$Proxy$.java)
[ERROR]     at org.picketlink.idm.jpa.internal.JPAIdentityStore.getPartitions(JPAIdentityStore.java:298)
[ERROR]     at org.picketlink.idm.jpa.internal.JPAIdentityStore.get(JPAIdentityStore.java:290)
[ERROR]     at org.picketlink.idm.internal.DefaultPartitionManager.getPartitions(DefaultPartitionManager.java:325)
[ERROR]     ... 80 more

And investigating, I can see that this is the root cause:

DefaultPartionManager.java

Method that throws error:

public <T extends Partition> List<T> getPartitions(Class<T> partitionClass)

Here:

throw MESSAGES.partitionGetFailed(partitionClass, "not specified", e);

However I am confused about this error when we have set the PartitionTypeEntity.class in the IDMConfiguration.java:

@ApplicationScoped
public class IDMConfiguration {
    @Inject
    private EEJPAContextInitializer contextInitializer;

    private IdentityConfiguration identityConfig = null;

    @Produces
    IdentityConfiguration createConfig() {
        if (identityConfig == null) {
            initConfig(null);
        }
        return identityConfig;
    }

    public void configureIdentityManagement(@Observes IdentityConfigurationEvent event) {
        initConfig(event.getConfig());
    }

        public void initConfig(IdentityConfigurationBuilder builder){
        if (builder == null){
            builder = new IdentityConfigurationBuilder();
        }
        builder.named("default" + "").stores().jpa().mappedEntity(
                    AccountTypeEntity.class,
                    RoleTypeEntity.class,
                    GroupTypeEntity.class,
                    IdentityTypeEntity.class,
                    RelationshipTypeEntity.class,
                    RelationshipIdentityTypeEntity.class,
                    PartitionTypeEntity.class,
                    PasswordCredentialTypeEntity.class,
                    AttributeTypeEntity.class)
                    //UserImpl.class)
                .supportGlobalRelationship(Relationship.class)
                .addContextInitializer(this.contextInitializer)
                .setCredentialHandlerProperty(PasswordCredentialHandler.SUPPORTED_ACCOUNT_TYPES_PROPERTY, UserImpl.class)

                .supportAllFeatures();
        identityConfig = builder.build();
    }

}
1

There are 1 answers

2
user3749223 On BEST ANSWER

Check your database, is there a entry for a "default" PartitionTypeEntity? I think you should check to see if it exists before you start using it. Picketlink is supposed to automatically create a default partition the first time you use it but I guess sometimes it doesn't do it for you. For me, in an IDMInitializer, I had to check if there was a "default" partition first and if there wasn't, I had to create a new Realm() before I start using the application.

    @Singleton
    @Startup
    public class IDMInitializer{
    @Inject
    private PartitionManager partitionManager;

    @PostConstruct
    public void init(){
            Realm defaultReam = this.partitionManager.getPartition(Realm.class, "default");
            if (defaultReam==null){
                    System.out.println("Couldn't find default partition, creating default partition");
                    defaultRealm = new Realm("default");
                    this.partitionManager.add(defaultRealm);
            } else {
                    System.out.println("Found default partition");
            }
    }
    }