2 Replies Latest reply on Jan 30, 2015 5:12 AM by valsaraj007

    Unable to get private credentials

    valsaraj007

      Hi,

       

      I have added private key into private credentials during login but unable to retrieve it later. I will share the code snippets.

       

      Code that adds prvate key during login:

      MyPrivateKey myPrivateKey = myKeyRing.getMyPrivateKey();

      subject.getPrivateCredentials().add(myPrivateKey);

       

      Code that retrieves private key later:

      Set<MyPrivateKey> myPrivateKeys = subject.getPrivateCredentials(MyPrivateKey.class); // this code fails to return private key with class MyPrivateKey

       

      But the following code returns a private key of class type Object and unable to cast to MyPrivateKey:

      Set<Object> privateKeys = subject.getPrivateCredentials();

       

      When I compared added and retrieved private key of type Object, they are same. I am wondering why this code fails, Set<MyPrivateKey> myPrivateKeys = subject.getPrivateCredentials(MyPrivateKey.class); But this code worked when I deployed in Jboss 4.2.2 GA.

       

      Please share if you have idea.

       

      Thanks in advance!

        • 1. Re: Unable to get private credentials
          valsaraj007

          Do we need to configure any kind of policy permission in JBoss?

           

          TRACE [org.jboss.security.audit] (default task-5) [Success]Source=org.jboss.security.plugins.javaee.EJBAuthorizationHelper;Action=authorization;Resource:=[org.jboss.security.authorization.resources.EJBResource:contextMap={policyRegistration=null}:method=public abstract java.lang.String org.app.core.AppPropertiesLocal.getProperty(java.lang.String):ejbMethodInterface=Local:ejbName=AppProperties:ejbPrincipal=org.wildfly.extension.undertow.security.AccountImpl$AccountPrincipal@1a3af:MethodRoles=Roles(<ANYBODY>,):securityRoleReferences=null:callerSubject=Subject:

            Principal: org.wildfly.extension.undertow.security.AccountImpl$AccountPrincipal@1a3af

            Principal: lt7

            Principal: Roles(members:appAccountUserManager)

            Public Credential: org.app.security.key.UserPublicKey@3a5e3bf4

            Private Credential: org.app.security.key.MyPrivateKey@b22e1c

          :callerRunAs=null:callerRunAs=null:ejbRestrictionEnforcement=false:ejbVersion=2.0];policyRegistration=null;

          TRACE [org.jboss.security] (default task-5) PBOX000354: Setting security roles ThreadLocal: null

          TRACE [org.jboss.security.audit] (default task-6) [Success]Source=org.jboss.as.security.service.SimpleSecurityManager;Action=authentication;principal=anonymous;

          TRACE [org.jboss.security] (default task-6) PBOX000354: Setting security roles ThreadLocal: {}

          DEBUG [org.jboss.security] (default task-6) PBOX000293: Exception caught: javax.naming.NameNotFoundException: policyRegistration -- service jboss.naming.context.java.policyRegistration

           

          In this log,   Principal: lt7 is what I added from login module. Also, the private credential can be seen which I am not able to retrieve. When compared to old JBoss version, it is same except Principal: org.wildfly.extension.undertow.security.AccountImpl$AccountPrincipal@1a3af which is an addition in WildFly.

          • 2. Re: Unable to get private credentials
            valsaraj007

            When I added password as String, it worked.

            String password = "xxxxxxxxxxxxxxx";

            subject.getPrivateCredentials().add(password );

             

            I am able to get this using, subject.getPrivateCredentials(String.class);

             

            So I am wondering why Set<MyPrivateKey> myPrivateKeys = subject.getPrivateCredentials(MyPrivateKey.class); not worked. Is this because it is a user defined class? Do we need to add such classes to be able to retrieve them?

            1 of 1 people found this helpful