0 Replies Latest reply on Mar 15, 2002 5:46 AM by linux_china

    jaas login failed,and I am made!

    linux_china Newbie

      I have jboss-2.4.4 installed!
      Now I have a big problem when I have a security with my ejb!

      %JBOSS_DIST%\conf\default\roles.properties
      scott=test
      scott.CallerPrincipal=caller_scott

      %JBOSS_DIST%\conf\default\users.properties
      scott=abc123

      ejb-jar.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar>
      JBoss Simple stateless session bean
      <display-name>UserInfo EJB</display-name>
      <enterprise-beans>

      <ejb-name>ejbfirst</ejb-name>
      ejbfirst.EJBFirstHome
      ejbfirst.EJBFirst
      <ejb-class>ejbfirst.EJBFirstBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
      <security-role-ref>
      <role-name>test</role-name>
      <role-link>test</role-link>
      </security-role-ref>

      </enterprise-beans>
      <assembly-descriptor>
      <security-role>
      <role-name>test</role-name>
      </security-role>
      <method-permission>
      <role-name>test</role-name>

      <ejb-name>ejbfirst</ejb-name>
      <method-name>*</method-name>

      </method-permission>
      </assembly-descriptor>
      </ejb-jar>

      jboss.xml
      <?xml version="1.0" encoding="UTF-8"?>

      <security-domain>java:/jaas/client-login</security-domain>
      <enterprise-beans>

      <ejb-name>ejbfirst</ejb-name>
      <jndi-name>ejb/ejbfirst</jndi-name>

      </enterprise-beans>


      the deploy is successful!
      the client test file is:
      EJBTestJaas.java
      import java.rmi.*;
      import javax.rmi.*;
      import javax.ejb.*;
      import javax.naming.*;
      import java.util.*;
      import ejbfirst.*;
      import javax.security.auth.callback.*;
      import javax.security.auth.login.*;
      public class EJBTestJaas
      { public static void main(String[] args)
      { try
      { String name = "scott";
      char[] password = "abc123".toCharArray();
      Properties h=System.getProperties();
      h.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      h.put(Context.PROVIDER_URL,"jnp://localhost:1099");
      AppCallbackHandler handler = new AppCallbackHandler(name, password);
      LoginContext lc = new LoginContext("client-login", handler);
      lc.login();
      System.out.println("login ok");
      //h.put(Context.SECURITY_PRINCIPAL,"scott");
      //h.put(Context.SECURITY_CREDENTIALS,"abc123");
      InitialContext initial=new InitialContext();
      long start=System.currentTimeMillis();
      Object objref=initial.lookup("ejb/ejbfirst");
      EJBFirstHome home=(EJBFirstHome)PortableRemoteObject.narrow(objref,EJBFirstHome.class);
      EJBFirst first=home.create();
      System.out.println(first.getUserName());
      long end=System.currentTimeMillis();
      System.out.println("time passed is "+(end-start));
      } catch( Exception e)
      { System.out.println(e.toString());
      }
      }
      static class AppCallbackHandler implements CallbackHandler
      {
      private String username;
      private char[] password;
      public AppCallbackHandler(String username, char[] password)
      {
      this.username = username;
      this.password = password;
      }
      public void handle(Callback[] callbacks) throws
      java.io.IOException, UnsupportedCallbackException
      {
      for (int i = 0; i < callbacks.length; i++)
      {
      if (callbacks instanceof NameCallback)
      {
      NameCallback nc = (NameCallback)callbacks
      ;
      nc.setName(username);
      }
      else if (callbacks instanceof PasswordCallback)
      {
      PasswordCallback pc = (PasswordCallback)callbacks
      ;
      pc.setPassword(password);
      }
      else
      {
      throw new UnsupportedCallbackException(callbacks, "Unrecognized Callback");
      }
      }
      }
      }
      }

      when I run the client program:
      java -Djava.security.auth.login.config=file:///%JBOSS_DIST%\client\auth.conf EJBTestJaas
      exception happened:
      login ok
      java.rmi.ServerException: RemoteException occurred in server thread; nested exce
      ption is:
      java.rmi.RemoteException: checkSecurityAssociation; nested exception is:

      java.lang.SecurityException: Insufficient method permissions, principal=
      scott, method=create, requiredRoles=[test], principalRoles=null

      who can give me help, and jaas drives me mad!
      thanks in advance!