[JBoss Portal] - Custom JAAS login module
by cgrahl
Hello,
I'm new to JBoss Portal, and i'm need to authenticate using my own user database. For testing purposes, i made a very simple Jaas login module. It so simple that it not even authenticates! :-) The login() method always returns true.
I'm using it just to learn what configuration must be done on the portal to use it.
Here is my code:
| public class TestLoginModule implements LoginModule {
|
| private Subject subject;
|
| private CallbackHandler callbackHandler;
|
| private Map sharedState;
|
| private Map options;
|
| private String username = null;
|
| private boolean loginOk = false;
|
| private SimplePrincipal usernamePrincipal;
|
| private Object password;
|
| public boolean abort() throws LoginException {
| // TODO Auto-generated method stub
| return false;
| }
|
| public boolean commit() throws LoginException {
| System.out.println("commit()");
| if (!loginOk)
| return false;
|
| usernamePrincipal = new SimplePrincipal(username);
| password = new String("idontusethis");
|
| subject.getPrincipals().add(usernamePrincipal);
| subject.getPublicCredentials().add(password);
|
| this.username = null;
| return true;
| }
|
| public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) {
| System.out.println("initialize(). CallbackHandler: " + callbackHandler.toString());
| this.subject = subject;
| this.callbackHandler = callbackHandler;
| this.sharedState = sharedState;
| this.options = options;
| }
|
| public boolean login() throws LoginException {
| System.out.println("login()");
| NameCallback namecallback = new NameCallback("Enter username");
| PasswordCallback passwordcallback = new PasswordCallback("Enter password", false);
|
| try {
| callbackHandler.handle(new Callback[] { namecallback, passwordcallback });
|
| username = namecallback.getName();
| password = new String(passwordcallback.getPassword());
|
| System.out.println("TODO\t" + this.getClass().getName() + ": Call Authentication Code.");
| System.out.println("Username: " + username + " password: " + password);
|
| loginOk = true;
| return true;
| } catch (UnsupportedCallbackException e) {
| } catch (java.io.IOException e) {
| } finally {
| }
|
| return false;
| }
|
| public boolean logout() throws LoginException {
| // TODO Auto-generated method stub
| return false;
| }
|
| }
|
I changed the login-config.xml as follows:
<login-module code="com.senior.security.jaas.TestLoginModule" flag="required">
| <module-option name="unauthenticatedIdentity">guest</module-option>
| <module-option name="userModuleJNDIName">java:/portal/UserModule</module-option>
| <module-option name="roleModuleJNDIName">java:/portal/RoleModule</module-option>
| <module-option name="userProfileModuleJNDIName">java:/portal/UserProfileModule</module-option>
| <module-option name="membershipModuleJNDIName">java:/portal/MembershipModule</module-option>
| <module-option name="additionalRole">Authenticated</module-option>
| <module-option name="password-stacking">useFirstPass</module-option>
| </login-module>
|
When i try to login, using admin/admin or user/user, the console shows the corret username/password pair. But the browser shows the "HTTP Status 403 - Access to the requested resource has been denied" error page.
I press the "back" button on the browser, and the user shows logged in (on the upper right corner of the screen). But I can't go to my dashboard.
Did I miss some configuration step?
What I must do to configure my own login module?
Thank you
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4085539#4085539
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4085539
18 years, 10 months
[JBoss Seam] - MDBs are devils advocat... JMS, Transactions and SMPC
by gbc@gmx.de
Hi all,
i'm very frustrated by Seam MDBs right now, here's my situation:
Having a MDB (on Queue) as Seam Component with an @In Stateless SessionBean. It gets called and executes a method within the SLSB.
My problem is: I need a new transaction at SLSB so the MDB shall mark the processed EntityBean on any error after Transaction is rolled back.
>From here my nightmare started:
#1 I tryied using:
| @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
|
on SLSBs method and let MDB onMessage unchanged
--> doesn't work
#2 Using
| @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
|
on both SLSB and MDBs onMessage:
--> doesn't work
#3 Using
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
|
on MDBs onMessage and REQUIRES_NEW at SLSB
--> doesn't work
I'm always getting following exception AFTER the MDBs onMessage has finished:
| 15:55:16,921 WARN [Component] Exception calling component @Destroy method: entityManager
| java.lang.IllegalStateException: attempting to destroy the persistence context while an active transaction exists (try installing <transaction:ejb-transaction/>)
| at org.jboss.seam.persistence.ManagedPersistenceContext.close(ManagedPersistenceContext.java:216)
| at org.jboss.seam.persistence.ManagedPersistenceContext.destroy(ManagedPersistenceContext.java:179)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
| at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
| at org.jboss.seam.Component.callComponentMethod(Component.java:2083)
| at org.jboss.seam.Component.callDestroyMethod(Component.java:2014)
| at org.jboss.seam.Component.destroy(Component.java:1332)
| at org.jboss.seam.contexts.Contexts.destroy(Contexts.java:251)
| at org.jboss.seam.contexts.Contexts.flushAndDestroyContexts(Contexts.java:363)
| at org.jboss.seam.contexts.Lifecycle.endCall(Lifecycle.java:92)
| at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:120)
| at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
| at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
| at org.jboss.aspects.tx.TxInterceptor$RequiresNew.invoke(TxInterceptor.java:262)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:245)
| at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
| at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
| at $Proxy142.onMessage(Unknown Source)
| at org.jboss.resource.adapter.jms.inflow.JmsServerSession.onMessage(JmsServerSession.java:178)
| at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:891)
| at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:170)
| at org.jboss.mq.SpySession.run(SpySession.java:323)
| at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:237)
| at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
| at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
| at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
| at java.lang.Thread.run(Thread.java:595)
|
So I installed everything in components.xml:
| <core:init debug="@debug@" jndi-pattern="@jndiPattern@" transaction-management-enabled="true"/>
|
| <core:transactionListener />
|
| <transaction:ejb-transaction />
|
Still same. So I tracked down problem to ManagedPersistenceContext:
| private void close()
| {
| boolean transactionActive = false;
| try
| {
| transactionActive = Transaction.instance().isActive();
| }
| catch(SystemException se)
| {
| log.debug("could not get transaction status while destroying persistence context");
| }
| if(transactionActive)
| throw new IllegalStateException("attempting to destroy the persistence context while an active transaction exists (try installing <transaction:ejb-transaction/>)");
| if(log.isDebugEnabled())
| log.debug((new StringBuilder()).append("destroying seam managed persistence context for persistence unit: ").append(persistenceUnitJndiName).toString());
| if(entityManager != null)
| entityManager.close();
| }
|
|
Then I discoverd the only way it works:
| @TransactionAttribute(TransactionAttributeType.NEVER)
|
at MDBs onMessage
BUT: This doesn't give me the chance to mark the entity without calling an other method annotated with REQUIRES_NEW
After testing, searching forum and web I've come to this by now:
JMS starts a transaction for the MDBs because if you want to publish to an other Queue, JMS must be sure your changes are commited before another message is been invoked.
When the SLSB is been destroyed, the EntityManager looks in Transaction.instance().isActive() and finds the open JMS Transaction so it refuses to destroy itself although its own transaction has been commited a while ago and is no more existing.
Is this a specified behavior?
Can I get around calling a second method to mark my EntityBean?
Or is this a bug? (I'll open JIRA then)
Thank you very much,
Greetz GHad
PS: Code is very basic and doesn't do any special, SLSB just gets an EntityBean by id, updates a field and returns. MDBs onMessage does nothing more than calling the SLSB.
Realted problem IMHO:
http://jboss.com/index.html?module=bb&op=viewtopic&t=117173
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4085531#4085531
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4085531
18 years, 10 months