Example usage for javax.naming NamingException getMessage

List of usage examples for javax.naming NamingException getMessage

Introduction

In this page you can find the example usage for javax.naming NamingException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:de.fiz.ddb.aas.utils.LDAPEngineUtilityOrganisation.java

protected Organisation convertLdapOrganizationToOrganisation(
        NamingEnumeration<SearchResult> pOrganizationResult, NamingEnumeration<SearchResult> pPrivilegesResult)
        throws ExecutionException, NameNotFoundException {
    Organisation vOrganisation = null;// w w w  .  ja  v  a  2 s  . c  om
    try {
        if ((pOrganizationResult != null) && pOrganizationResult.hasMore()) {

            SearchResult sr = pOrganizationResult.next();
            vOrganisation = convertSearchResultToOrganization(sr);
            // -- Organization privileges:
            vOrganisation = this.convertLdapGroupsToOrganizationPrivileges(vOrganisation, pPrivilegesResult);
        }
    } catch (NameNotFoundException ex) {
        LOG.log(Level.SEVERE, null, ex);
        throw ex;
    } catch (NamingException ne) {
        LOG.log(Level.SEVERE, null, ne);
        throw new ExecutionException(ne.getMessage(), ne.getCause());
    } finally {
        // -- releases this context's resources immediately, instead of waiting for the garbage collector
        if (pOrganizationResult != null) {
            try {
                pOrganizationResult.close();
            } catch (NamingException ex) {
            }
        }
    }
    return vOrganisation;
}

From source file:de.fiz.ddb.aas.utils.LDAPEngineUtilityOrganisation.java

protected Organisation convertLdapGroupsToOrganizationPrivileges(Organisation pOrg,
        NamingEnumeration<SearchResult> pPrivilegesResult) throws ExecutionException {
    try {//w  w  w.j  a v  a 2 s  .  c  o m
        if (pPrivilegesResult != null) {
            PrivilegeEnum p;
            SearchResult sr;
            String vCnPrivileg;
            // construct privileges
            while (pPrivilegesResult.hasMore()) {
                sr = pPrivilegesResult.next();
                vCnPrivileg = (String) sr.getAttributes().get(Constants.ldap_ddbPrivilege_Cn).get();
                p = this.mapToPrivilege(sr.getAttributes(), Constants.ldap_ddbPrivilege_Cn);
                if (p != null) {
                    pOrg.addPrivileges(p);
                } else {
                    LOG.log(Level.WARNING,
                            "Die Organisation ''{0}'' verfgt ber einen nicht existierende Privileg: ''{1}''!",
                            new Object[] { pOrg.getId(), vCnPrivileg });
                }
            }
            // -- releases this context's resources immediately, instead of waiting for the garbage collector
            pPrivilegesResult.close();
        }
    } catch (NamingException ne) {
        LOG.log(Level.SEVERE, null, ne);
        throw new ExecutionException(ne.getMessage(), ne.getCause());
    } finally {
        // -- releases this context's resources immediately, instead of waiting for the garbage collector
        if (pPrivilegesResult != null) {
            try {
                pPrivilegesResult.close();
            } catch (NamingException ex) {
            }
        }
    }
    return pOrg;
}

From source file:org.swordess.ldap.odm.core.SessionImpl.java

@Override
public void delete(String dn) {
    if (StringUtils.isEmpty(dn)) {
        return;/*ww  w.  jav  a  2 s  .com*/
    }

    LogUtils.debug(LOG, "delete dn=" + dn);

    try {
        ctx.unbind(dn);
        sessionCache.remove(dn);
    } catch (NameNotFoundException ignore) {
        LogUtils.debug(LOG, "Name not found: " + dn);
    } catch (NamingException e) {
        throw new SessionException(e.getMessage(), e);
    }
}

From source file:de.fiz.ddb.aas.utils.LDAPEngineUtilityOrganisation.java

