1. Unable to locate a login configuration
If you missing the auth.conf file which holding the client side JAAS configuration, you will accepte this Exception:(Only be used to invoke Remote Interface with Security Login):
Exception in thread "main" java.lang.SecurityException: Unable to locate a login configuration at com.sun.security.auth.login.ConfigFile.<init>(ConfigFile.java:97) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at java.lang.Class.newInstance0(Class.java:350) at java.lang.Class.newInstance(Class.java:303) at javax.security.auth.login.Configuration$3.run(Configuration.java:216) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.login.Configuration.getConfiguration(Configuration.java:210) at javax.security.auth.login.LoginContext$1.run(LoginContext.java:237) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.login.LoginContext.init(LoginContext.java:234) at javax.security.auth.login.LoginContext.<init>(LoginContext.java:403) at org.jboss.security.jndi.LoginInitialContextFactory.getInitialContext(LoginInitialContextFactory.java:86) at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247) at javax.naming.InitialContext.init(InitialContext.java:223) at javax.naming.InitialContext.<init>(InitialContext.java:197) at com.staffware.frameworks.ejb.EJBCLientTest.lookupWithSequrity(EJBCLientTest.java:51) at com.staffware.frameworks.ejb.EJBCLientTest.main(EJBCLientTest.java:41) Caused by: java.io.IOException: Unable to locate a login configuration at com.sun.security.auth.login.ConfigFile.init(ConfigFile.java:206) at com.sun.security.auth.login.ConfigFile.<init>(ConfigFile.java:95) ... 20 more
Some More Detailed Analysis:
JAAS authentication is performed in a pluggable fashion, So Customer(Java App) do not need to care about underlying authentication technology, Only thing Customer did need is customize its LoginModule, So we need to define our client LoginModule, JBoss always define its LoginModule in auth.conf file which we can find from JBOSS_HOME\client folder, the content as following:
srp-client { // Example client auth.conf for using the SRPLoginModule org.jboss.security.srp.jaas.SRPLoginModule required password-stacking="useFirstPass" principalClassName="org.jboss.security.SimplePrincipal" srpServerJndiName="SRPServerInterface" debug=true ; // jBoss LoginModule org.jboss.security.ClientLoginModule required password-stacking="useFirstPass" ; // Put your login modules that need jBoss here }; other { // jBoss LoginModule org.jboss.security.ClientLoginModule required ; // Put your login modules that need jBoss here };
what the above section has said, JAAS Login Configuration File is a necessary, we must set this file to JVM, we usually use key-value pattern which the key is 'java.security.auth.login.config', just as the following solution depicted:
Available Solution:
----------------------------------------------------------------------------------------------------------------------------------
Method One:
using the following argument when starting the JVM Can made it work :
-Djava.security.auth.login.config=file:./resource/auth.conf
Note that: Under your project root folder has a resource folder, and under the resource folder the Jboss authrity file has existed.
---------------------------------------------------------------------------------------------------------------------------------
Method Two:
This solution is most used what set JVM property 'java.security.auth.login.config' while JVM is starting up, the property key is 'java.security.auth.login.config', and the key reference value is point to Client-side Configuration File Location, as below code showing:
File authFile = new File("resource/auth.conf"); System.out.println("Client-side Configuration File Location: " + authFile.getAbsolutePath()); System.setProperty("java.security.auth.login.config", "file:///" + authFile.getAbsolutePath());
==========================================================================
2. When EJB Client(J2SE environment) Look up Remote Service, throw a error:java.lang.NoSuchMethodError
Exception in thread "main" java.lang.NoSuchMethodError: org.jboss.security.SecurityAssociation.isServer()Z at org.jboss.aspects.security.SecurityActions.isServer(SecurityActions.java:490) at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:88) at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:108) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:280) at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106) at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82) at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:809) at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:572) at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373) at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166) at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:174) at org.jboss.remoting.Client.invoke(Client.java:1640) at org.jboss.remoting.Client.invoke(Client.java:554) at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:62) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:107) at $Proxy0.fetchOrder(Unknown Source) at com.staffware.frameworks.ejb.EJBCLientTest.lookupWithSequrity(EJBCLientTest.java:71) at com.staffware.frameworks.ejb.EJBCLientTest.main(EJBCLientTest.java:47)
Solution:
this error has stucked me for quite a long time, today i have found what's the fucking wrong reason, it's an jboss-eap-4.3.0.GA_CP01 bug.this version jboss has incompatibly problem. 'java.lang.NoSuchMethodError' is a very barely Error, its can only occur at run time if the definition of a class has incompatibly changed, so I use a Class Search utility found that org.jboss.security.SecurityAssociation has been loaded 3 times if you run server production, that means org.jboss.security.SecurityAssociation exists in 3 jar files(JBOSS_HOME\client\jbossall-client.jar,
JBOSS_HOME\client\jbosssx-client.jar, JBOSS_HOME\server\production\lib\jbosssx.jar), and then i use a Decompile Utility found that JBOSS_HOME\server\production\lib\jbosssx.jar's SecurityAssociation hasn't existed isServer() method, and so far this is the reason why this error has throwed.
The Repair Method:
1. update jboss version from jboss-eap-4.3.0.GA_CP01 to a newer version,(jboss-eap-4.3.0.GA_CP04 has modified this bug);
2. replace the JBOSS_HOME\server\production\lib\jbosssx.jar, use later version's jbosssx.jar replace the old version's jbosssx.jar.
==================================================================
3. InvalidClassException throwed when look up EJB
javax.naming.CommunicationException [Root exception is java.io.InvalidClassException: org.jboss.ejb3.remoting.BaseRemoteProxy; local class incompatible: stream classdesc serialVersionUID = 1126421850898582900, local class serialVersionUID = -2711693270411201590] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:780) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627) at javax.naming.InitialContext.lookup(InitialContext.java:351) at com.staffware.frameworks.order.integration.AbstractTestCase.getFacade(AbstractTestCase.java:502) at com.staffware.frameworks.order.integration.AbstractTestCase.getOrderFacade(AbstractTestCase.java:480) at com.staffware.frameworks.order.integration.AbstractTestCase.<clinit>(AbstractTestCase.java:190)
The Error Reason:
The reason of this exception been throwed is that your classpath jbossall-client.jar not match the jboss you have run.
The Solution:
Copy jbossall-client.jar from you(you want to run)$Jboss_home\client, add this client jar to your application classpath, and to do this, this exception will dispair.
4. ProfileServiceBootstrap build ManagedDeployment throw a Exception.
I try to migrate my Application From Jboss Platform 4.3 to Jboss Platform 5.1, of course, App can work well on Platform 4.3, but it crush at the beginning of Platform 5.1 starting up, the exception as following:
org.jboss.deployers.spi.DeploymentException: Error deploying: file:/C:/jboss-eap-5.1/jboss-as/server/production/conf/bootstrap/vfs.xml at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49) at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataFactoryVisitor.deploy(BeanMetaDataFactoryVisitor.java:136) at org.jboss.system.server.profileservice.ProfileServiceBootstrap.initBootstrapMDs(ProfileServiceBootstrap.java:426) at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:242) at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:461) at org.jboss.Main.boot(Main.java:221) at org.jboss.Main$1.run(Main.java:556) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.IllegalStateException: ClassLoader has not been set at org.jboss.deployers.structure.spi.helpers.AbstractDeploymentUnit.getClassLoader(AbstractDeploymentUnit.java:159) at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataFactoryVisitor.addBeanComponent(BeanMetaDataFactoryVisitor.java:60) at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataFactoryVisitor.deploy(BeanMetaDataFactoryVisitor.java:126)
The same Exception also throwed while deploying 'file:/C:/jboss-eap-5.1/jboss-as/server/production/conf/bootstrap/logging.xml', What's the real happened, I will try to give a solution from now.
5. When lookup Jboss Datasource throw a Exception
Exception in thread "main" javax.naming.NameNotFoundException: OracleDS not bound at org.jnp.server.NamingServer.getBinding(NamingServer.java:581) at org.jnp.server.NamingServer.getBinding(NamingServer.java:589) at org.jnp.server.NamingServer.getObject(NamingServer.java:595) at org.jnp.server.NamingServer.lookup(NamingServer.java:342) 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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294) at sun.rmi.transport.Transport$1.run(Transport.java:153) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:149) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707) at java.lang.Thread.run(Thread.java:595) at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source) at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source) at sun.rmi.server.UnicastRef.invoke(Unknown Source) at org.jnp.server.NamingServer_Stub.lookup(Unknown Source) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627) at javax.naming.InitialContext.lookup(Unknown Source) at datasource.DataSourceConnection.main(DataSourceConnection.java:17)
I checked in the jmx-console of my application server and OracleDS is listed under java:namespace.
The Error Solution:
Usually J2EE Server do not allow directly connection with its Resource, especially Persistence level resource, however From JBoss-4.0.0 and above, there is support for accessing a DataSource from a remote client. The one change that is necessary for the client to be able to lookup the DataSource from JNDI is to specify use-java-context=false as shown here:
<datasources> <local-tx-datasource> <jndi-name>OracleDS</jndi-name> <use-java-context>false</use-java-context> <connection-url>...</connection-url>
This results in the DataSource being bound under the JNDI name "GenericDS" instead of the default of "java:/OracleDS" which restricts the lookup to the same VM as the jboss server.
Note that:
JBoss does not recommend using this feature on a production environment. It requires accessing a connection pool remotely and this is an anti-pattern as connections are not serializable. Besides, transaction propagation is not supported and it could lead to connection leaks if the remote clients are unreliable (i.e crashes, network failure). If you do need to access a datasource remotely, JBoss recommends accessing it via a remote session bean facade.
So to solve this question we only need to add '<use-java-context>false</use-java-context>' to DataSource configure file. as long as this line here
<use-java-context>false</use-java-context>
has been added, then everthing on the right way, by the way my test code:
Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); props.put(Context.PROVIDER_URL, "192.168.1.102:1099"); Context ctx = new InitialContext(props); DataSource datasource = (DataSource) ctx.lookup("OracleDS"); Connection conn = datasource.getConnection();