Author: ptillemans
Date: 2006-09-26 06:57:14-0700
New Revision: 10304
Added:
trunk/src/java/org/tigris/scarab/services/security/ldap/
trunk/src/java/org/tigris/scarab/services/security/ldap/DummyCallbackHandler.java
trunk/src/java/org/tigris/scarab/services/security/ldap/LDAPSynchronizer.java
trunk/src/java/org/tigris/scarab/services/security/ldap/LDAPUserInfoCallback.java
trunk/src/java/org/tigris/scarab/services/security/ldap/LdapLoginModule.java
trunk/src/test/org/tigris/scarab/services/security/
trunk/src/test/org/tigris/scarab/services/security/ldap/
trunk/src/test/org/tigris/scarab/services/security/ldap/LDAPIteratorTest.java
trunk/src/test/org/tigris/scarab/services/security/ldap/MockInitialContextFactory.java
trunk/src/test/org/tigris/scarab/services/security/ldap/MockJndiContext.java
Log:
SCB499: LDAP Integration
Added: trunk/src/java/org/tigris/scarab/services/security/ldap/DummyCallbackHandler.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/services/security/ldap/DummyCallbackHandler.java?view=auto&rev=10304
==============================================================================
--- (empty file)
+++ trunk/src/java/org/tigris/scarab/services/security/ldap/DummyCallbackHandler.java 2006-09-26 06:57:14-0700
@@ -0,0 +1,101 @@
+package org.tigris.scarab.services.security.ldap;
+/* ====================================================================
+*
+* Copyright (c) 2006 CollabNet.
+*
+* Licensed under the
+*
+* CollabNet/Tigris.org Apache-style license (the "License");
+*
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://scarab.tigris.org/LICENSE
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+* implied. See the License for the specific language governing
+* permissions and limitations under the License.
+* ====================================================================
+*
+* This software consists of voluntary contributions made by many
+* individuals on behalf of CollabNet.
+*
+* Copyright (C) 2004 Core Software Foundation
+*
+*/
+import java.io.IOException;
+
+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;
+
+
+public class DummyCallbackHandler implements CallbackHandler {
+ private String username;
+ private LDAPUserInfoCallback ldapUserInfo;
+
+ char[] password;
+
+ public DummyCallbackHandler() {
+ };
+
+ /**
+ * <p>
+ * Creates a callback handler with the give username and password.
+ */
+ public DummyCallbackHandler(String user, String pass) {
+ this.username = user;
+ this.password = pass.toCharArray();
+ }
+
+ public void setUsername(String user) {
+ this.username = user;
+ }
+
+ public void setPassword(String pass) {
+ this.password = pass.toCharArray();
+ }
+
+
+
+ /**
+ * @return Returns the ldapUserInfo.
+ */
+ public LDAPUserInfoCallback getLdapUserInfo() {
+ return ldapUserInfo;
+ }
+
+
+
+ public void handle(Callback[] callbacks) throws IOException,
+ UnsupportedCallbackException {
+ for (int i = 0; i < callbacks.length; i++) {
+ if (callbacks[i] instanceof NameCallback) {
+ ((NameCallback) callbacks[i]).setName(username);
+ } else if (callbacks[i] instanceof PasswordCallback) {
+ ((PasswordCallback) callbacks[i]).setPassword(password);
+ } else if (callbacks[i] instanceof LDAPUserInfoCallback) {
+ ldapUserInfo = (LDAPUserInfoCallback) callbacks[i];
+ } else {
+ throw new UnsupportedCallbackException(callbacks[i],
+ "Callback class not supported");
+ }
+ }
+ }
+
+ /**
+ * Clears out password state.
+ */
+ public void clearPassword() {
+ if (password != null) {
+ for (int i = 0; i < password.length; i++)
+ password[i] = ' ';
+ password = null;
+ }
+ }
+
+}
Added: trunk/src/java/org/tigris/scarab/services/security/ldap/LDAPSynchronizer.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/services/security/ldap/LDAPSynchronizer.java?view=auto&rev=10304
==============================================================================
--- (empty file)
+++ trunk/src/java/org/tigris/scarab/services/security/ldap/LDAPSynchronizer.java 2006-09-26 06:57:14-0700
@@ -0,0 +1,171 @@
+
+package org.tigris.scarab.services.security.ldap;
+/* ====================================================================
+*
+* Copyright (c) 2006 CollabNet.
+*
+* Licensed under the
+*
+* CollabNet/Tigris.org Apache-style license (the "License");
+*
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://scarab.tigris.org/LICENSE
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+* implied. See the License for the specific language governing
+* permissions and limitations under the License.
+* ====================================================================
+*
+* This software consists of voluntary contributions made by many
+* individuals on behalf of CollabNet.
+*
+*/
+
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.security.auth.login.LoginException;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.fulcrum.security.TurbineSecurity;
+import org.apache.fulcrum.security.impl.db.entity.TurbineUser;
+import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
+import org.apache.turbine.Turbine;
+import org.tigris.scarab.om.ScarabUser;
+import org.tigris.scarab.om.ScarabUserImplPeer;
+import org.tigris.scarab.om.ScarabUserManager;
+import org.tigris.scarab.services.security.ScarabDBSecurityService;
+import org.tigris.scarab.util.PasswordGenerator;
+
+/**
+ * Iterate over the query result set of an LDAP query for users
+ *
+ * @author pti
+ *
+ */
+public class LDAPSynchronizer {
+ static Category logger = Logger.getInstance(LDAPSynchronizer.class);
+
+ private String baseDn;
+
+ private String providerFactory;
+
+ private String providerUrl;
+
+ private String query;
+
+ private String loginAttribute;
+
+ public LDAPSynchronizer(Configuration cfg) throws NamingException {
+ this.baseDn = cfg.getString("baseDN", "");
+ this.baseDn = cfg.getString("baseDN", "");
+ this.baseDn = cfg.getString("baseDN", "");
+ providerFactory = cfg.getString(providerFactory,
+ "com.sun.jndi.ldap.LdapCtxFactory");
+ providerUrl = cfg.getString("providerUrl", "ldap://localhost/");
+ baseDn = cfg.getString("baseDN", "");
+ query = cfg.getString("query", "objectClass=inetOrgPerson");
+ loginAttribute = cfg.getString("loginAttribute", "uid");
+ }
+
+ /**
+ * Synchronize a user from an LDAP repository with the database. Create new
+ * ScarabUsers for people found in LDAP, but not in Scarab.
+ *
+ * TODO: remove/disable ScarabUsers not found in LDAP
+ *
+ * @param sr
+ * A search result returned from the JNDI query;
+ * @throws Exception
+ */
+ public void synchUser(SearchResult sr) throws Exception {
+ Attributes attributes = null;
+ ScarabUser user = null;
+
+ attributes = sr.getAttributes();
+ String uid = (String) attributes.get(loginAttribute).get(0);
+ logger.info("uid : " + uid);
+ user = ScarabUserManager.getInstance(uid);
+
+ // if the user does not exist yet, create a new one
+ if (user == null) {
+ user = ScarabUserManager.getInstance();
+ user.setName(uid);
+
+ // Generate random password to avoid security hole.
+ // This will be reset when the user logs in the first time
+ user.setPassword(PasswordGenerator.generate());
+ user.createNewUser();
+ }
+
+ user.setConfirmed("CONFIRMED");
+ user.setEmail(getAttributeValue(attributes.get("mail"), "Unknown"));
+ user.setLastName(getAttributeValue(attributes.get("sn"), "Unknown"));
+ user.setFirstName(getAttributeValue(attributes.get("givenName"),
+ "Unknown"));
+
+ TurbineSecurity.saveUser(user);
+
+ }
+
+ /**
+ * @param attrib
+ * Attribute to get the value from
+ * @param deflt
+ * Default string returned when attrib is null.
+ * @throws NamingException
+ */
+ private String getAttributeValue(Attribute attrib, String deflt)
+ throws NamingException {
+ String result = deflt;
+ if (attrib != null) {
+ result = (String) attrib.get(0);
+ }
+ return result;
+ }
+
+ /**
+ * Do a subtree search to get all accounts and synch them one by one.
+ *
+ * @throws NamingException
+ */
+ public void synchronize() throws NamingException {
+ InitialDirContext ctx;
+ NamingEnumeration results;
+
+ Hashtable props = new Hashtable();
+ props.put(Context.INITIAL_CONTEXT_FACTORY, providerFactory);
+ props.put(Context.PROVIDER_URL, providerUrl);
+ ctx = new InitialDirContext(props);
+
+ SearchControls cons = new SearchControls();
+ cons.setSearchScope(SearchControls.SUBTREE_SCOPE);
+ results = ctx.search(baseDn, query, null, cons);
+
+ while (results.hasMore()) {
+ try {
+ synchUser((SearchResult) results.next());
+ } catch (NamingException e) {
+ logger.error("NamingException caught: ", e);
+ } catch (Exception e) {
+ logger.error("Exception caught: ", e);
+ }
+ }
+
+ }
+
+}
Added: trunk/src/java/org/tigris/scarab/services/security/ldap/LDAPUserInfoCallback.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/services/security/ldap/LDAPUserInfoCallback.java?view=auto&rev=10304
==============================================================================
--- (empty file)
+++ trunk/src/java/org/tigris/scarab/services/security/ldap/LDAPUserInfoCallback.java 2006-09-26 06:57:14-0700
@@ -0,0 +1,74 @@
+package org.tigris.scarab.services.security.ldap;
+/* ====================================================================
+*
+* Copyright (c) 2006 CollabNet.
+*
+* Licensed under the
+*
+* CollabNet/Tigris.org Apache-style license (the "License");
+*
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://scarab.tigris.org/LICENSE
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+* implied. See the License for the specific language governing
+* permissions and limitations under the License.
+* ====================================================================
+*
+* This software consists of voluntary contributions made by many
+* individuals on behalf of CollabNet.
+*
+*/
+
+import javax.security.auth.callback.Callback;
+
+public class LDAPUserInfoCallback implements Callback {
+
+ private String sn;
+ private String givenname;
+ private String email;
+
+ /**
+ * @return Returns the email.
+ */
+ public String getEmail() {
+ return email;
+ }
+ /**
+ * @return Returns the givenname.
+ */
+ public String getGivenname() {
+ return givenname;
+ }
+ /**
+ * @return Returns the sn.
+ */
+ public String getSn() {
+ return sn;
+ }
+ /**
+ * @param email The email to set.
+ */
+ public void setEmail(String email) {
+ this.email = email;
+ }
+ /**
+ * @param givenname The givenname to set.
+ */
+ public void setGivenname(String givenname) {
+ this.givenname = givenname;
+ }
+ /**
+ * @param sn The sn to set.
+ */
+ public void setSn(String sn) {
+ this.sn = sn;
+ }
+
+
+
+}
Added: trunk/src/java/org/tigris/scarab/services/security/ldap/LdapLoginModule.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/services/security/ldap/LdapLoginModule.java?view=auto&rev=10304
==============================================================================
--- (empty file)
+++ trunk/src/java/org/tigris/scarab/services/security/ldap/LdapLoginModule.java 2006-09-26 06:57:14-0700
@@ -0,0 +1,148 @@
+package org.tigris.scarab.services.security.ldap;
+/* ====================================================================
+*
+* Copyright (c) 2006 CollabNet.
+*
+* Licensed under the
+*
+* CollabNet/Tigris.org Apache-style license (the "License");
+*
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://scarab.tigris.org/LICENSE
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+* implied. See the License for the specific language governing
+* permissions and limitations under the License.
+* ====================================================================
+*
+* This software consists of voluntary contributions made by many
+* individuals on behalf of CollabNet.
+*
+* Copyright (C) 2004 Core Software Foundation
+*
+*/
+import java.io.IOException;
+import java.security.Principal;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+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.LoginException;
+import javax.security.auth.spi.LoginModule;
+
+
+public class LdapLoginModule implements LoginModule {
+ public static final String HOST_KEY = "host";
+ public static final String USERNAME_KEY = "usernamefield";
+ public static final String BASEDN_KEY = "basedn";
+
+ private Subject subject;
+ private CallbackHandler callbackHandler;
+ private Map sharedState;
+ Properties options = new Properties();
+ private String cbName;
+ private String cbPassword;
+ private boolean verification = false;
+ private Hashtable props;
+ private DirContext ctx;
+
+ public void initialize(Subject subject,
+ CallbackHandler callbackHandler, Map sharedState, Map options) {
+ this.callbackHandler = callbackHandler;
+ this.sharedState = sharedState;
+ this.options.putAll(options);
+ }
+
+ public boolean abort() throws LoginException {
+ return true;
+ }
+
+ public boolean commit() throws LoginException {
+ return true;
+ }
+
+ public boolean login() throws LoginException {
+ Callback[] calls = new Callback[3];
+ LDAPUserInfoCallback ldapUserInfo = new LDAPUserInfoCallback();
+ calls[0] = new NameCallback("name");
+ calls[1] = new PasswordCallback("Password", false);
+ calls[2] = ldapUserInfo;
+
+ if (callbackHandler == null)
+ throw new LoginException("callback is null");
+
+ try {
+ callbackHandler.handle(calls);
+ } catch (IOException e) {
+ throw new LoginException(e.toString());
+ } catch (UnsupportedCallbackException e) {
+ throw new LoginException(
+ e.toString()
+ + "callbackHandler does not support name or password callback");
+ }
+
+ cbName = ((NameCallback) calls[0]).getName();
+ if (cbName.equals(null))
+ throw new LoginException("name must not be null");
+
+ cbPassword = String.valueOf(((PasswordCallback) (calls[1])).getPassword());
+ if (cbPassword.equals(null))
+ throw new LoginException("password must not be null");
+
+ try {
+ props = new Hashtable();
+ props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
+ props.put(Context.PROVIDER_URL, options.get(HOST_KEY));
+ ctx = new InitialDirContext(props);
+ SearchControls cons = new SearchControls();
+ cons.setSearchScope(SearchControls.SUBTREE_SCOPE);
+ NamingEnumeration results = ctx.search((String)options.get(BASEDN_KEY),"uid={0}",new Object[] { cbName },cons);
+ Attributes attributes = null;
+ String principal = null;
+ while (results.hasMore()){
+ SearchResult sr = (SearchResult)results.next();
+ attributes = sr.getAttributes();
+ principal = sr.getName() + "," + options.get(BASEDN_KEY);
+ }
+ if ( attributes == null || principal == null){
+ throw new LoginException("No User Found");
+ }
+ ctx.close();
+ props.put(Context.SECURITY_PRINCIPAL, principal);
+ props.put(Context.SECURITY_CREDENTIALS, cbPassword);
+ props.put(Context.SECURITY_AUTHENTICATION, "simple");
+ ctx = new InitialDirContext(props);
+ verification = true;
+ ldapUserInfo.setEmail(attributes.get("mail").get().toString());
+ ldapUserInfo.setGivenname(attributes.get("givenname").get().toString());
+ ldapUserInfo.setSn(attributes.get("sn").get().toString());
+ ctx.close();
+ } catch (NamingException e) {
+ throw new LoginException(e.toString() + " " + e.getRootCause());
+ }
+
+ return verification;
+ }
+
+ public boolean logout() throws LoginException {
+ return true;
+ }
+}
Added: trunk/src/test/org/tigris/scarab/services/security/ldap/LDAPIteratorTest.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/test/org/tigris/scarab/services/security/ldap/LDAPIteratorTest.java?view=auto&rev=10304
==============================================================================
--- (empty file)
+++ trunk/src/test/org/tigris/scarab/services/security/ldap/LDAPIteratorTest.java 2006-09-26 06:57:14-0700
@@ -0,0 +1,94 @@
+/**
+ *
+ */
+package org.tigris.scarab.services.security.ldap;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.SearchResult;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.fulcrum.security.TurbineSecurity;
+import org.apache.fulcrum.security.entity.User;
+import org.tigris.scarab.om.ScarabUser;
+import org.tigris.scarab.test.BaseScarabTestCase;
+
+import junit.framework.TestCase;
+
+/**
+ * @author pti
+ *
+ */
+public class LDAPIteratorTest extends BaseScarabTestCase {
+
+ private LDAPSynchronizer syncer;
+ private LDAPSynchronizer emptySyncer;
+
+ final static String TESTUSER = "u001";
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ Configuration config = new PropertiesConfiguration();
+ config.setProperty("providerFactory", "com.sun.jndi.ldap.LdapCtxFactory");
+ config.setProperty("providerURL", "ldap://localhost/");
+ config.setProperty("baseDN", "dc=crowsnest,dc=be");
+ config.setProperty("loginAttribute", "uid");
+
+ config.setProperty("query", "objectClass=person");
+ syncer = new LDAPSynchronizer(config);
+
+ if (TurbineSecurity.accountExists(TESTUSER)) {
+ TurbineSecurity.removeUser(TurbineSecurity.getUser(TESTUSER));
+ }
+
+ }
+
+ /**
+ * Test the update from LDAP to scarab user
+ *
+ * @throws Exception
+ */
+ public void testSyncer() throws Exception {
+ SearchResult sr;
+ Attributes attribs;
+ User user;
+
+ attribs = new BasicAttributes();
+ attribs.put("uid",TESTUSER);
+ attribs.put("sn","Testeur");
+ attribs.put("givenName","Ted");
+ attribs.put("mail","[email protected]");
+
+ sr = new SearchResult("dn=testuser,dc=testeur,dc=org",null,attribs);
+ syncer.synchUser(sr);
+
+ // test creation of new account
+ user = TurbineSecurity.getUser(TESTUSER);
+ assertNotNull(user);
+ assertEquals("[email protected]",user.getEmail());
+ assertEquals("Ted",user.getFirstName());
+ assertEquals("Testeur",user.getLastName());
+
+ attribs.put("givenName","Tom");
+ attribs.put("mail","[email protected]");
+
+ // test update of existing account
+ sr = new SearchResult("dn=testuser,dc=testeur,dc=org",null,attribs);
+ syncer.synchUser(sr);
+ user = TurbineSecurity.getUser(TESTUSER);
+ assertEquals("[email protected]",user.getEmail());
+ assertEquals("Tom",user.getFirstName());
+
+ }
+
+}
Added: trunk/src/test/org/tigris/scarab/services/security/ldap/MockInitialContextFactory.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/test/org/tigris/scarab/services/security/ldap/MockInitialContextFactory.java?view=auto&rev=10304
==============================================================================
--- (empty file)
+++ trunk/src/test/org/tigris/scarab/services/security/ldap/MockInitialContextFactory.java 2006-09-26 06:57:14-0700
@@ -0,0 +1,25 @@
+/**
+ *
+ */
+package org.tigris.scarab.services.security.ldap;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+/**
+ * @author pti
+ *
+ */
+public class MockInitialContextFactory implements InitialContextFactory {
+
+ /* (non-Javadoc)
+ * @see javax.naming.spi.InitialContextFactory#getInitialContext(java.util.Hashtable)
+ */
+ public Context getInitialContext(Hashtable arg0) throws NamingException {
+ return new MockJndiContext();
+ }
+
+}
Added: trunk/src/test/org/tigris/scarab/services/security/ldap/MockJndiContext.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/test/org/tigris/scarab/services/security/ldap/MockJndiContext.java?view=auto&rev=10304
==============================================================================
--- (empty file)
+++ trunk/src/test/org/tigris/scarab/services/security/ldap/MockJndiContext.java 2006-09-26 06:57:14-0700
@@ -0,0 +1,182 @@
+package org.tigris.scarab.services.security.ldap;
+
+import org.apache.log4j.Logger;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.InitialContextFactoryBuilder;
+import javax.naming.spi.NamingManager;
+
+public class MockJndiContext implements Context {
+ /**
+ * Logger for this class
+ */
+private static final Logger logger = Logger.getLogger(MockJndiContext.class);
+
+ static HashMap map = new HashMap();
+
+ static public void clear() {
+ map.clear();
+ }
+
+ public MockJndiContext() throws NamingException {
+ super();
+ }
+
+ public Object lookup(Name name) throws NamingException {
+ return lookup(name.toString());
+ }
+
+ public Object lookup(String name) throws NamingException {
+ Object o = map.get(name);
+ if (o == null) {
+ throw new NamingException("Name " + name
+ + " not found in MockJndiContext");
+ }
+ return o;
+ }
+
+ public void bind(Name name, Object obj) throws NamingException {
+ bind(name.toString(), obj);
+ }
+
+ public void bind(String name, Object obj) throws NamingException {
+ map.put(name, obj);
+ }
+
+ public void rebind(Name name, Object obj) throws NamingException {
+ rebind(name.toString(), obj);
+ }
+
+ public void rebind(String name, Object obj) throws NamingException {
+ map.put(name, obj);
+ }
+
+ public void unbind(Name name) throws NamingException {
+ unbind(name.toString());
+ }
+
+ public void unbind(String name) throws NamingException {
+ map.remove(name);
+ }
+
+ public void rename(Name oldName, Name newName) throws NamingException {
+ rename(oldName.toString(), newName.toString());
+ }
+
+ public void rename(String oldName, String newName) throws NamingException {
+ bind(newName, lookup(oldName));
+ unbind(oldName);
+ }
+
+ public NamingEnumeration list(Name name) throws NamingException {
+ return null;
+ }
+
+ public NamingEnumeration list(String name) throws NamingException {
+ return null;
+ }
+
+ public NamingEnumeration listBindings(Name name) throws NamingException {
+ return null;
+ }
+
+ public NamingEnumeration listBindings(String name) throws NamingException {
+ return null;
+ }
+
+ public void destroySubcontext(Name name) throws NamingException {
+
+ }
+
+ public void destroySubcontext(String name) throws NamingException {
+
+ }
+
+ public Context createSubcontext(Name name) throws NamingException {
+ return null;
+ }
+
+ public Context createSubcontext(String name) throws NamingException {
+ return null;
+ }
+
+ public Object lookupLink(Name name) throws NamingException {
+ return null;
+ }
+
+ public Object lookupLink(String name) throws NamingException {
+ return null;
+ }
+
+ public NameParser getNameParser(Name name) throws NamingException {
+ return null;
+ }
+
+ public NameParser getNameParser(String name) throws NamingException {
+ return null;
+ }
+
+ public Name composeName(Name name, Name prefix) throws NamingException {
+ return null;
+ }
+
+ public String composeName(String name, String prefix)
+ throws NamingException {
+ return null;
+ }
+
+ public Object addToEnvironment(String propName, Object propVal)
+ throws NamingException {
+ return null;
+ }
+
+ public Object removeFromEnvironment(String propName) throws NamingException {
+ return null;
+ }
+
+ public Hashtable getEnvironment() throws NamingException {
+ return null;
+ }
+
+ public void close() throws NamingException {
+
+ }
+
+ public String getNameInNamespace() throws NamingException {
+ return null;
+ }
+
+// static {
+// System.getProperties().setProperty("java.naming.factory.initial",
+// "com.melexis.viiper.shopfloor.ejb.MockJndiContext");
+//
+// try {
+// if (!NamingManager.hasInitialContextFactoryBuilder()) {
+// NamingManager
+// .setInitialContextFactoryBuilder(new InitialContextFactoryBuilder() {
+//
+// public InitialContextFactory createInitialContextFactory(
+// Hashtable environment)
+// throws NamingException {
+// return new MockJndiContext();
+// }
+// });
+// }
+// } catch (IllegalStateException e) {
+// logger.error("Illegal State Exception", e);
+// } catch (NamingException e) {
+// logger.error("NamingException", e);
+// }
+// }
+
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.