List of usage examples for javax.naming NamingException getMessage
public String getMessage()
From source file:nl.nn.adapterframework.ldap.LdapSender.java
private String performOperationChangeUnicodePwd(String entryName, ParameterResolutionContext prc, Map paramValueMap) throws SenderException, ParameterException { ModificationItem[] modificationItems = new ModificationItem[2]; modificationItems[0] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("unicodePwd", encodeUnicodePwd((String) paramValueMap.get("oldPassword")))); modificationItems[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("unicodePwd", encodeUnicodePwd((String) paramValueMap.get("newPassword")))); DirContext dirContext = null; try {// ww w . j a va2 s .co m dirContext = getDirContext(paramValueMap); dirContext.modifyAttributes(entryName, modificationItems); return DEFAULT_RESULT_CHANGE_UNICODE_PWD_OK; } catch (NamingException e) { // https://wiki.servicenow.com/index.php?title=LDAP_Error_Codes: // 19 LDAP_CONSTRAINT_VIOLATION Indicates that the attribute value specified in a modify, add, or modify DN operation violates constraints placed on the attribute. The constraint can be one of size or content (string only, no binary). // AD: // [LDAP: error code 19 - 0000052D: AtrErr: DSID-03191041, #1... if (e.getMessage().startsWith("[LDAP: error code 19 - ")) { if (log.isDebugEnabled()) log.debug("Operation [" + getOperation() + "] old password doesn't match or new password doesn't comply with policy for: " + entryName); return DEFAULT_RESULT_CHANGE_UNICODE_PWD_NOK; } else { storeLdapException(e, prc); throw new SenderException( "Exception in operation [" + getOperation() + "] entryName [" + entryName + "]", e); } } finally { closeDirContext(dirContext); } }
From source file:nl.nn.adapterframework.ldap.LdapSender.java
private String performOperationCreate(String entryName, ParameterResolutionContext prc, Map paramValueMap, Attributes attrs) throws SenderException, ParameterException { if (manipulationSubject.equals(MANIPULATION_ATTRIBUTE)) { String result = null;/*from w w w .j a v a2 s . co m*/ NamingEnumeration na = attrs.getAll(); while (na.hasMoreElements()) { Attribute a = (Attribute) na.nextElement(); log.debug("Create attribute: " + a.getID()); NamingEnumeration values; try { values = a.getAll(); } catch (NamingException e1) { storeLdapException(e1, prc); throw new SenderException("cannot obtain values of Attribute [" + a.getID() + "]", e1); } while (values.hasMoreElements()) { Attributes partialAttrs = new BasicAttributes(); Attribute singleValuedAttribute; String id = a.getID(); Object value = values.nextElement(); if (log.isDebugEnabled()) { if (id.toLowerCase().contains("password") || id.toLowerCase().contains("pwd")) { log.debug("Create value: ***"); } else { log.debug("Create value: " + value); } } if (unicodePwd && "unicodePwd".equalsIgnoreCase(id)) { singleValuedAttribute = new BasicAttribute(id, encodeUnicodePwd(value)); } else { singleValuedAttribute = new BasicAttribute(id, value); } partialAttrs.put(singleValuedAttribute); DirContext dirContext = null; try { dirContext = getDirContext(paramValueMap); dirContext.modifyAttributes(entryName, DirContext.ADD_ATTRIBUTE, partialAttrs); } catch (NamingException e) { // https://wiki.servicenow.com/index.php?title=LDAP_Error_Codes: // 20 LDAP_TYPE_OR_VALUE_EXISTS Indicates that the attribute value specified in a modify or add operation already exists as a value for that attribute. // Sun: // [LDAP: error code 20 - Attribute Or Value Exists] if (e.getMessage().startsWith("[LDAP: error code 20 - ")) { if (log.isDebugEnabled()) log.debug("Operation [" + getOperation() + "] successful: " + e.getMessage()); result = DEFAULT_RESULT_CREATE_OK; } else { storeLdapException(e, prc); throw new SenderException( "Exception in operation [" + getOperation() + "] entryName [" + entryName + "]", e); } } finally { closeDirContext(dirContext); } } } if (result != null) { return result; } return DEFAULT_RESULT; } else { DirContext dirContext = null; try { if (unicodePwd) { Enumeration enumeration = attrs.getIDs(); while (enumeration.hasMoreElements()) { String id = (String) enumeration.nextElement(); if ("unicodePwd".equalsIgnoreCase(id)) { Attribute attr = attrs.get(id); for (int i = 0; i < attr.size(); i++) { attr.set(i, encodeUnicodePwd(attr.get(i))); } } } } dirContext = getDirContext(paramValueMap); dirContext.bind(entryName, null, attrs); return DEFAULT_RESULT; } catch (NamingException e) { // if (log.isDebugEnabled()) log.debug("Exception in operation [" + getOperation()+ "] entryName ["+entryName+"]", e); if (log.isDebugEnabled()) log.debug("Exception in operation [" + getOperation() + "] entryName [" + entryName + "]: " + e.getMessage()); // https://wiki.servicenow.com/index.php?title=LDAP_Error_Codes: // 68 LDAP_ALREADY_EXISTS Indicates that the add operation attempted to add an entry that already exists, or that the modify operation attempted to rename an entry to the name of an entry that already exists. // Sun: // [LDAP: error code 68 - Entry Already Exists] if (e.getMessage().startsWith("[LDAP: error code 68 - ")) { return DEFAULT_RESULT_CREATE_OK; } else { storeLdapException(e, prc); throw new SenderException(e); } } finally { closeDirContext(dirContext); } } }
From source file:net.testdriven.psiprobe.controllers.sql.ConnectionTestController.java
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String resourceName = ServletRequestUtils.getStringParameter(request, "resource"); DataSource dataSource = null; try {/* w ww . j a va 2 s . c o m*/ dataSource = getContainerWrapper().getResourceResolver().lookupDataSource(context, resourceName); } catch (NamingException e) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } if (dataSource == null) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } else { try { // TODO: use Spring's jdbc template? try (Connection conn = dataSource.getConnection()) { DatabaseMetaData md = conn.getMetaData(); List<Map<String, String>> dbMetaData = new ArrayList<>(); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdName", md.getDatabaseProductName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdVersion", md.getDatabaseProductVersion()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverName", md.getDriverName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverVersion", md.getDriverVersion()); // addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcVersion", String.valueOf(md.getJDBCMajorVersion())); return new ModelAndView(getViewName(), "dbMetaData", dbMetaData); } } catch (SQLException e) { String message = getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.connection.failure", new Object[] { e.getMessage() }); logger.error(message, e); request.setAttribute("errorMessage", message); } } return new ModelAndView(getViewName()); }
From source file:org.apache.directory.studio.connection.core.io.jndi.LdifSearchLogger.java
/** * Logs the given text to the search logger of the given connection. * /*from w w w. j a v a 2 s .co m*/ * @param text the text to log * @param type the type, either SEARCH REQUEST or SEARCH RESULT * @param ex the naming exception if an error occurred, null otherwise * @param connection the connection */ private void log(String text, String type, NamingException ex, Connection connection) { String id = connection.getId(); if (!loggers.containsKey(id)) { if (connection.getName() != null) { initSearchLogger(connection); } } if (loggers.containsKey(id)) { Logger logger = loggers.get(id); DateFormat df = new SimpleDateFormat(ConnectionCoreConstants.DATEFORMAT); df.setTimeZone(ConnectionCoreConstants.UTC_TIME_ZONE); if (ex != null) { logger.log(Level.ALL, LdifCommentLine.create("#!" + type + " ERROR") //$NON-NLS-1$//$NON-NLS-2$ .toFormattedString(LdifFormatParameters.DEFAULT)); } else { logger.log(Level.ALL, LdifCommentLine.create("#!" + type + " OK") //$NON-NLS-1$//$NON-NLS-2$ .toFormattedString(LdifFormatParameters.DEFAULT)); } logger.log(Level.ALL, LdifCommentLine .create("#!CONNECTION ldap://" + connection.getHost() + ":" + connection.getPort()) //$NON-NLS-1$//$NON-NLS-2$ .toFormattedString(LdifFormatParameters.DEFAULT)); logger.log(Level.ALL, LdifCommentLine.create("#!DATE " + df.format(new Date())) //$NON-NLS-1$ .toFormattedString(LdifFormatParameters.DEFAULT)); if (ex != null) { String errorComment = "#!ERROR " + ex.getMessage(); //$NON-NLS-1$ errorComment = errorComment.replaceAll("\r", " "); //$NON-NLS-1$ //$NON-NLS-2$ errorComment = errorComment.replaceAll("\n", " "); //$NON-NLS-1$ //$NON-NLS-2$ LdifCommentLine errorCommentLine = LdifCommentLine.create(errorComment); logger.log(Level.ALL, errorCommentLine.toFormattedString(LdifFormatParameters.DEFAULT)); } logger.log(Level.ALL, text); } }
From source file:org.wso2.carbon.appfactory.eventing.jms.TopicPublisher.java
public void publishMessage(Event event) throws AppFactoryEventException { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF); properties.put(CF_NAME_PREFIX + CF_NAME, Util.getTCPConnectionURL()); properties.put(CarbonConstants.REQUEST_BASE_CONTEXT, "true"); try {/*w w w. ja va2s. c o m*/ ctx = new InitialContext(properties); connFactory = (TopicConnectionFactory) ctx.lookup(CF_NAME); } catch (NamingException e) { throw new AppFactoryEventException("Failed to initialize InitialContext.", e); } TopicConnection topicConnection = null; TopicSession topicSession = null; try { topicConnection = connFactory.createTopicConnection(); topicSession = topicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); // Send message String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); Topic topic = topicSession.createTopic(event.getTarget()); //Until MB supports 'Dynamic Topics' we have to create a subscription, therefore forcing Message broker to // create the topic. String defaultSubscriptionId = tenantDomain + "/" + DEFAULT_SUBSCRIPTION + UUID.randomUUID(); topicSubscriber = topicSession.createDurableSubscriber(topic, defaultSubscriptionId); // We are unsubscribing from the Topic as soon as topicSession.unsubscribe(defaultSubscriptionId); // create the message to send MapMessage mapMessage = topicSession.createMapMessage(); mapMessage.setString(MESSAGE_TITLE, event.getMessageTitle()); mapMessage.setString(MESSAGE_BODY, event.getMessageBody()); javax.jms.TopicPublisher topicPublisher = topicSession.createPublisher(topic); topicConnection.start(); topicPublisher.publish(mapMessage); if (log.isDebugEnabled()) { log.debug("Message with Id:" + mapMessage.getJMSMessageID() + ", with title:" + event.getMessageTitle() + " was successfully published."); } } catch (JMSException e) { log.error("Failed to publish message due to " + e.getMessage(), e); throw new AppFactoryEventException("Failed to publish message due to " + e.getMessage(), e); } finally { if (topicSubscriber != null) { try { topicSubscriber.close(); } catch (JMSException e) { log.error("Failed to close default topic subscriber", e); } } if (topicSession != null) { try { topicSession.close(); } catch (JMSException e) { log.error("Failed to close topic session", e); } } if (topicConnection != null) { try { topicConnection.close(); } catch (JMSException e) { log.error("Failed to close topic connection", e); } } } }
From source file:com.googlecode.psiprobe.controllers.sql.ConnectionTestController.java
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String resourceName = ServletRequestUtils.getStringParameter(request, "resource"); DataSource dataSource = null; try {/*from w w w .j a v a 2 s.c o m*/ dataSource = getContainerWrapper().getResourceResolver().lookupDataSource(context, resourceName, getContainerWrapper()); } catch (NamingException e) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } if (dataSource == null) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } else { try { // TODO: use Spring's jdbc template? Connection conn = dataSource.getConnection(); try { DatabaseMetaData md = conn.getMetaData(); List dbMetaData = new ArrayList(); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdName", md.getDatabaseProductName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdVersion", md.getDatabaseProductVersion()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverName", md.getDriverName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverVersion", md.getDriverVersion()); // addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcVersion", String.valueOf(md.getJDBCMajorVersion())); return new ModelAndView(getViewName(), "dbMetaData", dbMetaData); } finally { conn.close(); } } catch (SQLException e) { String message = getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.connection.failure", new Object[] { e.getMessage() }); logger.error(message, e); request.setAttribute("errorMessage", message); } } return new ModelAndView(getViewName()); }
From source file:psiprobe.controllers.sql.ConnectionTestController.java
@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String resourceName = ServletRequestUtils.getStringParameter(request, "resource"); DataSource dataSource = null; try {/*from www . j a v a 2 s . c om*/ dataSource = getContainerWrapper().getResourceResolver().lookupDataSource(context, resourceName, getContainerWrapper()); } catch (NamingException e) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); logger.trace("", e); } if (dataSource == null) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } else { try { // TODO: use Spring's jdbc template? try (Connection conn = dataSource.getConnection()) { DatabaseMetaData md = conn.getMetaData(); List<Map<String, String>> dbMetaData = new ArrayList<>(); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdName", md.getDatabaseProductName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdVersion", md.getDatabaseProductVersion()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverName", md.getDriverName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverVersion", md.getDriverVersion()); // addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcVersion", // String.valueOf(md.getJDBCMajorVersion())); return new ModelAndView(getViewName(), "dbMetaData", dbMetaData); } } catch (SQLException e) { String message = getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.connection.failure", new Object[] { e.getMessage() }); logger.error(message, e); request.setAttribute("errorMessage", message); } } return new ModelAndView(getViewName()); }
From source file:nl.nn.adapterframework.ldap.LdapSender.java
private String performOperationUpdate(String entryName, ParameterResolutionContext prc, Map paramValueMap, Attributes attrs) throws SenderException, ParameterException { String entryNameAfter = entryName; if (paramValueMap != null) { String newEntryName = (String) paramValueMap.get("newEntryName"); if (newEntryName != null && StringUtils.isNotEmpty(newEntryName)) { if (log.isDebugEnabled()) log.debug("newEntryName=[" + newEntryName + "]"); DirContext dirContext = null; try { dirContext = getDirContext(paramValueMap); dirContext.rename(entryName, newEntryName); entryNameAfter = newEntryName; } catch (NamingException e) { String msg;/*from ww w .j ava 2s . co m*/ // https://wiki.servicenow.com/index.php?title=LDAP_Error_Codes: // 32 LDAP_NO_SUCH_OBJECT Indicates the target object cannot be found. This code is not returned on following operations: Search operations that find the search base but cannot find any entries that match the search filter. Bind operations. // Sun: // [LDAP: error code 32 - No Such Object... if (e.getMessage().startsWith("[LDAP: error code 32 - ")) { msg = "Operation [" + getOperation() + "] failed - wrong entryName [" + entryName + "]"; } else { msg = "Exception in operation [" + getOperation() + "] entryName [" + entryName + "]"; } storeLdapException(e, prc); throw new SenderException(msg, e); } finally { closeDirContext(dirContext); } } } if (manipulationSubject.equals(MANIPULATION_ATTRIBUTE)) { NamingEnumeration na = attrs.getAll(); while (na.hasMoreElements()) { Attribute a = (Attribute) na.nextElement(); log.debug("Update attribute: " + a.getID()); NamingEnumeration values; try { values = a.getAll(); } catch (NamingException e1) { storeLdapException(e1, prc); throw new SenderException("cannot obtain values of Attribute [" + a.getID() + "]", e1); } while (values.hasMoreElements()) { Attributes partialAttrs = new BasicAttributes(); Attribute singleValuedAttribute; String id = a.getID(); Object value = values.nextElement(); if (log.isDebugEnabled()) { if (id.toLowerCase().contains("password") || id.toLowerCase().contains("pwd")) { log.debug("Update value: ***"); } else { log.debug("Update value: " + value); } } if (unicodePwd && "unicodePwd".equalsIgnoreCase(id)) { singleValuedAttribute = new BasicAttribute(id, encodeUnicodePwd(value)); } else { singleValuedAttribute = new BasicAttribute(id, value); } partialAttrs.put(singleValuedAttribute); DirContext dirContext = null; try { dirContext = getDirContext(paramValueMap); dirContext.modifyAttributes(entryNameAfter, DirContext.REPLACE_ATTRIBUTE, partialAttrs); } catch (NamingException e) { String msg; // https://wiki.servicenow.com/index.php?title=LDAP_Error_Codes: // 32 LDAP_NO_SUCH_OBJECT Indicates the target object cannot be found. This code is not returned on following operations: Search operations that find the search base but cannot find any entries that match the search filter. Bind operations. // Sun: // [LDAP: error code 32 - No Such Object... if (e.getMessage().startsWith("[LDAP: error code 32 - ")) { msg = "Operation [" + getOperation() + "] failed - wrong entryName [" + entryNameAfter + "]"; } else { msg = "Exception in operation [" + getOperation() + "] entryName [" + entryNameAfter + "]"; } //result = DEFAULT_RESULT_UPDATE_NOK; storeLdapException(e, prc); throw new SenderException(msg, e); } finally { closeDirContext(dirContext); } } } return DEFAULT_RESULT; } else { DirContext dirContext = null; try { dirContext = getDirContext(paramValueMap); //dirContext.rename(newEntryName, oldEntryName); //result = DEFAULT_RESULT; dirContext.rename(entryName, entryName); return "<LdapResult>Deze functionaliteit is nog niet beschikbaar - naam niet veranderd.</LdapResult>"; } catch (NamingException e) { // https://wiki.servicenow.com/index.php?title=LDAP_Error_Codes: // 68 LDAP_ALREADY_EXISTS Indicates that the add operation attempted to add an entry that already exists, or that the modify operation attempted to rename an entry to the name of an entry that already exists. // Sun: // [LDAP: error code 68 - Entry Already Exists] if (!e.getMessage().startsWith("[LDAP: error code 68 - ")) { storeLdapException(e, prc); throw new SenderException(e); } return DEFAULT_RESULT_CREATE_NOK; } finally { closeDirContext(dirContext); } } }
From source file:de.unibi.techfak.bibiserv.BiBiTools.java
/** * Return datasource used by this BiBiTools class. * * If (BiBiTool Property ('useDebugDataSource') is set to true, then a * DebugDataSource is used instead of a normal one. * * @see DDataSource// w w w .jav a2 s . c o m * * @return */ public static DataSource getDataSource() throws DBConnectionException { if (BiBiTools.datasource == null) { try { Context ctx = new InitialContext(); if (ctx == null) { log.error("context is null"); throw new DBConnectionException(); } // @todo: Hardcoded DataSource !!! if (Boolean.parseBoolean(getProperties().getProperty("useDebugDataSource", "false"))) { BiBiTools.datasource = new DDataSource((DataSource) ctx.lookup("jdbc/bibiserv2")); } else { BiBiTools.datasource = (DataSource) ctx.lookup("jdbc/bibiserv2"); } } catch (NamingException ex) { log.fatal("An NamingException occurred : " + ex.getMessage()); throw new DBConnectionException(); } } return BiBiTools.datasource; }
From source file:org.wso2.carbon.identity.agent.onprem.userstore.manager.ldap.LDAPUserStoreManager.java
/** * {@inheritDoc}//from w w w .ja va2 s . c o m */ public boolean doAuthenticate(String userName, Object credential) throws UserStoreException { boolean debug = log.isDebugEnabled(); if (userName == null || credential == null) { return false; } userName = userName.trim(); String password = (String) credential; password = password.trim(); if (userName.equals("") || password.equals("")) { return false; } if (debug) { log.debug("Authenticating user " + userName); } boolean bValue = false; String name; // read DN patterns from user-mgt.xml String patterns = userStoreProperties.get(LDAPConstants.USER_DN_PATTERN); if (patterns != null && !patterns.isEmpty()) { if (debug) { log.debug("Using UserDNPatterns " + patterns); } // if the property is present, split it using # to see if there are // multiple patterns specified. String[] userDNPatternList = patterns.split(CommonConstants.XML_PATTERN_SEPERATOR); if (userDNPatternList.length > 0) { for (String userDNPattern : userDNPatternList) { name = MessageFormat.format(userDNPattern, escapeSpecialCharactersForDN(userName)); if (debug) { log.debug("Authenticating with " + name); } try { bValue = this.bindAsUser(name, (String) credential); if (bValue) { break; } } catch (NamingException e) { // do nothing if bind fails since we check for other DN // patterns as well. if (log.isDebugEnabled()) { log.debug("Checking authentication with UserDN " + userDNPattern + "failed " + e.getMessage(), e); } } } } } else { name = getNameInSpaceForUserName(userName); try { if (name != null) { if (debug) { log.debug("Authenticating with " + name); } bValue = this.bindAsUser(name, (String) credential); } } catch (NamingException e) { String errorMessage = "Cannot bind user : " + userName; if (log.isDebugEnabled()) { log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); } } return bValue; }