Hello, I'm trying to connect to JNDI over HTTP. Right now I'm on the local lan
and actually the same host that is running jboss. My test case works fine if I
use the standard JNDI InitialContext for JBoss.
I wrote a relatively simple test case as follows:
| /**
| *
| */
| package com.foo.webservice.client;
|
| import java.io.IOException;
| import java.rmi.RMISecurityManager;
| import java.util.Hashtable;
|
| import javax.naming.Context;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
| import javax.security.auth.Subject;
| import javax.security.auth.callback.Callback;
| import javax.security.auth.callback.CallbackHandler;
| import javax.security.auth.callback.NameCallback;
| import javax.security.auth.callback.PasswordCallback;
| import javax.security.auth.callback.UnsupportedCallbackException;
| import javax.security.auth.login.LoginContext;
| import javax.security.auth.login.LoginException;
|
| import com.foo.web.services.db.*;
| /**
| * @author pmadden
| *
| */
| public class DBServiceTest
| {
| LoginContext loginContext;
|
| public DBServiceTest()
| {
|
| }
|
| private class ClientCallbackHandler implements CallbackHandler
| {
| String user;
| String pass;
| public ClientCallbackHandler(String user, String pass)
| {
| this.user = user;
| this.pass = pass;
| }
|
| /*
| * (non-Javadoc)
| * @see
javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.callback.Callback[])
| */
| public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException
| {
| int len = callbacks.length;
| Callback cb;
|
| for (int i = 0; i < len; i++)
| {
| cb = callbacks;
|
| if (cb instanceof NameCallback)
| {
| ((NameCallback) cb).setName(this.user);
| }
| else if (cb instanceof PasswordCallback)
| {
| ((PasswordCallback)
cb).setPassword(this.pass.toCharArray());
| }
| else
| {
| throw new UnsupportedCallbackException(cb, "Don't know
what to do with this!");
| }
| }
| }
| }
|
| protected Subject login(String user, String pass) throws LoginException
| {
| // reads the jaas.config file - looks for clooster setting.
| loginContext = new LoginContext("clooster",
| new ClientCallbackHandler(user, pass));
|
| loginContext.login();
|
| return loginContext.getSubject();
| }
|
| protected void logout() throws LoginException
| {
| if (this.loginContext != null)
| {
| this.loginContext.logout();
| }
| }
|
| public void testDBService() throws Exception
| {
| if (System.getSecurityManager() == null)
| System.setSecurityManager(new RMISecurityManager());
|
| InitialContext initContext = this.getInitialContext();
| EJB3RemoteDBService dbService = (EJB3RemoteDBService)
initContext.lookup("ejb3/EJB3DBService");
| }
|
| @SuppressWarnings("unchecked")
| protected InitialContext getInitialContext() throws NamingException
| {
| Hashtable<String, String> env = new Hashtable<String, String>();
|
| env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.HttpNamingContextFactory");
| env.put(Context.PROVIDER_URL,
"http://10.10.10.6:8080/invoker/JNDIFactory");
| env.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
|
| InitialContext initContext = new InitialContext(env);
|
| env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
| env.put("j2ee.clientName", "jbossws-client");
| return initContext;
| }
|
| public static void main(String[] args)
| {
| DBServiceTest test = new DBServiceTest();
|
| try
| {
| Subject subject = test.login("foo","bar");
|
| if (subject != null)
| {
| System.out.println(subject.toString());
|
| test.testDBService();
| }
| }
| catch (Exception e)
| {
| e.printStackTrace(System.err);
| }
| finally
| {
| try
| {
| test.logout();
| }
| catch (LoginException e)
| {
| e.printStackTrace(System.err);
| }
| }
| }
| }
|
I can actually get the LoginContext to login. It fails trying to create the
InitialContext with the following output:
| Subject:
| Principal: foo
|
| javax.naming.NamingException: Failed to retrieve Naming interface [Root
exception is java.io.IOException: Server returned HTTP response code: 403 for
URL: http://10.10.10.6:8080/invoker/JNDIFactory]
| at
org.jboss.naming.HttpNamingContextFactory.getInitialContext(HttpNamingContextFactory.java:84)
| at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
| at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
| at javax.naming.InitialContext.init(Unknown Source)
| at javax.naming.InitialContext.<init>(Unknown Source)
| at
com.clooster.webservice.client.DBServiceTest.getInitialContext(DBServiceTest.java:112)
| at
com.clooster.webservice.client.DBServiceTest.testDBService(DBServiceTest.java:99)
| at
com.clooster.webservice.client.DBServiceTest.main(DBServiceTest.java:131)
| Caused by: java.io.IOException: Server returned HTTP response code: 403 for
URL: http://10.10.10.6:8080/invoker/JNDIFactory
| at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
| at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
| at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
| at java.lang.reflect.Constructor.newInstance(Unknown Source)
| at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
| at java.security.AccessController.doPrivileged(Native Method)
| at
sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
| at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
Source)
| at
org.jboss.naming.HttpNamingContextFactory.getNamingServer(HttpNamingContextFactory.java:133)
| at
org.jboss.naming.HttpNamingContextFactory.getInitialContext(HttpNamingContextFactory.java:80)
| ... 7 more
| Caused by: java.io.IOException: Server returned HTTP response code: 403 for
URL: http://10.10.10.6:8080/invoker/JNDIFactory
| at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
Source)
| at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown
Source)
| at java.net.URLConnection.getHeaderFieldInt(Unknown Source)
| at java.net.URLConnection.getContentLength(Unknown Source)
| at
org.jboss.naming.HttpNamingContextFactory.getNamingServer(HttpNamingContextFactory.java:128)
| ... 8 more
|
I'm running on standard port 8080. I added the username and password to both
users.properties and conf\props\jmx-console-users.properties.
Any help would be greatly appreciated.
Thanks,
PVM
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4004358#4004358
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4004358
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user