HibernateLoginModule login on JBoss Portal
ollihak Mar 22, 2005 5:42 AMHi,
I'm using JBoss 4.0.0 and the new AOP feature for integration puposes.
Anyway, what I want to do is to perform a login to JBoss Portal programatically in an aspect.
What I found out, is that JBoss Portal uses an JAAS LoginModule, called HibernateLoginModule. It's methods login() and commit() are called from JBoss' class HibernateContext (at least I think so).
Now I tried in my aspect to do the same things that must happen in HibernateContext to perform the login like this
HashMap sharedState = new HashMap(); sharedState.put("javax.security.auth.login.name", portalUserName); sharedState.put("javax.security.auth.login.password", Tools.md5AsHexString(portalPass)); HashMap options = new HashMap(); options.put("password-stacking", "useFirstPass"); options.put("unauthenticatedIdentity", "guest"); options.put("hashAlgorithm", "MD5"); options.put("hasEncoding", "HEX"); options.put("factoryJNDIName", "java:/portal/SessionFactory"); options.put("principalsQuery", "SELECT u.password FROM UserImpl AS u WHERE u.userName=:username"); options.put("rolesQuery", "SELECT g.name FROM UserImpl AS u LEFT JOIN u.roles AS g WHERE u.userName=:username"); options.put("additionalRole", "Authenticated"); HibernateLoginModule hlm = new HibernateLoginModule(); hlm.initialize(new Subject(), null, sharedState, options); boolean log = hlm.login(); System.out.println("Login-result is: " + log); hlm.commit();
When I execute the code, the last line throws the following exception:
23:17:33,682 INFO [STDOUT] javax.security.auth.login.LoginException:
javax.tran
saction.NotSupportedException: Transaction already active, cannot nest
transacti
ons.
23:17:33,698 INFO [STDOUT] at
org.jboss.portal.core.security.jaas.Hibernate
LoginModule.getRoleSets(HibernateLoginModule.java:196)
23:17:33,698 INFO [STDOUT] at
org.jboss.security.auth.spi.AbstractServerLog
inModule.commit(AbstractServerLoginModule.java:187)
23:17:33,698 INFO [STDOUT] at
integrate.IntegratingLoginAspect.invoke(Integ
ratingLoginAspect.java:150)
23:17:33,698 INFO [STDOUT] at
rmibean.ConnectHyperdocBean_login_N3488153054
972647034_OptimizedMethodInvocation.invokeNext(ConnectHyperdocBean_login_N348815
3054972647034_OptimizedMethodInvocation.java)
23:17:33,698 INFO [STDOUT] at
rmibean.ConnectHyperdocBean.login(ConnectHype
rdocBean.java)
23:17:33,698 INFO [STDOUT] at
sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
23:17:33,698 INFO [STDOUT] at
sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
23:17:33,698 INFO [STDOUT] at
sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
23:17:33,698 INFO [STDOUT] at
java.lang.reflect.Method.invoke(Method.java:5
85)
23:17:33,698 INFO [STDOUT] at
org.jboss.invocation.Invocation.performCall(I
nvocation.java:345)
23:17:33,698 INFO [STDOUT] at
org.jboss.ejb.StatelessSessionContainer$Conta
inerInterceptor.invoke(StatelessSessionContainer.java:214)
23:17:33,698 INFO [STDOUT] at
org.jboss.resource.connectionmanager.CachedCo
nnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
23:17:33,698 INFO [STDOUT] at
org.jboss.ejb.plugins.StatelessSessionInstanc
eInterceptor.invoke(StatelessSessionInstanceInterceptor.java:113)
23:17:33,698 INFO [STDOUT] at
org.jboss.webservice.server.ServiceEndpointIn
terceptor.invoke(ServiceEndpointInterceptor.java:51)
23:17:33,698 INFO [STDOUT] at
org.jboss.ejb.plugins.CallValidationIntercept
or.invoke(CallValidationInterceptor.java:48)
23:17:33,698 INFO [STDOUT] at
org.jboss.ejb.plugins.AbstractTxInterceptor.i
nvokeNext(AbstractTxInterceptor.java:105)
23:17:33,698 INFO [STDOUT] at
org.jboss.ejb.plugins.TxInterceptorCMT.runWit
hTransactions(TxInterceptorCMT.java:316)
23:17:33,698 INFO [STDOUT] at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke
(TxInterceptorCMT.java:149)
23:17:33,698 INFO [STDOUT] at
org.jboss.ejb.plugins.SecurityInterceptor.inv
oke(SecurityInterceptor.java:128)
23:17:33,698 INFO [STDOUT] at
org.jboss.ejb.plugins.LogInterceptor.invoke(L
ogInterceptor.java:191)
23:17:33,698 INFO [STDOUT] at
org.jboss.ejb.plugins.ProxyFactoryFinderInter
ceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
23:17:33,698 INFO [STDOUT] at
org.jboss.ejb.SessionContainer.internalInvoke
(SessionContainer.java:624)
23:17:33,698 INFO [STDOUT] at
org.jboss.ejb.Container.invoke(Container.java
:854)
23:17:33,698 INFO [STDOUT] at
sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
23:17:33,698 INFO [STDOUT] at
sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
23:17:33,698 INFO [STDOUT] at
sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
23:17:33,698 INFO [STDOUT] at
java.lang.reflect.Method.invoke(Method.java:5
85)
23:17:33,698 INFO [STDOUT] at
org.jboss.mx.interceptor.ReflectedDispatcher.
invoke(ReflectedDispatcher.java:141)
23:17:33,698 INFO [STDOUT] at
org.jboss.mx.server.Invocation.dispatch(Invoc
ation.java:80)
23:17:33,698 INFO [STDOUT] at
org.jboss.mx.server.Invocation.invoke(Invocat
ion.java:72)
23:17:33,698 INFO [STDOUT] at
org.jboss.mx.server.AbstractMBeanInvoker.invo
ke(AbstractMBeanInvoker.java:242)
23:17:33,698 INFO [STDOUT] at
org.jboss.mx.server.MBeanServerImpl.invoke(MB
eanServerImpl.java:642)
23:17:33,698 INFO [STDOUT] at
org.jboss.invocation.jrmp.server.JRMPInvoker$
MBeanServerAction.invoke(JRMPInvoker.java:775)
23:17:33,698 INFO [STDOUT] at
org.jboss.invocation.jrmp.server.JRMPInvoker.
invoke(JRMPInvoker.java:382)
23:17:33,698 INFO [STDOUT] at
sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
23:17:33,698 INFO [STDOUT] at
sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
23:17:33,698 INFO [STDOUT] at
sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
23:17:33,698 INFO [STDOUT] at
java.lang.reflect.Method.invoke(Method.java:5
85)
23:17:33,698 INFO [STDOUT] at
sun.rmi.server.UnicastServerRef.dispatch(Unic
astServerRef.java:294)
23:17:33,698 INFO [STDOUT] at
sun.rmi.transport.Transport$1.run(Transport.j
ava:153)
23:17:33,698 INFO [STDOUT] at
java.security.AccessController.doPrivileged(N
ative Method)
23:17:33,698 INFO [STDOUT] at
sun.rmi.transport.Transport.serviceCall(Trans
port.java:149)
23:17:33,698 INFO [STDOUT] at
sun.rmi.transport.tcp.TCPTransport.handleMess
ages(TCPTransport.java:460)
23:17:33,698 INFO [STDOUT] at
sun.rmi.transport.tcp.TCPTransport$Connection
Handler.run(TCPTransport.java:701)
23:17:33,698 INFO [STDOUT] at java.lang.Thread.run(Thread.java:595)
In fact I never started a transaction in my aspect by myself and I was told that each method that starts a transaction is used to commit it as well.
Can anybody tell me, what I have to do to perform the login correctly. All I need is that this commit-method will return true
Thank you
regards from Germany
OLLI