[JCA/JBoss] - one data source with multiple database users
by diemon
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
| <datasources>
| <local-tx-datasource>
| <jndi-name>myDatasource</jndi-name>
| <connection-url>jdbc:oracle:thin:@server:1521:db</connection-url>
| <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
| <security-domain>MyRealm</security-domain>
| </local-tx-datasource>
| </datasources>
|
and added to login-config.xml:
| <authentication>
| <login-module code = "my.login.module.MyLoginModule" flag = "required">
| <module-option name="sysUserName">user</module-option>
| <module-option name="sysPassword">pass</module-option>
| <module-option name="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=myDatasource</module-option>
| </login-module>
| </authentication>
|
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() {
| if (sysMode) {
| userName = sysUserName;
| password = sysPassword;
| } else {
| String[] ss = Identity.instance().getUsername().split(" ");
| String s = ss[0].substring(0, 1).toLowerCase();
| s += ss[1].toLowerCase();
| userName = s;
| password = s;
| }
| }
| }
|
The problem is that when I try to switch user with:
| org.jboss.seam.security.Identity.instance().setUsername("User Name");
| SkorLoginModule.setSysMode(false);
| try {
| LoginContext loginContext = new LoginContext("MyRealm");
| loginContext.login();
| } catch (LoginException e) {
| System.out.println("error");
| }
|
|
there aren't created any sub-pools for every user. There is one physical db connection. When I try to flush cache from JaasSecurityManager, the connection i reseted and previously logged in user is disconnected.
Another question is: when should I invoke loginContext.login() because now it's invoked in a stateless bean which authenticate method is configured in seam's compoments.xml file as:
| <security:identity authenticate-method="#{authenticator.authenticate}"
| security-rules="#{securityRules}"/>
|
I think the authenticate method should be invoked somewhere else - in authenticator bean the entity manager is already injected by @PersistenceContext annotation.
Thanks in advance for any help.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4151703#4151703
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4151703
18 years, 1 month
[JBoss jBPM] - problem persisting jBPM process instance
by alex_enache
Hi guys,
I have a problem persisting a process instance using hibernate. Here is the scenario:
- I had a project based on jBPM, created on seam 4.0; when persisting a process instance there were no problems
- in the meantime I changed the project structure to work on seam 4.2; and now I get error when persisting the process instance; below is the error:
12:35:10,017 ERROR [STDERR] org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="ro.fii.projectmanager.model.Flow"/>
| at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1600)
| ...
and here is the code that is used to persist the process instance:
JbpmConfiguration jbpmConfig = null;
| JbpmContext jbpmContext = null;
| try {
| jbpmConfig = JbpmConfiguration.getInstance();
| jbpmContext = jbpmConfig.createJbpmContext();
| ProcessDefinition pd = ProcessDefinition.parseXmlString(
| "<process-definition name=\"pd-name\">" +
| " <start-state>" +
| " <transition to='s' />" +
| " </start-state>" +
| " <state name='s'>" +
| " <transition to='end' />" +
| " </state>" +
| " <end-state name='end' />" +
| "</process-definition>");
| ProcessInstance processInstance = new ProcessInstance(pd);
| jbpmContext.save(processInstance);
| }
| catch(Exception e) {
| e.printStackTrace();
| }
| finally {
| if (jbpmContext!=null) {
| jbpmContext.close();
| }
| }
Even stranger is that when I comment my classes from hibernate.cfg.xml and then try to persist again the process definition I don't get any errors, but the first time it wants to persist the process instance, all the classes from hibernate.cfg.xml are re-mapped and then the process instance is saved.
I don't know exactly what to ask from you. If anyone has any suggestion they are more than welcomed. Thanks!
Alex
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4151700#4151700
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4151700
18 years, 1 month
[Security & JAAS/JBoss] - Re: Authentication policies conflict
by tremalnaik
Sure, the jboss-web.xml security configuration for the application WAR is:
<security-domain flushOnSessionInvalidation="true">java:/jaas/bitastarRealm</security-domain>
|
the the jboss-web.xml security configuration for the WAR of the web services is:
<security-domain>java:/jaas/bitastarRealm_noDisable</security-domain>
|
and the application jboss.xml conf is
<jboss>
| <enterprise-beans>
| <session>
| <ejb-name>StarAccess</ejb-name>
| <jndi-name>StarAccess</jndi-name>
| </session>
| <session>
| <ejb-name>StarClientData</ejb-name>
| <jndi-name>StarClientData</jndi-name>
| <configuration-name>Secured Stateless SessionBean</configuration-name>
| </session>
| <session>
| <ejb-name>StarUserAdmin</ejb-name>
| <jndi-name>StarUserAdmin</jndi-name>
| <configuration-name>Secured Stateless SessionBean</configuration-name>
| </session>
| </enterprise-beans>
| <container-configurations>
| <container-configuration extends="Standard Stateless SessionBean">
| <container-name>Secured Stateless SessionBean</container-name>
| <security-domain>java:/jaas/bitastarRealm</security-domain>
| </container-configuration>
| </container-configurations>
| </jboss>
|
|
The clients are authenticated by means of a EJB: the application Login Module invokes a method on the unsecured StarAccess (see above).
So, when the web services client accesses the main application web tier, the first time it is authenticated using the correct security domain (bitastarRealm_noDisable). But then, when the main application accesses the business tier cached domain informations, it uses the security domain configured in its own jboss.xml for the EJBs (bitastarRealm).
That is the problem, isn't it? Can you suggest any method to circumvent this? At the moment, as I told you, I simply disabled the caching (DefaultCacheTimeout set to 0), but this is not very satisfactory.
Thank you very much
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4151695#4151695
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4151695
18 years, 1 month
[Persistence, JBoss/CMP, Hibernate, Database] - Same data souce multiple database
by unnis
How can I connect to multiple databases using same datasource.
My requirement is ,
Based on the user profile I need to connect multiple databases. All of my databases will reside in same mysql server and is having same structure.I can't use multiple datasource and multiple connection pool, since the number of databses is more. So my plan is to have a single datasource and swich the database using setCatalog() jdbc method.
My application does the data source lookup in the following ways
1) Direct JNDI lookup in EJB
2) Using Hibernate
3) Using KODO-JDO
In all the above cases I am using same JNDI name ( mySqlDS) .
How can I achive this ???
I feel that database switching has to be done before giving the connection to the client ( EJB/Hibernate/jdo) . So this has to be done at DataSource level so that ds.getConnection() should return the proper connection with proper catalog set.
If I am using CustomDataSource , Inside CustomDataSource is there a way to access values from EJbContext ???
Thanks & Regards
unnis
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4151693#4151693
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4151693
18 years, 1 month
[Tomcat, HTTPD, Servlets & JSP] - Re: Problem in starting jboss
by narendrakchoudhary
this is under bin directory
-rwxr-xr-x 1 gpmstesting gpmstesting 3539 Dec 1 2003 classpath.sh
-rwxr-xr-x 1 gpmstesting gpmstesting 1669 Dec 1 2003 deployer.bat
-rwxr-xr-x 1 gpmstesting gpmstesting 2649 Dec 1 2003 deployer.sh
-rwxr-xr-x 1 gpmstesting gpmstesting 2463 Dec 1 2003 jboss_init_redhat.sh
-rw-r--r-- 1 root root 27297 Jan 2 12:10 log
-rwxr-xr-x 1 gpmstesting gpmstesting 2826 Dec 1 2003 run.bat
-rwxr-xr-x 1 gpmstesting gpmstesting 1421 Dec 1 2003 run.conf
-rwxr-xr-x 1 gpmstesting gpmstesting 30186 Dec 1 2003 run.jar
-rwxr-xr-x 1 gpmstesting gpmstesting 2341071 Dec 1 2003 run.log
-rwxr-xr-x 1 gpmstesting gpmstesting 4866 Feb 27 10:12 run.sh
-rwxr-xr-x 1 gpmstesting gpmstesting 1795 Dec 1 2003 shutdown.bat
-rwxr-xr-x 1 gpmstesting gpmstesting 16879 Dec 1 2003 shutdown.jar
-rwxr-xr-x 1 gpmstesting gpmstesting 1829 Dec 1 2003 shutdown.sh
-rwxr-xr-x 1 gpmstesting gpmstesting 1515 Dec 1 2003 twiddle.bat
-rwxr-xr-x 1 gpmstesting gpmstesting 31140 Dec 1 2003 twiddle.jar
-rwxr-xr-x 1 gpmstesting gpmstesting 1850 Dec 1 2003 twiddle.sh
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4151691#4151691
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4151691
18 years, 1 month