Jaas login module service [message #660200] |
Thu, 17 March 2011 06:37  |
Eclipse User |
|
|
|
Hi,
I am migrating my non-osgi project to virgo and I am having trouble using jaas authentication in virgo.
I have 2 questions regarding virgo and jaas.
a. I have my own jaas LoginModule implementation and I want virgo to authenticate the administration user that connects to Web Servers using that implementation.
I have changed the org.eclipse.virgo.kernel.authentication.config file to use my class:
virgo-kernel {
acme.security.MyLoginModule REQUIRED;
};
and exposed my class to the service registry, but how do I tell virgo to reference that service and use it for authentication ?
b. I am using the ActiveMQ bundle as my jms implementation and I want it to use my jaas login module as well but I am getting an exception saying the class cannot be found in KernelBundleClassLoader: [bundle=org.apache.activemq.activemq-core_5.4.1].
I have tried asking about this exception in the activemq forum and I was told that JAAS does not work in OSGi, and I need to use a specific integration layer in order to make that work. Does virgo have somthing like this ?
Here is the full exception stacktrace:
10:34:45.262 [ActiveMQ Transport: tcp:///127.0.0.1:51561] WARN o.a.a.broker.TransportConnection - Failed to add Connection
java.lang.SecurityException: User name or password is invalid.
at org.apache.activemq.security.JaasAuthenticationBroker.addCon nection(JaasAuthenticationBroker.java:83) ~[bundlefile:5.4.1]
at org.apache.activemq.broker.BrokerFilter.addConnection(Broker Filter.java:85) ~[bundlefile:5.4.1]
at org.apache.activemq.broker.MutableBrokerFilter.addConnection (MutableBrokerFilter.java:91) ~[bundlefile:5.4.1]
at org.apache.activemq.broker.TransportConnection.processAddCon nection(TransportConnection.java:694) [bundlefile:5.4.1]
at org.apache.activemq.broker.jmx.ManagedTransportConnection.pr ocessAddConnection(ManagedTransportConnection.java:83) [bundlefile:5.4.1]
at org.apache.activemq.command.ConnectionInfo.visit(ConnectionI nfo.java:137) [bundlefile:5.4.1]
at org.apache.activemq.broker.TransportConnection.service(Trans portConnection.java:309) [bundlefile:5.4.1]
at org.apache.activemq.broker.TransportConnection$1.onCommand(T ransportConnection.java:185) [bundlefile:5.4.1]
at org.apache.activemq.transport.TransportFilter.onCommand(Tran sportFilter.java:69) [bundlefile:5.4.1]
at org.apache.activemq.transport.WireFormatNegotiator.onCommand (WireFormatNegotiator.java:113) [bundlefile:5.4.1]
at org.apache.activemq.transport.InactivityMonitor.onCommand(In activityMonitor.java:228) [bundlefile:5.4.1]
at org.apache.activemq.transport.TransportSupport.doConsume(Tra nsportSupport.java:83) [bundlefile:5.4.1]
at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTran sport.java:219) [bundlefile:5.4.1]
at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransp ort.java:201) [bundlefile:5.4.1]
at java.lang.Thread.run(Thread.java:662) [na:1.6.0_24]
Caused by: javax.security.auth.login.LoginException: unable to find LoginModule class: acme.security.MyLoginModule in KernelBundleClassLoader: [bundle=org.apache.activemq.activemq-core_5.4.1]
at javax.security.auth.login.LoginContext.invoke(LoginContext.j ava:808) ~[na:1.6.0_24]
at javax.security.auth.login.LoginContext.access$000(LoginConte xt.java:186) ~[na:1.6.0_24]
at javax.security.auth.login.LoginContext$4.run(LoginContext.ja va:683) ~[na:1.6.0_24]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_24]
at javax.security.auth.login.LoginContext.invokePriv(LoginConte xt.java:680) ~[na:1.6.0_24]
at javax.security.auth.login.LoginContext.login(LoginContext.ja va:579) ~[na:1.6.0_24]
at org.apache.activemq.security.JaasAuthenticationBroker.addCon nection(JaasAuthenticationBroker.java:76) ~[bundlefile:5.4.1]
Thanks,
Jacob
|
|
|
|
|
|
|
|
|
|
Re: Jaas login module service [message #1698244 is a reply to message #665594] |
Fri, 12 June 2015 08:47  |
Eclipse User |
|
|
|
To work around a similar problem I:
1. Resorted to adding this entry to my OSGi bundle's /META-INF/MANIFEST.MF file
This completely corrupts the OSGi container's bundle wiring but is necessary if you want to support loading any JAAS LoginModule deployed in the OSGi container.
2. In the code where the LoginContext is constructed, I set the Thread.currentThread().setClassLoaderContext to be my bundle's classloader
ClassLoader myBundleClassloader =
Thread.currentThread().getContextClassLoader();
Class<SomeClassInMyBundle> classFromBundle =
SomeClassInMyBundle.class;
ClassLoader classloaderWithSomeClassFromBundle = classFromBundle.getClassLoader();
Thread.currentThread().setContextClassLoader(
classloaderWithSomeClassFromBundle);
final String applicationName = "myapp";
LoginContext lc;
try {
lc = new LoginContext(applicationName, subject,
jaasCallbackHandler, configuration);
} catch (LoginException e) {
LOGGER.error("LoginContext#<init> failed because LoginException,
username="+ suppliedUsername, e);
return false;
} finally {
Thread.currentThread().setContextClassLoader(myBundleClassloader);
}
try {
lc.login();
LOGGER.info("login success for username=" + suppliedUsername);
return true;
} catch (LoginException e) {
LOGGER.error("LoginContext#login failed because LoginException,
username="+ suppliedUsername, e);
return false;
}
|
|
|
Powered by
FUDForum. Page generated in 0.05566 seconds