public Set<OIDs> getAllSubOrgIds(boolean pLicensedOrgs, OIDs pOIDs, int pScopy, AasPrincipal pPerformer)
        throws ExecutionException {
    Set<OIDs> vSetOIDs = new HashSet<OIDs>();
    NamingEnumeration<SearchResult> searchResults = null;
    try {//from w  w  w  .  j av  a  2  s.  c  om
        searchResults = getAllSubOrgs(pLicensedOrgs, pOIDs, pScopy,
                new String[] { Constants.ldap_ddbOrg_Id, Constants.ldap_ddbOrg_PID, "+" }, pPerformer);
        SearchResult sr;
        Attribute attr;
        while (searchResults.hasMore()) {
            sr = searchResults.next();
            if ((attr = sr.getAttributes().get(Constants.ldap_ddb_EntryDN)) != null) {
                vSetOIDs.add(new OIDs(String.valueOf(attr.get()),
                        (attr = sr.getAttributes().get(Constants.ldap_ddbOrg_PID)) != null
                                ? String.valueOf(attr.get())
                                : null));
            } else {
                throw new ExecutionException("entryDN = null : OIDs = " + pOIDs, null);
            }
        }
    } catch (IllegalAccessException ex) {
        LOG.log(Level.SEVERE, "Connection-Error", ex);
        throw new ExecutionException(ex.getMessage(), ex.getCause());
    } catch (NamingException ne) {
        LOG.log(Level.SEVERE, "NamingException", ne);
        throw new ExecutionException(ne.getMessage(), ne.getCause());
    } finally {
        if (searchResults != null) {
            try {
                searchResults.close();
                searchResults = null;
            } catch (NamingException ex) {
            }
        }
    }
    return vSetOIDs;
}

From source file:org.swordess.ldap.odm.core.SessionImpl.java

@Override
public void delete(Object entity) {
    if (null == entity) {
        return;/* ww  w  .  j av  a 2s  .co m*/
    }

    if (!(entity instanceof Persistent)) {
        LogUtils.debug(LOG, entity + " is not persistent, do nothing");
        return;
    }

    String dn = DnHelper.build(entity);
    LogUtils.debug(LOG, "delete dn=" + dn);

    try {
        ctx.unbind(dn);
        sessionCache.remove(dn);
    } catch (NamingException e) {
        throw new SessionException(e.getMessage(), e);
    }
}

From source file:org.apache.naming.NamingContext.java

/**
 * Retrieves the named object./*from   ww  w.j  a v  a  2s. co m*/
 * 
 * @param name the name of the object to look up
 * @param resolveLinks If true, the links will be resolved
 * @return the object bound to name
 * @exception NamingException if a naming exception is encountered
 */
protected Object lookup(Name name, boolean resolveLinks) throws NamingException {

    // Removing empty parts
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty()) {
        // If name is empty, a newly allocated naming context is returned
        return new NamingContext(env, this.name, bindings);
    }

    NamingEntry entry = (NamingEntry) bindings.get(name.get(0));

    if (entry == null) {
        throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name.get(0)));
    }

    if (name.size() > 1) {
        // If the size of the name is greater that 1, then we go through a
        // number of subcontexts.
        if (entry.type != NamingEntry.CONTEXT) {
            throw new NamingException(sm.getString("namingContext.contextExpected"));
        }
        return ((Context) entry.value).lookup(name.getSuffix(1));
    } else {
        if ((resolveLinks) && (entry.type == NamingEntry.LINK_REF)) {
            String link = ((LinkRef) entry.value).getLinkName();
            if (link.startsWith(".")) {
                // Link relative to this context
                return lookup(link.substring(1));
            } else {
                return (new InitialContext(env)).lookup(link);
            }
        } else if (entry.type == NamingEntry.REFERENCE) {
            try {
                Object obj = NamingManager.getObjectInstance(entry.value, name, this, env);
                if (obj != null) {
                    entry.value = obj;
                    entry.type = NamingEntry.ENTRY;
                }
                return obj;
            } catch (NamingException e) {
                throw e;
            } catch (Exception e) {
                log.warn(sm.getString("namingContext.failResolvingReference"), e);
                throw new NamingException(e.getMessage());
            }
        } else {
            return entry.value;
        }
    }

}

From source file:org.swordess.ldap.odm.core.SessionImpl.java

public List<String> lookup(String context, String filter) {
    if (null == filter) {
        return null;
    }//from w  w  w  . j a  v a 2s .c o m

    LogUtils.debug(LOG, String.format("search DNs with context=%s, filter=%s", context, filter));

    SearchControls ctrl = new SearchControls();
    ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);
    ctrl.setReturningAttributes(new String[] {});

    try {
        List<String> retVal = new ArrayList<String>();
        NamingEnumeration<SearchResult> results = ctx.search(context, filter, ctrl);
        while (results.hasMore()) {
            retVal.add(results.next().getNameInNamespace());
        }
        return retVal;
    } catch (NamingException e) {
        throw new SessionException(e.getMessage(), e);
    }
}

From source file:org.swordess.ldap.odm.core.SessionImpl.java

