Hello
I have problem with configuring JBoss 4.2.1+Seam 2.0.1+Oracle 10 to use one
data source with multiple users. I have configured *-ds.xml file with
|
|
| myDatasource
| jdbc:oracle:thin:@server:1521:db
| oracle.jdbc.driver.OracleDriver
| MyRealm
|
|
|
and added to login-config.xml:
|
|
| user
| pass
| jboss.jca:service=LocalTxCM,name=myDatasource
|
|
|
my login module code is as follows:
| import java.security.AccessController;
| import java.security.Principal;
| import java.security.PrivilegedAction;
| import java.security.acl.Group;
| import java.util.Map;
|
| import javax.management.MBeanServer;
| import javax.management.MBeanServerFactory;
| import javax.management.MalformedObjectNameException;
| import javax.management.ObjectName;
| import javax.resource.spi.ManagedConnectionFactory;
| import javax.resource.spi.security.PasswordCredential;
| import javax.security.auth.Subject;
| import javax.security.auth.callback.CallbackHandler;
| import javax.security.auth.login.LoginException;
|
| import org.jboss.mx.util.MBeanServerLocator;
| import org.jboss.seam.security.Identity;
| import org.jboss.security.SecurityAssociation;
| import org.jboss.security.SimplePrincipal;
| import org.jboss.security.auth.spi.AbstractServerLoginModule;
|
| public class MyLoginModule extends AbstractServerLoginModule {
|
| private static final org.apache.log4j.Logger log =
org.apache.log4j.Logger
| .getLogger(my.login.module.MyLoginModule.class);
|
| /* used at jboss startup */
| private static boolean sysMode = true;
|
| private String sysUserName;
| private String sysPassword;
| private String userName;
| private String password;
|
| private MBeanServer server;
| private ObjectName managedConnectionFactoryName;
| private ManagedConnectionFactory mcf;
|
| public SkorLoginModule() {}
|
| @Override
| public void initialize(Subject subject, CallbackHandler handler, Map
sharedState, Map options) {
|
| super.initialize(subject, callbackHandler, sharedState,
options);
|
| String name = (String)
options.get("managedConnectionFactoryName");
| try {
| managedConnectionFactoryName = new ObjectName(name);
| } catch (MalformedObjectNameException mone) {
| throw new IllegalArgumentException("Malformed
ObjectName: " + name);
| }
|
| sysUserName = (String)options.get("sysUserName");
| if (sysUserName == null) {
| throw new IllegalArgumentException("Must supply a
system user name!");
| }
| userName = (String)options.get("sysUserName");
|
| sysPassword = (String)options.get("sysPassword");
| if (sysPassword == null) {
| throw new IllegalArgumentException("Must supply a
system user password!");
| }
| password = (String)options.get("sysPassword");
|
| server = MBeanServerLocator.locateJBoss();
| getMcf();
| }
|
| @Override
| public boolean login() throws LoginException {
|
| setUserNameAndPassword();
| log.info("login(): userName=" + userName + ", sysMode=" +
sysMode);
|
| Principal principal = new SimplePrincipal(userName);
|
| PasswordCredential credential = new
| PasswordCredential(userName, password.toCharArray());
| credential.setManagedConnectionFactory(getMcf());
|
| subject.getPrincipals().add(principal);
| subject.getPrivateCredentials().add(credential);
|
| super.loginOk = true;
| return true;
| }
|
| protected ManagedConnectionFactory getMcf() {
|
| if (mcf == null) {
| try {
| mcf =
(ManagedConnectionFactory)server.getAttribute(managedConnectionFactoryName,
"ManagedConnectionFactory");
| } catch (Exception e) {
| throw new IllegalArgumentException("Managed
Connection Factory not found: " + managedConnectionFactoryName);
| }
| }
| return mcf;
| }
|
| @Override
| protected Principal getIdentity() {
|
| setUserNameAndPassword();
| log.info("getIdentity(): userName=" + userName + ", sysMode=" +
sysMode);
|
| return new SimplePrincipal(userName);
| }
|
| @Override
| protected Group[] getRoleSets() throws LoginException {
| return new Group[] {};
| }
|
| private void setUserNameAndPassword() {
|