[JNDI/Naming/Network] - JNDI lookup for failed!
by rajeshhanu
Hi Guys,
When i run the application, i got the following error.
Exception in thread "main" com.lsyas.acs.common.exception.SystemException: JNDI lookup for FluegeManager failed!
at com.lsyas.acs.advanced.handling.db.JndiAccess.lookup(JndiAccess.java:148)
at com.lsyas.acs.advanced.handling.db.JndiAccess.lookup(JndiAccess.java:124)
at com.lsyas.acs.advanced.handling.db.RemoteLocator.getRemoteInstance(RemoteLocator.java:106)
at com.lsyas.acs.advanced.handling.db.TestMain.testdatamethod(TestMain.java:27)
at com.lsyas.acs.advanced.handling.db.TestMain.main(TestMain.java:34)
Caused by: javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:8080 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:8080 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:8080 [Root exception is java.net.ConnectException: Connection refused: connect]]]
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1562)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:634)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.lsyas.acs.advanced.handling.db.JndiAccess.lookup(JndiAccess.java:146)
... 4 more
Caused by: javax.naming.CommunicationException: Failed to connect to server localhost:8080 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:8080 [Root exception is java.net.ConnectException: Connection refused: connect]]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:274)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1533)
... 8 more
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost:8080 [Root exception is java.net.ConnectException: Connection refused: connect]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:248)
... 9 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.(Unknown Source)
at java.net.Socket.(Unknown Source)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:84)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:77)
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:244)
... 9 more
I am using JBoss-4.2.3.GA
The following files are used to get the JNDI context.
TestMain.java
------------------
public class TestMain {
private FluegeManager manager = null;
/**
* @param args
*/
public void testdatamethod() {
RemoteLocator remoteLocator = new RemoteLocator("org.jnp.interfaces.NamingContextFactory",
"jnp://localhost:8080",
"org.jboss.naming:org.jnp.interfaces");
manager = remoteLocator.getRemoteInstance(FluegeManager.class);
List fluegedata = manager.getAll();
System.out.println("Data Size is "+ fluegedata.size());
}
public static void main(String[] args) {
TestMain testMain = new TestMain();
testMain.testdatamethod();
}
}
RemoteLocater.java
---------------------------
public class RemoteLocator {
private JndiAccess jndiAccess;
public RemoteLocator() {
jndiAccess = new JndiAccess();
}
public RemoteLocator(String initialContextFactory, String providerUrl, String urlPkgPrefixes) {
jndiAccess = new JndiAccess(initialContextFactory, providerUrl, urlPkgPrefixes);
}
@SuppressWarnings({"MissingClassJavaDoc"})
public T getRemoteInstance(Class remoteInterface) {
return jndiAccess.lookup(remoteInterface.getSimpleName(), remoteInterface);
}
}
JndiAccess.java
---------------------
public class JndiAccess {
private String initialContextFactory;
private String providerUrl;
private String urlPkgPrefixes;
private InitialContext initialContext = null;
public JndiAccess() {
initialContextFactory = null;
providerUrl = null;
urlPkgPrefixes = null;
}
public JndiAccess(String initialContextFactory, String providerUrl, String urlPkgPrefixes) {
this.initialContextFactory = initialContextFactory;
this.providerUrl = providerUrl;
this.urlPkgPrefixes = urlPkgPrefixes;
}
private Object lookup(String dataJndiName) {
try {
if (initialContext == null) {
if (initialContextFactory != null || providerUrl != null || urlPkgPrefixes != null) {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
env.put(Context.PROVIDER_URL, providerUrl);
env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
initialContext = new InitialContext(env);
} else {
initialContext = new InitialContext();
}
}
return initialContext.lookup(dataJndiName);
} catch (NamingException e) {
throw new SystemException("JNDI lookup for " + dataJndiName + " failed!", e);
}
}
}
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4228482#4228482
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4228482
16 years, 11 months
[Security & JAAS/JBoss] - Force web request/user through JAAS login (bug in cache time
by andrewe
There is a little back story in this old post, but here is the gist.
We have a web application that uses PKI certs to control user access. Typically, we use custom JSTL libs to verify the user has the proper roles to access the requested .jsp. However, this forces us to include authentication/authorization code into every page, which isn't the best solution.
Instead, we'd like to handle this in the application server (JBoss 4.2.2 in our case). We already use a security domain for EJBs and we'd like to extend this to the web tier.
My attempt at doing this (see old post) had a few problems, but that was mostly just developer error. However, since then, I had problems forcing the users request to authenticate via the JAAS process on each web request.
For example, a user would go to http://jboss/secure/secure.jsp, and his certificate would be passed to my custom login module via HTTP header and the user would be authenticate. However, if the user then requested http://jboss/secure2.jsp, the custom login module would not be accessed. This seemed to be because JBoss caches login credentials.
That page recommends setting the default cache timeout to 0, in order to force authentication/authorization each time. While this does work for the web requests, it breaks our EJBs. If, for example, a servlet makes a single call to an EJB and then exits, it works fine. If we make a call to two EJBs, then it fails.
It is possible that this is a bug in the JAAS code within JBoss (I can't seem to find the URLs/JIRA issue that relate at this time), but my bigger question is whether this is the best way to force each web request through an authentication and authorization process? For each request, we need to verify the user has the proper roles? Is this the best way to do it? Or is there any approach I should use?
Thanks...
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4228435#4228435
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4228435
16 years, 11 months