public static String errorCodeToDescription(NamingException code){ String errorCode = code.getExplanation(); Matcher m = LDAP_ERROR_CODE.matcher(errorCode); if (m.find()) { errorCode = m.group(0).substring(m.group(0).length()-3); } switch (errorCode) { case "525": return "User not found"; case "52e": return "Invalid credentials"; case "530": return "Not permitted to logon at this time"; case "531": return "Not permitted to logon at this workstation"; case "532": return "Password expired (remember to check the user set in osuser.xml also)"; case "533": return "Account disabled"; case "701": return "Account expired"; case "773": return "User must reset password"; case "775": return "User account locked"; default: return errorCode; } }
/** * Convenience method to get the explanation associated with this exception, * if the root cause was an instance of {@link javax.naming.NamingException}. * * @return a detail string explaining more about this exception if the root * cause is an instance of javax.naming.NamingException, or * <code>null</code> if there is no detail message for this * exception */ public String getExplanation() { if (getCause() instanceof javax.naming.NamingException) { return ((javax.naming.NamingException) getCause()).getExplanation(); } return null; }
/** * Convenience method to get the explanation associated with this exception, * if the root cause was an instance of {@link javax.naming.NamingException}. * * @return a detail string explaining more about this exception if the root * cause is an instance of javax.naming.NamingException, or * <code>null</code> if there is no detail message for this * exception */ public String getExplanation() { if (getCause() instanceof javax.naming.NamingException) { return ((javax.naming.NamingException) getCause()).getExplanation(); } return null; }
/** * Convenience method to get the explanation associated with this exception, * if the root cause was an instance of {@link javax.naming.NamingException}. * * @return a detail string explaining more about this exception if the root * cause is an instance of javax.naming.NamingException, or * <code>null</code> if there is no detail message for this * exception */ public String getExplanation() { if (getCause() instanceof javax.naming.NamingException) { return ((javax.naming.NamingException) getCause()).getExplanation(); } return null; }
/** * Convenience method to get the explanation associated with this exception, * if the root cause was an instance of {@link javax.naming.NamingException}. * * @return a detail string explaining more about this exception if the root * cause is an instance of javax.naming.NamingException, or * <code>null</code> if there is no detail message for this * exception */ public String getExplanation() { if (getCause() instanceof javax.naming.NamingException) { return ((javax.naming.NamingException) getCause()).getExplanation(); } return null; }
/** * Create the naming manager. * @throws NamingException if no initial context is built */ private SingletonNamingManager() throws NamingException { try { ictx = new InitialContext(); // there is a bug in carol that makes this not work. //myEnv = ictx.getEnvironment(); clBindings = new Hashtable(); } catch (NamingException n) { logger.log(BasicLevel.ERROR, "NamingManager: " + n.getExplanation()); Throwable t = n.getRootCause(); if (t != null) { if (t.getMessage().startsWith("Connection refused to host:")) { logger.log(BasicLevel.ERROR, "NamingManager: rmi registry not started ?"); } else { logger.log(BasicLevel.ERROR, "NamingManager: " + t.getMessage()); } } throw n; } }
boolean isLdapValid(final Credentials credentials) throws RepositoryException { LdapUser ldapUser = getLdapAuthData(credentials); if (ldapUser != null) { Hashtable<String, String> authEnv = new Hashtable<String, String>(11); //String dn = "uid=" + ldapUser.getUserName() + "," + ldapBase; String dn = StringUtils.replace(ldapBase, "${userName}", ldapUser.getUserName()); authEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory"); authEnv.put(Context.PROVIDER_URL, ldapUrl); authEnv.put(Context.SECURITY_AUTHENTICATION, ldapAuthenticationType); authEnv.put(Context.SECURITY_PRINCIPAL, dn); authEnv.put(Context.SECURITY_CREDENTIALS, ldapUser.getPassword()); try { DirContext ctx = new InitialDirContext(authEnv); Attributes attributes = ctx.getAttributes(dn); ldapUser.setAttributes(attributes); return true; } catch (AuthenticationException authEx) { log.error("Authentication failure - "+dn+" Error: "+authEx.getExplanation()); return false; } catch (NamingException namEx) { throw new RepositoryException("Ldap Error:"+namEx.getExplanation()); } } // no authdata, not valid return false; }
public void close() { try { if(ldapCtx != null) { ldapCtx.close(); } } catch (NamingException ne) { LogManager.logWarning(LogConstants.CTX_CONNECTOR, LDAPPlugin.Util.gs(LDAPPlugin.Event.TEIID12003, ne.getExplanation())); } }
public String getCode() { if(getCause() instanceof NamingException) { NamingException nex = (NamingException) getCause(); return nex.getRootCause() != null ? nex.getRootCause().getMessage() : nex.getExplanation(); } else { return null; } } }
/** * Controls JNDI context initialization. * * @throws SyncFactoryException if an error occurs parsing the JNDI context */ private static synchronized void initJNDIContext() throws SyncFactoryException { if ((ic != null) && (lazyJNDICtxRefresh == false)) { try { parseProperties(parseJNDIContext()); lazyJNDICtxRefresh = true; // touch JNDI namespace once. } catch (NamingException e) { e.printStackTrace(); throw new SyncFactoryException("SPI: NamingException: " + e.getExplanation()); } catch (Exception e) { e.printStackTrace(); throw new SyncFactoryException("SPI: Exception: " + e.getMessage()); } } } /**
/** * Closes LDAP context, effectively closing the connection to LDAP. * (non-Javadoc) */ @Override public void close() { if(initCtx != null) { try { initCtx.close(); } catch(NamingException e) { LogManager.logDetail(LogConstants.CTX_CONNECTOR, LDAPPlugin.Util.getString("LDAPConnection.contextCloseError",e.getExplanation())); //$NON-NLS-1$ } } LogManager.logDetail(LogConstants.CTX_CONNECTOR,"LDAP context has been closed."); //$NON-NLS-1$ }
@Override public void close() { if (searchEnumeration != null) { try { searchEnumeration.close(); } catch (Exception e) { } // catch everything, because NamingEnumeration has undefined behavior if it previously hit an exception } if (ldapCtx != null) { try { ldapCtx.close(); } catch (NamingException ne) { LogManager.logWarning(LogConstants.CTX_CONNECTOR, LDAPPlugin.Util.gs(LDAPPlugin.Event.TEIID12003, ne.getExplanation())); } } }
WeldServletLogger.LOG.beanManagerReferenceBoundTo(QUALIFIED_BEAN_MANAGER_JNDI_NAME); } catch (NamingException e) { throw WeldServletLogger.LOG.couldNotBindBeanManagerReferenceToJNDI(e.getExplanation()); throw WeldServletLogger.LOG.couldNotCreateInitialContext(e.getExplanation());
WeldServletLogger.LOG.beanManagerReferenceBoundTo(QUALIFIED_BEAN_MANAGER_JNDI_NAME); } catch (NamingException e) { throw WeldServletLogger.LOG.couldNotBindBeanManagerReferenceToJNDI(e.getExplanation()); throw WeldServletLogger.LOG.couldNotCreateInitialContext(e.getExplanation());
/** * Closes LDAP context, effectively closing the connection to LDAP. * (non-Javadoc) */ @Override public void close() { if(initCtx != null) { try { initCtx.close(); } catch(NamingException e) { LogManager.logDetail(LogConstants.CTX_CONNECTOR, LDAPPlugin.Util.getString("LDAPConnection.contextCloseError",e.getExplanation())); //$NON-NLS-1$ } } LogManager.logDetail(LogConstants.CTX_CONNECTOR,"LDAP context has been closed."); //$NON-NLS-1$ }
/** * Set the standard request controls */ private void setRequestControls(byte[] cookie) throws TranslatorException { List<Control> ctrl = new ArrayList<Control>(); SortKey[] keys = searchDetails.getSortKeys(); try { if (keys != null) { ctrl.add(new SortControl(keys, Control.NONCRITICAL)); } if (this.executionFactory.usePagination()) { ctrl.add(new PagedResultsControl(this.executionContext.getBatchSize(), cookie, Control.CRITICAL)); } if (!ctrl.isEmpty()) { this.ldapCtx.setRequestControls(ctrl.toArray(new Control[ctrl.size()])); LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Sort/pagination controls were created successfully."); //$NON-NLS-1$ } } catch (NamingException ne) { final String msg = LDAPPlugin.Util.getString("LDAPSyncQueryExecution.setControlsError") + //$NON-NLS-1$ " : "+ne.getExplanation(); //$NON-NLS-1$ throw new TranslatorException(ne, msg); } catch(IOException e) { throw new TranslatorException(e); } }
/** * Perform the LDAP search against the subcontext, using the filter and * search controls appropriate to the query and model metadata. */ private void executeSearch() throws TranslatorException { String filter = searchDetails.getContextFilter(); try { searchEnumeration = this.ldapCtx.search("", filter, ctrls); //$NON-NLS-1$ } catch (NamingException ne) { final String msg = LDAPPlugin.Util.getString("LDAPSyncQueryExecution.execSearchError"); //$NON-NLS-1$ throw new TranslatorException(ne, msg + " : " + ne.getExplanation()); //$NON-NLS-1$ } catch(Exception e) { final String msg = LDAPPlugin.Util.getString("LDAPSyncQueryExecution.execSearchError"); //$NON-NLS-1$ throw new TranslatorException(e, msg); } }
logger.error("Failed to close userContext. Reason: " + e.getExplanation());
protected Identity getObject(String distinguishedName, String scope) { LdapContext context = null; try { LdapName object = new LdapName(distinguishedName); context = getServiceContext(); Attributes search; search = context.getAttributes(object); if (!isType(search, scope) && !hasPermission(search)){ return null; } return attributesToIdentity(object); } catch (NamingException e) { getLogger().error("Failed to get object: {} : {}", distinguishedName, e.getExplanation()); if(!LDAPUtils.isRecoverable(e)) { invalidateServiceContext(context); context = null; } return null; } finally { if (context != null) { returnServiceContext(context); } } }
private void executeDelete() throws TranslatorException { Condition criteria = ((Delete)command).getWhere(); // since we have the exact same processing rules for criteria // for updates and deletes, we use a common private method to do this. // note that this private method will throw a ConnectorException // for illegal criteria, which we deliberately don't catch // so it gets passed on as is. String distinguishedName = getDNFromCriteria(criteria); // just try to delete an LDAP entry using the DN // specified in the DELETE operation. If it isn't // legal, we'll get a NamingException back, whose explanation // we'll return in a ConnectorException try { ldapCtx.destroySubcontext(distinguishedName); } catch (NamingException ne) { final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.deleteFailed",distinguishedName,ne.getExplanation()); //$NON-NLS-1$ throw new TranslatorException(msg); // don't remember why I added this generic catch of Exception, // but it does no harm... } catch (Exception e) { final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.deleteFailedUnexpected",distinguishedName); //$NON-NLS-1$ throw new TranslatorException(e, msg); } }