Example usage for javax.naming Context getNameInNamespace

List of usage examples for javax.naming Context getNameInNamespace

Introduction

In this page you can find the example usage for javax.naming Context getNameInNamespace.

Prototype

public String getNameInNamespace() throws NamingException;

Source Link

Document

Retrieves the full name of this context within its own namespace.

Usage

From source file:org.springframework.security.ldap.LdapUtils.java

/**
 * Obtains the part of a DN relative to a supplied base context.
 * <p>// www. ja v  a2 s . com
 * If the DN is "cn=bob,ou=people,dc=springframework,dc=org" and the base context name
 * is "ou=people,dc=springframework,dc=org" it would return "cn=bob".
 * </p>
 *
 * @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;
    }

    DistinguishedName base = new DistinguishedName(baseDn);
    DistinguishedName full = new DistinguishedName(fullDn);

    if (base.equals(full)) {
        return "";
    }

    Assert.isTrue(full.startsWith(base), "Full DN does not start with base DN");

    full.removeFirst(base);

    return full.toString();
}

From source file:org.springframework.security.ldap.LdapUtils.java

/**
 * Gets the full dn of a name by prepending the name of the context it is relative to.
 * If the name already contains the base name, it is returned unaltered.
 *//*from   w  w  w .  j a v  a 2  s.  c o m*/
public static DistinguishedName getFullDn(DistinguishedName dn, Context baseCtx) throws NamingException {
    DistinguishedName baseDn = new DistinguishedName(baseCtx.getNameInNamespace());

    if (dn.contains(baseDn)) {
        return dn;
    }

    baseDn.append(dn);

    return baseDn;
}

From source file:org.squale.jraf.bootstrap.naming.NamingHelper.java

/**
 * Cree un contexte initial/*  w w  w  . j  a  v a  2  s . c o  m*/
 * @param jndiUrl url de l'annuaire
 * @param jndiClass classe d'acces
 * @return contexte initial
 * @throws JrafConfigException
 */
public static Context getInitialContext(String jndiUrl, String jndiClass) throws JrafConfigException {

    Hashtable hash = getJndiProperties(jndiUrl, jndiClass);

    if (log.isDebugEnabled()) {
        log.debug("JNDI InitialContext properties:" + hash.size());
    }
    Context lc_context = null;
    try {
        if (hash.size() == 0) {
            lc_context = new InitialContext();
            if (log.isDebugEnabled()) {
                try {
                    log.debug("New initial context" + lc_context.getNameInNamespace());
                } catch (NoInitialContextException exc) {
                    log.debug("No initial context...");
                }
            }
        } else {
            lc_context = new InitialContext(hash);
            if (log.isDebugEnabled()) {
                log.debug("new Initial context:" + lc_context.getNameInNamespace() + " " + hash.size());
            }
        }
        return lc_context;
    } catch (NamingException e) {
        log.error("Impossible de recuperer le contexte JNDI : ", e);
        throw new JrafConfigException("Impossible de recuperer le contexte JNDI : ", e);
    }
}