@Override
public <T> List<T> searchIndirections(Class<T> clazz, String filter) {
    if (null == filter) {
        return null;
    }/*from w  ww  . j  a  v  a2s  .  co m*/

    LogUtils.debug(LOG, String.format("search %s with filter=%s", clazz.getName(), filter));

    OneMetaData oneMetaData = IndirectionsMetaData.get(clazz).getOne();

    SearchControls ctrl = new SearchControls();
    ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);
    ctrl.setReturningAttributes(new String[] { oneMetaData.getIdAttr(), oneMetaData.getIndirectionAttr() });

    try {
        List<T> retVal = new ArrayList<T>();
        NamingEnumeration<SearchResult> results = ctx.search(oneMetaData.getContext(), filter, ctrl);
        while (results.hasMore()) {
            SearchResult result = results.next();
            retVal.add(fromAttributesToIndirections(clazz, result.getAttributes()));
        }
        return retVal;
    } catch (NamingException e) {
        throw new SessionException(e.getMessage(), e);
    }
}

From source file:de.fiz.ddb.aas.utils.LDAPEngineUtilityOrganisation.java

public NamingEnumeration<SearchResult> getAllSubOrgs(boolean pLicensedOrgs, OIDs pOIDs, int pScopy,
        String[] attributeFilter, AasPrincipal pPerformer) throws ExecutionException {
    if (pPerformer == null) {
        throw new IllegalArgumentException("The contractor is unknown: Performer == null");
    }//from ww w . j a  va  2  s.c  o m
    if (attributeFilter == null) {
        attributeFilter = new String[] { "*", "+" };
    }

    String orgRdn = pOIDs.getOrgRDN();
    if (StringUtils.isEmpty(orgRdn)) {
        orgRdn = getOrgRdnForOrgId(pOIDs, pPerformer);
    }

    if (orgRdn == null) {
        throw new ExecutionException("OrgRDN = null", null);
    }
    InitialLdapContext ctx = null;
    try {
        ctx = LDAPConnector.getSingletonInstance().takeCtx();
        StringBuilder vBaseDn = new StringBuilder(Constants.ldap_ddbOrg_Id).append("=")
                .append(orgRdn.replaceAll(",", "," + Constants.ldap_ddbOrg_Id + "=")).append(",")
                .append((!pLicensedOrgs ? LDAPConnector.getSingletonInstance().getInstitutionBaseDN()
                        : LDAPConnector.getSingletonInstance().getLicensedInstitutionsBaseDN()));
        StringBuilder vFilter = new StringBuilder("(objectClass=").append(Constants.ldap_ddbOrg_ObjectClass)
                .append(")");
        NamingEnumeration<SearchResult> searchResults = this.query(ctx, vBaseDn.toString(), vFilter.toString(),
                attributeFilter, pScopy);
        return searchResults;
    } catch (IllegalAccessException ex) {
        LOG.log(Level.SEVERE, "Connection-Error", ex);
        throw new ExecutionException(ex.getMessage(), ex.getCause());
    } catch (NamingException ne) {
        LOG.log(Level.SEVERE, "NamingException", ne);
        throw new ExecutionException(ne.getMessage(), ne.getCause());
    } finally {
        if (ctx != null) {
            try {
                LDAPConnector.getSingletonInstance().putCtx(ctx);
            } catch (Exception ex) {
                LOG.log(Level.SEVERE, "Exception", ex);
            }
        }
    }
}

From source file:org.swordess.ldap.odm.core.SessionImpl.java

private void connectIndirections(IndirectionsMetaData metaData, String oneDN, List<String> theOtherDNs) {
    if (StringUtils.isEmpty(oneDN) || CollectionUtils.isEmpty(theOtherDNs)) {
        LogUtils.debug(LOG, "connectIndirections: either one or theOther is empty, do nothing.");
        return;//from  w  ww . j  a  v  a 2 s. c om
    }

    LogUtils.debug(LOG, "connect " + oneDN + " and " + theOtherDNs);

    try {
        ctx.modifyAttributes(oneDN,
                new ModificationItem[] { ModUtils.add(metaData.getOne().getIndirectionAttr(), theOtherDNs) });
        LogUtils.debug(LOG, String.format("connected: %s -> %s", oneDN, theOtherDNs));

        for (String theOtherDN : theOtherDNs) {
            String indirectionAttr = metaData.getTheOther().dnToIndirectionAttr(theOtherDN);
            if (null == indirectionAttr) {
                LogUtils.debug(LOG, "no corresponding indirection configured for " + theOtherDN);
                continue;
            }

            ctx.modifyAttributes(theOtherDN, new ModificationItem[] { ModUtils.add(indirectionAttr, oneDN) });
            LogUtils.debug(LOG, String.format("connected: %s -> %s", theOtherDN, oneDN));
        }
    } catch (NamingException e) {
        throw new SessionException(e.getMessage(), e);
    }
}