I have been working on this problem for a week.
You can try this class. I am still working out a few bugs but this seems to be working. I'll keep this topic posted with updates as I go...
Steve
| package org.jboss.portal.core.security.jaas;
|
| import java.util.HashSet;
| import java.util.Map;
| import java.util.Set;
|
| import javax.naming.InitialContext;
|
| import org.jboss.portal.identity.NoSuchUserException;
| import org.jboss.portal.identity.UserModule;
| import org.jboss.portal.identity.RoleModule;
| import org.jboss.portal.identity.User;
| import org.jboss.portal.identity.Role;
|
| import javax.security.auth.Subject;
| import javax.security.auth.callback.CallbackHandler;
| import javax.transaction.TransactionManager;
| import org.jboss.portal.common.transaction.Transactions;
|
| public class ExtModelLoginModule extends org.jboss.portal.identity.auth.IdentityLoginModule {
|
| protected String emailSuffix;
|
| public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options)
| {
| super.initialize(subject, callbackHandler, sharedState, options);
|
| emailSuffix = (String)options.get("emailSuffix");
| if (emailSuffix == null)
| emailSuffix = "";
|
| log.trace("emailSuffix = " + emailSuffix);
| }
|
| protected boolean validatePassword(String arg0, String arg1) {
| Boolean ok = Boolean.FALSE;
| try
| {
| TransactionManager tm = (TransactionManager)new InitialContext().lookup("java:/TransactionManager");
| ok = (Boolean) Transactions.required(tm, new Transactions.Runnable()
| {
| public Object run() throws Exception
| {
| try
| {
| UserModule userMod = getUserModule();
| userMod.findUserByUserName(getUsername());
| return Boolean.TRUE;
| }
| catch (NoSuchUserException e)
| {
| log.trace("NoSuchUser exception, trying to create user");
| RoleModule roleMod = getRoleModule();
| User newuser = getUserModule().createUser(getUsername(),"NONE",getUsername()+ emailSuffix);
| Role userRole = roleMod.findRoleByName("User");
| Set userRoleSet = java.util.Collections.synchronizedSet(new HashSet());
| userRoleSet.add(userRole);
| roleMod.setRoles(newuser, userRoleSet);
| return Boolean.TRUE;
| }
| }
| });
|
| } catch (Exception e1) {
| log.error("Error logging in user.", e1);
| ok = Boolean.FALSE;
| }
|
| return ok.booleanValue();
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3953504#3953504
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3953504
|