[jboss-user] [Security & JAAS/JBoss] - Re: Can't get access right from Java Client
jmcollin92
do-not-reply at jboss.com
Sat Sep 23 11:27:57 EDT 2006
Really, really thank's for your help.
I've tried your piece of code (and I've already tired some similarly code) without success.
Here is my code :
static class AppCallbackHandler implements CallbackHandler
| {
| private String username;
| private String password;
|
| public AppCallbackHandler(String username, String 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.toCharArray());
| }
| else
| {
| throw new UnsupportedCallbackException(callbacks, "Unrecognized Callback");
| }
| }
| }
| }
|
| @SuppressWarnings("unchecked")
| @Before
| public void setUp() throws Exception {
| log.info("Appel setUp");
| System.setProperty("java.security.auth.login.config", "E:/jmc/projets/CPI/workspace/CPITests/bin/auth.conf");
|
| try
| {
| AppCallbackHandler handler = new AppCallbackHandler("root", "root");
| LoginContext lc = new LoginContext("CPIProject", handler);
| System.out.println("Created LoginContext");
| lc.login();
| Subject s = lc.getSubject();
| for (Principal p : s.getPrincipals()) {
| log.debug("Principal dans Subjet :"+p.getName());
| }
| }
| catch (LoginException le)
| {
| System.out.println("Login failed");
| le.printStackTrace();
| }
|
| Context ctx = new InitialContext();
| Object lookupObj = ctx.lookup(ServiceCollaborateurHome.JNDI_NAME);
| log.info("Recherche de la home");
| ServiceCollaborateurHome home = (ServiceCollaborateurHome) PortableRemoteObject.narrow(lookupObj, ServiceCollaborateurHome.class);
The error is always the same (server side) :
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
| java.rmi.AccessException: SecurityException; nested exception is:
| javax.security.auth.login.FailedLoginException: No matching username found in Principals
| at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:325)
| at sun.rmi.transport.Transport$1.run(Transport.java:153)
| at java.security.AccessController.doPrivileged(Native Method)
| at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
| at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
| at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
| at java.lang.Thread.run(Thread.java:595)
| at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
| at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
| at sun.rmi.server.UnicastRef.invoke(Unknown Source)
| at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
| at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:118)
| at org.jboss.invocation.InvokerInterceptor.invokeInvoker(InvokerInterceptor.java:163)
| at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:103)
| at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
| at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:55)
| at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:169)
| at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:91)
| at $Proxy0.create(Unknown Source)
| at jmcnet.cpi.tests.TestGererCollaborateur.setUp(TestGererCollaborateur.java:119)
| at junit.framework.TestCase.runBare(TestCase.java:128)
| at junit.framework.TestResult$1.protect(TestResult.java:110)
| at junit.framework.TestResult.runProtected(TestResult.java:128)
| at junit.framework.TestResult.run(TestResult.java:113)
| at junit.framework.TestCase.run(TestCase.java:120)
| at junit.framework.TestSuite.runTest(TestSuite.java:228)
| at junit.framework.TestSuite.run(TestSuite.java:223)
| at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
| at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
| at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
| at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
| Caused by: java.rmi.AccessException: SecurityException; nested exception is:
| javax.security.auth.login.FailedLoginException: No matching username found in Principals
| at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:388)
| at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:136)
| at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:107)
| at org.jboss.ejb.SessionContainer.internalInvokeHome(SessionContainer.java:637)
| at org.jboss.ejb.Container.invoke(Container.java:975)
| at sun.reflect.GeneratedMethodAccessor123.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
| at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:819)
| at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:420)
| at sun.reflect.GeneratedMethodAccessor125.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
| at sun.rmi.transport.Transport$1.run(Transport.java:153)
| at java.security.AccessController.doPrivileged(Native Method)
| at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
| at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
| at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
| at java.lang.Thread.run(Thread.java:595)
| Caused by: javax.security.auth.login.FailedLoginException: No matching username found in Principals
| at org.jboss.security.auth.spi.DatabaseServerLoginModule.getUsersPassword(DatabaseServerLoginModule.java:152)
| at org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(UsernamePasswordLoginModule.java:206)
| at sun.reflect.GeneratedMethodAccessor138.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at javax.security.auth.login.LoginContext.invoke(LoginContext.java:769)
| at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186)
| at javax.security.auth.login.LoginContext$4.run(LoginContext.java:683)
| at java.security.AccessController.doPrivileged(Native Method)
| at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
| at javax.security.auth.login.LoginContext.login(LoginContext.java:579)
| at org.jboss.security.plugins.JaasSecurityManager.defaultLogin(JaasSecurityManager.java:601)
| at org.jboss.security.plugins.JaasSecurityManager.authenticate(JaasSecurityManager.java:535)
| at org.jboss.security.plugins.JaasSecurityManager.isValid(JaasSecurityManager.java:344)
| at org.jboss.ejb.plugins.SecurityInterceptor.checkSecurityAssociation(SecurityInterceptor.java:211)
| at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:135)
| at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:132)
| ... 23 more
I've tried something : giving a wrong name to the security module (given to the LoginContext constructor) makes the test pass !
I've got a login exception but I can call my EJB and it's works !
Have you an idea of what happens ?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3973708#3973708
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3973708
More information about the jboss-user
mailing list