List of usage examples for javax.naming NamingException getMessage
public String getMessage()
From source file:org.openiam.spml2.spi.ldap.LdapConnectorImpl.java
public LdapContext connect(String userName, String password) { //LdapContext ctxLdap = null; Hashtable<String, String> envDC = new Hashtable(); //keystore = secres.getString("KEYSTORE"); System.setProperty("javax.net.ssl.trustStore", keystore); log.debug("Connecting to ldap using principal=" + userName); //envDC.put(Context.PROVIDER_URL,host); envDC.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); envDC.put(Context.SECURITY_AUTHENTICATION, "simple"); // simple envDC.put(Context.SECURITY_PRINCIPAL, userName); //"administrator@diamelle.local" envDC.put(Context.SECURITY_CREDENTIALS, password); // if (protocol != null && protocol.equalsIgnoreCase("SSL")) { // envDC.put(Context.SECURITY_PROTOCOL, protocol); // }//from w ww .jav a2 s.c o m try { return (new InitialLdapContext(envDC, null)); } catch (NamingException ne) { log.error(ne.getMessage()); } return null; }
From source file:de.sub.goobi.helper.ldap.Ldap.java
/** * Get next free uidNumber./* w w w. ja v a 2 s . co m*/ * * @return next free uidNumber */ private String getNextUidNumber() { Hashtable<String, String> env = getLdapConnectionSettings(); env.put(Context.SECURITY_PRINCIPAL, ConfigCore.getParameter("ldap_adminLogin")); env.put(Context.SECURITY_CREDENTIALS, ConfigCore.getParameter("ldap_adminPassword")); DirContext ctx; String rueckgabe = ""; try { ctx = new InitialDirContext(env); Attributes attrs = ctx.getAttributes(ConfigCore.getParameter("ldap_nextFreeUnixId")); Attribute la = attrs.get("uidNumber"); rueckgabe = (String) la.get(0); ctx.close(); } catch (NamingException e) { logger.error(e); Helper.setFehlerMeldung(e.getMessage()); } return rueckgabe; }
From source file:org.wso2.carbon.appfactory.ext.datasource.ApplicationAwareDataSourceRepository.java
private void unregisterJNDI(DataSourceMetaInfo dsmInfo, String applicationID) { String initialApplicationName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getApplicationName(); try {// ww w. j a v a 2s. c o m PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(this.getTenantId()); PrivilegedCarbonContext.getThreadLocalCarbonContext() .setApplicationName(applicationID + AF_DUMMY_VERSION); JNDIConfig jndiConfig = dsmInfo.getJndiConfig(); if (jndiConfig == null) { return; } try { InitialContext context = new InitialContext(jndiConfig.extractHashtableEnv()); context.unbind(jndiConfig.getName()); } catch (NamingException e) { log.error("Error in unregistering JNDI name: " + jndiConfig.getName() + " - " + e.getMessage(), e); } } finally { PrivilegedCarbonContext.getThreadLocalCarbonContext().setApplicationName(initialApplicationName); PrivilegedCarbonContext.endTenantFlow(); } }
From source file:org.wso2.carbon.appfactory.ext.datasource.ApplicationAwareDataSourceRepository.java
private void registerJNDI(DataSourceMetaInfo dsmInfo, Object dsObject, String applicationID) throws DataSourceException { String initialApplicationName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getApplicationName(); try {//from w w w . ja va 2 s . co m PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(this.getTenantId()); /* Have to add dummy version to comply with AF app naming rule */ PrivilegedCarbonContext.getThreadLocalCarbonContext() .setApplicationName(applicationID + AF_DUMMY_VERSION); JNDIConfig jndiConfig = dsmInfo.getJndiConfig(); if (jndiConfig == null) { return; } InitialContext context; try { context = new InitialContext(jndiConfig.extractHashtableEnv()); } catch (NamingException e) { throw new DataSourceException("Error creating JNDI initial context: " + e.getMessage(), e); } this.checkAndCreateJNDISubContexts(context, jndiConfig.getName()); try { context.rebind(jndiConfig.getName(), dsObject); } catch (NamingException e) { throw new DataSourceException( "Error in binding to JNDI with name '" + jndiConfig.getName() + "' - " + e.getMessage(), e); } } finally { PrivilegedCarbonContext.getThreadLocalCarbonContext().setApplicationName(initialApplicationName); PrivilegedCarbonContext.endTenantFlow(); } }
From source file:ru.efo.security.ADUserDetailsService.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { final String username = authentication.getName(); final String password = authentication.getCredentials().toString(); logger.log(Level.FINE, "Performing logon into '" + ldapUrl + "' with credentials '" + username + "'/'" + password.replaceAll(".", "*") + "'"); DirContext context = null;/*from ww w . j a v a 2s. c o m*/ try { context = getDirContext(username + userSuffix, password); logger.log(Level.FINE, "User '" + username + "' has been successfully logged on"); final ADUserDetails details = loadUserByUsername(context, username, password); return new UsernamePasswordAuthenticationToken(details, password, details.getAuthorities()); } catch (NamingException ex) { logger.log(Level.SEVERE, "Could not login into '" + ldapUrl + "'", ex); throw new BadCredentialsException(ex.getMessage()); } finally { if (context != null) { try { context.close(); } catch (NamingException ex) { logger.log(Level.WARNING, "Could not close DirContext", ex); } } } }
From source file:com.heliumv.api.BaseApi.java
public void respondUnavailable(NamingException e) { log.info("default-log", e); getServletResponse().setHeader(X_HV_ERROR_CODE, HvErrorCode.NAMING_EXCEPTION.toString()); getServletResponse().setHeader(X_HV_ERROR_CODE_DESCRIPTION, e.getMessage()); getServletResponse().setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); }
From source file:de.fiz.ddb.aas.auxiliaryoperations.ThreadOrganisationUpdate.java
private void updateOrg() throws NameNotFoundException, AASUnauthorizedException, AttributeModificationException, ExecutionException {/* ww w . ja v a 2s . c om*/ boolean vChange = false; InitialLdapContext vCtx = null; try { if (this._oldOrganisation == null) { LOG.log(Level.WARNING, "No such organization ''{0}'' with oid: ''{1}''.", new Object[] { this._organisation.getDisplayName(), this._organisation.getOIDs() }); throw new NameNotFoundException("No such organization '" + this._organisation.getDisplayName() + "' with oid: '" + this._organisation.getOIDs() + "'."); } GeoAdresse vGeoAdresse; String vLocalDispalyName = null; if (_submit != null) { // hier ist "GeoLocationDisplayName" breits ausgefhrt try { vGeoAdresse = _submit.get(10, TimeUnit.SECONDS); if (vGeoAdresse.getRequestStatus() == GeoRequestStatus.OK) { this._organisation.getAddress().setLatitude(vGeoAdresse.getLatitude()); this._organisation.getAddress().setLongitude(vGeoAdresse.getLongitude()); this._organisation.getAddress() .setLocationDisplayName(vGeoAdresse.getLocationDisplayName()); } else { LOG.log(Level.WARNING, "GeoRequestStatus: {0}, (organization id: {1})", new Object[] { vGeoAdresse.getRequestStatus(), this._organisation.getOIDs() }); } } catch (InterruptedException ex) { LOG.log(Level.WARNING, "Geocoding request exeption for organization id: " + this._organisation.getOIDs(), ex); } catch (TimeoutException ex) { LOG.log(Level.WARNING, "Geocoding request exeption for organization id: " + this._organisation.getOIDs(), ex); } } else if (_submitGeoLocDisplayName != null) { try { vLocalDispalyName = _submitGeoLocDisplayName.get(5, TimeUnit.SECONDS); this._organisation.getAddress().setLocationDisplayName(vLocalDispalyName); //LOG.info("LocalDisplayName='" + vLocalDispalyName + "'" + vLocalDispalyName + "'"); } catch (InterruptedException ex) { LOG.log(Level.WARNING, this._organisation.getOIDs() + " without location display name: " + ex.getMessage()); } catch (ExecutionException ex) { LOG.log(Level.WARNING, this._organisation.getOIDs() + " without location display name: " + ex.getMessage()); } catch (TimeoutException ex) { LOG.log(Level.WARNING, this._organisation.getOIDs() + " without location display name: " + ex.getMessage()); } } LOG.info("newOIDs: '" + this._organisation.getOIDs() + "'"); LOG.info("oldOIDs: '" + this._oldOrganisation.getOIDs() + "'"); if (this._organisation.getOrgRDN() == null) { // -- Ansonsten eine nicht gesetzte RDN kann zum Knall fhren... this._organisation.setOrgRDN(this._oldOrganisation.getOrgRDN()); } else if (!this._organisation.getOrgRDN().equals(this._oldOrganisation.getOrgRDN())) { // -- Hier ist etwas faul... LOG.log(Level.WARNING, "The organization ''{0}'' has RDN: ''{1}'', but there exist an organization ''{0}'' with RDN: ''{2}''!", new Object[] { this._organisation.getId(), this._organisation.getOrgRDN(), this._oldOrganisation.getOrgRDN() }); throw new NameNotFoundException("No such organization '" + this._organisation.getDisplayName() + "' with oid: '" + this._organisation.getOIDs() + "'."); } if (this.isPrivilegesUpdate()) { Set<PrivilegeEnum> removePrivileges = this.privilegeDiff(this._organisation.getPrivilegesSet(), this._oldOrganisation.getPrivilegesSet()); Set<PrivilegeEnum> addPrivileges = this.privilegeDiff(this._oldOrganisation.getPrivilegesSet(), this._organisation.getPrivilegesSet()); if (!removePrivileges.isEmpty() || !addPrivileges.isEmpty()) { vChange = true; for (PrivilegeEnum p : removePrivileges) { ThreadSinglePrivilegeDelete threadSinglePrivilegeDelete = new ThreadSinglePrivilegeDelete(p, this._organisation, this._performer); threadSinglePrivilegeDelete.call(); } for (PrivilegeEnum p : addPrivileges) { ThreadSinglePrivilegeCreate threadSinglePrivilegeCreate = new ThreadSinglePrivilegeCreate(p, this._organisation, this._performer); threadSinglePrivilegeCreate.call(); } } } Attributes orgAttributes = new BasicAttributes(true); Attributes orgRemoveAttributes = new BasicAttributes(true); if (vChange = this.convertOrganizationToLdapOrgAttrsForUpdate(this._organisation, this._oldOrganisation, orgAttributes, orgRemoveAttributes, getPerformer())) { // -- If any changes, the status is set to 'revised' // but not if status will be explicitly changed or by a update operation on Licenses directory if (!isChangeOfStatus() && !isUpdatingOfLicensedOrgs()) { if ((ConstEnumOrgStatus.approved.equals(this._organisation.getStatus()))) { // -- ...then go retrospectively into "revised" status: this._organisation.setStatus(ConstEnumOrgStatus.revised); orgAttributes.put(Constants.ldap_ddbOrg_Status, String.valueOf(this._organisation.getStatus().name())); } } } // --------------------------------------------------------------------- if (vChange) { // -- Save changes to the corresponding directory: StringBuilder vOrgEntryDN = (isUpdatingOfLicensedOrgs() ? this.getLicensedOrgsDN(this._organisation.getOIDs()) : this.getOrgDN(this._organisation.getOIDs())); LOG.log(Level.INFO, "DEBUG-Info: destination OrgEntryDN = '" + vOrgEntryDN + "'"); vCtx = LDAPConnector.getSingletonInstance().takeCtx(); if (orgRemoveAttributes.size() > 0) { vCtx.modifyAttributes(vOrgEntryDN.toString(), DirContext.REMOVE_ATTRIBUTE, orgRemoveAttributes); } vCtx.modifyAttributes(vOrgEntryDN.toString(), DirContext.REPLACE_ATTRIBUTE, orgAttributes); } else { throw new AttributeModificationException( "Not modified: oid = '" + this._organisation.getOIDs() + "'"); } } catch (RejectedExecutionException ex) { LOG.log(Level.SEVERE, "RejectedExecutionException\n{0}", ex); throw new ExecutionException(ex.getMessage(), ex.getCause()); } catch (IllegalAccessException ex) { LOG.log(Level.SEVERE, "Connection-Error\n{0}", ex); throw new ExecutionException(ex.getMessage(), ex.getCause()); } catch (NameNotFoundException ex) { LOG.log(Level.WARNING, null, ex); throw ex; } catch (AttributeModificationException ex) { LOG.log(Level.WARNING, "AttributeModificationException\n{0}", ex.getMessage()); // !!!!AttributeModificationException extends NamingExeption: //throw ex; throw new AttributeModificationException(ex.getMessage()); } catch (NamingException ne) { LOG.log(Level.SEVERE, "NamingException\n{0}", ne); throw new ExecutionException(ne.getMessage(), ne.getCause()); } finally { if (vCtx != null) { try { LDAPConnector.getSingletonInstance().putCtx(vCtx); } catch (Exception ex) { LOG.log(Level.SEVERE, "Exception", ex); } } } }
From source file:org.kawanfw.commons.api.server.DefaultCommonsConfigurator.java
/** * /*from w w w . ja v a2s. c om*/ * Returns a {@code Connection} from <a * href="http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html" >Tomcat * JDBC Connection Pool</a>.<br> * <br> * How the {@code Connection} is extracted depends on KawanSoft framework in use: * <ul> * <li>SQL framework: the {@code Connection} is extracted from the * {@code DataSource} created by the embedded Tomcat JDBC Pool. The JDBC * parameters used to create the {@code DataSource} are defined in the * properties file passed at start-up of the SQL Framework.</li> * <li>FILE framework: the {@code Connection} is extracted from the * {@code DataSource} created by an <a href= * "http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/tomcat/jdbc/pool/DataSourceFactory.html" * ><code>org.apache.tomcat.jdbc.pool.DataSourceFactory</code></a> factory * defined as a {@code 'jdbc/kawanfw-default'} Resource in {@code server.xml} * or {@code context.xml}.<br> * Here is an example: <a href="http://www.kawanfw.org/3.0/src/context.xml">context.xml</a></li> * </ul> * * * @return the {@code Connection} extracted from Tomcat JDBC Connection * Pool. */ @Override public Connection getConnection() throws SQLException { if (dataSource == null) { String servletName = getServletNameFromServletPath(); if (TomcatModeStore.isFrameworkSql()) { // SQL Software dataSource = TomcatModeStore.getDataSource(servletName); if (dataSource == null) { if (TomcatModeStore.isTomcatEmbedded()) { String message = Tag.PRODUCT_USER_CONFIG_FAIL + " the \"driverClassName\" property is not defined in the properties file for servlet " + servletName; ServerLogger.getLogger().log(Level.WARNING, message); throw new SQLException(message); } else { String message = Tag.PRODUCT_USER_CONFIG_FAIL + " the \"driverClassName\" property is not defined in the properties file for servlet " + servletName + " or the servlet name does not match the url pattern in your web.xml"; ServerLogger.getLogger().log(Level.WARNING, message); throw new SQLException(message); } } } else { // FILE Software String defaultResourceName = "jdbc/kawanfw-default"; try { Context initCtx0 = (Context) new InitialContext().lookup("java:comp/env"); dataSource = (DataSource) initCtx0.lookup(defaultResourceName); } catch (NamingException e) { String message = Tag.PRODUCT_USER_CONFIG_FAIL + " Invalid <Resource> configuration. Lookup failed on Resource: " + defaultResourceName + " Reason: " + e.getMessage(); throw new SQLException(message, e); } } } Connection connection = dataSource.getConnection(); return connection; }
From source file:com.heliumv.api.BaseApi.java
public Response getUnavailable(NamingException e) { return getResponseBuilder().status(Response.Status.INTERNAL_SERVER_ERROR) .header(X_HV_ERROR_CODE, HvErrorCode.NAMING_EXCEPTION.toString()) .header(X_HV_ERROR_CODE_DESCRIPTION, e.getMessage()).build(); }
From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.factory.JMSConnectionFactory.java
public JMSConnectionFactory(Properties properties) { try {// ww w. j a va 2 s . c om ctx = new InitialContext(properties); } catch (NamingException e) { logger.error("NamingException while obtaining initial context. " + e.getMessage(), e); } String connectionFactoryType = properties.getProperty(JMSConstants.CONNECTION_FACTORY_TYPE); if ("topic".equals(connectionFactoryType)) { this.destinationType = JMSConstants.JMSDestinationType.TOPIC; } else { this.destinationType = JMSConstants.JMSDestinationType.QUEUE; } if (properties.getProperty(JMSConstants.PARAM_JMS_SPEC_VER) == null || JMSConstants.JMS_SPEC_VERSION_1_1 .equals(properties.getProperty(JMSConstants.PARAM_JMS_SPEC_VER))) { jmsSpec = JMSConstants.JMS_SPEC_VERSION_1_1; } else if (JMSConstants.JMS_SPEC_VERSION_2_0 .equals(properties.getProperty(JMSConstants.PARAM_JMS_SPEC_VER))) { jmsSpec = JMSConstants.JMS_SPEC_VERSION_2_0; } else { jmsSpec = JMSConstants.JMS_SPEC_VERSION_1_0; } if ("true".equalsIgnoreCase(properties.getProperty(JMSConstants.PARAM_IS_SHARED_SUBSCRIPTION))) { isSharedSubscription = true; } else { isSharedSubscription = false; } noPubSubLocal = Boolean.valueOf(properties.getProperty(JMSConstants.PARAM_PUBSUB_NO_LOCAL)); clientId = properties.getProperty(JMSConstants.PARAM_DURABLE_SUB_CLIENT_ID); subscriptionName = properties.getProperty(JMSConstants.PARAM_DURABLE_SUB_NAME); if (isSharedSubscription) { if (subscriptionName == null) { logger.info("Subscription name is not given. Therefor declaring a non-shared subscription"); isSharedSubscription = false; } } String subDurable = properties.getProperty(JMSConstants.PARAM_SUB_DURABLE); if (subDurable != null) { isDurable = Boolean.parseBoolean(subDurable); } String msgSelector = properties.getProperty(JMSConstants.PARAM_MSG_SELECTOR); if (msgSelector != null) { messageSelector = msgSelector; } this.connectionFactoryString = properties.getProperty(JMSConstants.CONNECTION_FACTORY_JNDI_NAME); if (connectionFactoryString == null || "".equals(connectionFactoryString)) { connectionFactoryString = "QueueConnectionFactory"; } this.destinationName = properties.getProperty(JMSConstants.DESTINATION_NAME); if (destinationName == null || "".equals(destinationName)) { destinationName = "QUEUE_" + System.currentTimeMillis(); } String strTransactedSession = properties.getProperty(JMSConstants.SESSION_TRANSACTED); if (strTransactedSession == null || "".equals(strTransactedSession) || !strTransactedSession.equals("true")) { transactedSession = false; } else if ("true".equals(strTransactedSession)) { transactedSession = true; } String strSessionAck = properties.getProperty(JMSConstants.SESSION_ACK); if (null == strSessionAck) { sessionAckMode = 1; } else if (strSessionAck.equals("AUTO_ACKNOWLEDGE")) { sessionAckMode = Session.AUTO_ACKNOWLEDGE; } else if (strSessionAck.equals("CLIENT_ACKNOWLEDGE")) { sessionAckMode = Session.CLIENT_ACKNOWLEDGE; } else if (strSessionAck.equals("DUPS_OK_ACKNOWLEDGE")) { sessionAckMode = Session.DUPS_OK_ACKNOWLEDGE; } else if (strSessionAck.equals("SESSION_TRANSACTED")) { sessionAckMode = Session.SESSION_TRANSACTED; } else { sessionAckMode = 1; } createConnectionFactory(); }