I use usually a simpler approach:
public static InitialContext getInitialContext(...)
| throws NamingException
| {
| String trailer = ("http".equals(proto) || "https".equals(proto))
| ? "/invoker/JNDIFactory"
| : null;
| URI uri = null;
| try {
| uri = new URI(proto, null, host, port, trailer, null,
null);
| } catch (Exception e) {
| log.warn(e.getLocalizedMessage());
| if (log.isDebugEnabled()) {
| log.debug("getPreferredContextValues", e);
| }
| }
| if (uri == null) {
| throw new IllegalArgumentException("invalid values");
| }
| String url = uri.getScheme() + "://" + uri.getHost() + ":" +
uri.getPort();
| if (uri.getPath() != null && uri.getPath().length() > 0) {
| url += uri.getPath();
| }
| String factory = "org.jnp.interfaces.NamingContextFactory";
| if ("http".equals(uri.getScheme()) ||
"https".equals(uri.getScheme())) {
| factory = "org.jboss.naming.HttpNamingContextFactory";
| }
| Properties props = new Properties();
| // java.naming.factory.initial
| props.put(Context.INITIAL_CONTEXT_FACTORY, factory);
| // java.naming.factory.url.pkgs
| props.put(Context.URL_PKG_PREFIXES,
| "org.jboss.naming:org.jnp.interfaces");
| // java.naming.provider.url
| props.put(Context.PROVIDER_URL, url);
| // jnp.disableDiscovery
| props.put(JNP_DISCOVERY,
|
!Misc.differentStrings(System.getProperty(JNP_DISCOVERY), "true"));
| return new InitialContext(props);
| }
| ...
| // login
| SecurityAssociation.setPrincipal(new SimplePrincipal(name));
| SecurityAssociation.setCredential(password);
| InitialContext ctx = getInitialContext(...);
| ...
| // logout
| SecurityAssociation.clear();
|
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3903275#3903275
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3903275
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user