From b5e969073582a7c3a5f4c3844af6aafba49af614 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Sat, 20 May 2006 18:14:05 +0000 Subject: [PATCH] Removed duplicate file. --- .../providers/ldap/LdapUtils.java | 116 ------------------ 1 file changed, 116 deletions(-) delete mode 100644 core/src/main/java/org/acegisecurity/providers/ldap/LdapUtils.java diff --git a/core/src/main/java/org/acegisecurity/providers/ldap/LdapUtils.java b/core/src/main/java/org/acegisecurity/providers/ldap/LdapUtils.java deleted file mode 100644 index 83d846af4e..0000000000 --- a/core/src/main/java/org/acegisecurity/providers/ldap/LdapUtils.java +++ /dev/null @@ -1,116 +0,0 @@ -/* Copyright 2004, 2005 Acegi Technology Pty Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ - -package org.acegisecurity.providers.ldap; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.util.Assert; - -import javax.naming.Context; -import javax.naming.NamingException; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; - -/** - * LDAP Utility methods. - * - * @author Luke Taylor - * @version $Id$ - */ -public class LdapUtils { - //~ Static fields/initializers ============================================= - - private static final Log logger = LogFactory.getLog(LdapUtils.class); - - //~ Methods ================================================================ - - public static void closeContext(Context ctx) { - try { - if (ctx != null) { - ctx.close(); - } - } catch (NamingException e) { - logger.error("Failed to close context.", e); - } - } - - /** - * Parses the supplied LDAP URL. - * @param url the URL (e.g. ldap://monkeymachine:11389/dc=acegisecurity,dc=org). - * @return the URI object created from the URL - * @throws IllegalArgumentException if the URL is null, empty or the URI syntax is invalid. - */ - public static URI parseLdapUrl(String url) { - Assert.hasLength(url); - - try { - return new URI(url); - } catch (URISyntaxException e) { - IllegalArgumentException iae = new IllegalArgumentException("Unable to parse url: " + url); - iae.initCause(e); - throw iae; - } - } - - public static byte[] getUtf8Bytes(String s) { - try { - return s.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - // Should be impossible since UTF-8 is required by all implementations - throw new IllegalStateException("Failed to convert string to UTF-8 bytes. Shouldn't be possible"); - } - } - - public static String escapeNameForFilter(String name) { - // TODO: Implement escaping as defined in RFC 2254 - // Think this is probably not needed as filter args should be escaped automatically - // by the search methods. - - return name; - } - - /** - * Obtains the part of a DN relative to a supplied base context. - *

- * If the DN is "cn=bob,ou=people,dc=acegisecurity,dc=org" and the base context - * name is "ou=people,dc=acegisecurity,dc=org" it would return "cn=bob". - *

- * - * @param fullDn the DN - * @param baseCtx the context to work out the name relative to. - * @return the - * @throws NamingException any exceptions thrown by the context are propagated. - */ - public static String getRelativeName(String fullDn, Context baseCtx) throws NamingException { - String baseDn = baseCtx.getNameInNamespace(); - - if (baseDn.length() == 0) { - return fullDn; - } - - if (baseDn.equals(fullDn)) { - return ""; - } - - int index = fullDn.lastIndexOf(baseDn); - - Assert.isTrue(index > 0, "Context base DN is not contained in the full DN"); - - // remove the base name and preceding comma. - return fullDn.substring(0, index - 1); - } -}