List of usage examples for javax.naming NamingException getMessage
public String getMessage()
From source file:org.sonar.plugins.ldap.LdapAuthenticator.java
private boolean checkPasswordUsingBind(String principal, String password, String ldapKey) { if (StringUtils.isEmpty(password)) { LOG.debug("Password is blank."); return false; }// www . j a v a2s .c o m InitialDirContext context = null; try { context = contextFactories.get(ldapKey).createUserContext(principal, password); return true; } catch (NamingException e) { LOG.debug("Password not valid for user {} in server {}: {}", principal, ldapKey, e.getMessage()); return false; } finally { ContextHelper.closeQuietly(context); } }
From source file:org.dspace.services.email.EmailServiceImpl.java
@Override public void init() { // See if there is already a Session in our environment String sessionName = cfg.getProperty("mail.session.name"); if (null == sessionName) { sessionName = "Session"; }/*w ww. j a va 2 s .co m*/ try { InitialContext ctx = new InitialContext(null); session = (Session) ctx.lookup("java:comp/env/mail/" + sessionName); } catch (NamingException ex) { logger.warn("Couldn't get an email session from environment: {}", ex.getMessage()); } if (null != session) { logger.info("Email session retrieved from environment."); } else { // No Session provided, so create one logger.info("Initializing an email session from configuration."); Properties props = new Properties(); props.put("mail.transport.protocol", "smtp"); String host = cfg.getProperty("mail.server"); if (null != host) { props.put("mail.host", cfg.getProperty("mail.server")); } String port = cfg.getProperty("mail.server.port"); if (null != port) { props.put("mail.smtp.port", port); } if (null == cfg.getProperty("mail.server.username")) { session = Session.getInstance(props); } else { props.put("mail.smtp.auth", "true"); session = Session.getInstance(props, this); } // Set extra configuration properties String extras = cfg.getProperty("mail.extraproperties"); if ((extras != null) && (!"".equals(extras.trim()))) { String arguments[] = extras.split(","); String key, value; for (String argument : arguments) { key = argument.substring(0, argument.indexOf('=')).trim(); value = argument.substring(argument.indexOf('=') + 1).trim(); props.put(key, value); } } } }
From source file:org.qualipso.funkyfactory.test.clock.functionnal.ClockServiceFunctionalTest.java
/** * Test the getTime ClockService unauthentified *///from ww w . j av a2 s . co m @Test public void testGetTimeUnauthentified() { logger.debug("Testing ClockService unauthentified"); try { messageTest(); } catch (NamingException e) { logger.error("Problem when doing the service lookup"); logger.error(e.getMessage(), e); fail(e.getMessage()); } catch (ClockServiceException e) { logger.error("Problem when calling the service"); logger.error(e.getMessage(), e); fail(e.getMessage()); } }
From source file:org.sonar.plugins.ldap.LdapAuthenticator.java
/** * Authenticate the user against LDAP servers until first success. * @param login The login to use.//from w ww .j av a2s .c o m * @param password The password to use. * @return false if specified user cannot be authenticated with specified password on any LDAP server */ public boolean authenticate(String login, String password) { for (String ldapKey : userMappings.keySet()) { final String principal; if (contextFactories.get(ldapKey).isSasl()) { principal = login; } else { final SearchResult result; try { result = userMappings.get(ldapKey).createSearch(contextFactories.get(ldapKey), login) .findUnique(); } catch (NamingException e) { LOG.debug("User {} not found in server {}: {}", login, ldapKey, e.getMessage()); continue; } if (result == null) { LOG.debug("User {} not found in {}", login, ldapKey); continue; } principal = result.getNameInNamespace(); } boolean passwordValid; if (contextFactories.get(ldapKey).isGssapi()) { passwordValid = checkPasswordUsingGssapi(principal, password, ldapKey); } else { passwordValid = checkPasswordUsingBind(principal, password, ldapKey); } if (passwordValid) { return true; } } LOG.debug("User {} not found", login); return false; }
From source file:org.codehaus.plexus.redback.authentication.ldap.LdapBindAuthenticator.java
private void closeNamingEnumeration(NamingEnumeration<SearchResult> results) { try {/* w w w. jav a 2 s. co m*/ if (results != null) { results.close(); } } catch (NamingException e) { log.warn("skip exception closing naming search result " + e.getMessage()); } }
From source file:org.projectforge.business.ldap.LdapConnector.java
public LdapContext createContext() { init();/*from w w w .j av a2 s.c o m*/ final Hashtable<String, String> env; final String authentication = ldapConfig.getAuthentication(); if ("none".equals(authentication) == false) { env = createEnv(ldapConfig.getManagerUser(), ldapConfig.getManagerPassword()); } else { env = createEnv(null, null); } try { final LdapContext ctx = new InitialLdapContext(env, null); return ctx; } catch (final NamingException ex) { log.error("While trying to connect LDAP initally: " + ex.getMessage(), ex); throw new RuntimeException(ex); } }
From source file:org.cauldron.execution.ContextUtils.java
public Task find(String name) { try {/*ww w. j a va2s. c om*/ InitialContext ic = new InitialContext(); return (Task) ic.lookup(prefix + name); } catch (NamingException e) { ContextImpl.log.error("JNDI exception while finding task named " + name + " : " + e.getMessage()); return null; } }
From source file:org.apache.archiva.redback.authentication.ldap.LdapBindAuthenticator.java
private void closeNamingEnumeration(NamingEnumeration<SearchResult> results) { try {/*from www . j ava2s .c o m*/ if (results != null) { results.close(); } } catch (NamingException e) { log.warn("skip exception closing naming search result {}", e.getMessage()); } }
From source file:com.jaeksoft.searchlib.renderer.plugin.AuthPluginNtlm.java
@Override public User getUser(Renderer renderer, HttpServletRequest request) throws IOException { String remoteUser = request.getRemoteUser(); if (remoteUser == null) remoteUser = request.getHeader("X-OSS-REMOTE-USER"); ActiveDirectory activeDirectory = null; if (StringUtils.isEmpty(remoteUser)) throw new AuthException("No user"); int i = remoteUser.indexOf('@'); if (i != -1)// w ww . j a v a 2 s .c o m remoteUser = remoteUser.substring(0, i); try { String domain = renderer.getAuthDomain(); User user = AuthUserCache.INSTANCE.get(remoteUser, domain); if (user != null) return user; NtlmPasswordAuthentication ntlmAuth = getNtlmAuth(renderer, null, null); activeDirectory = new ActiveDirectory(ntlmAuth.getUsername(), ntlmAuth.getPassword(), ntlmAuth.getDomain()); NamingEnumeration<SearchResult> result = activeDirectory.findUser(remoteUser); Attributes attrs = ActiveDirectory.getAttributes(result); if (attrs == null) throw new AuthException("No user found: " + remoteUser); String userId = ActiveDirectory.getObjectSID(attrs); List<ADGroup> groups = new ArrayList<ADGroup>(); activeDirectory.findUserGroups(attrs, groups); String dnUser = ActiveDirectory.getStringAttribute(attrs, "DistinguishedName"); activeDirectory.findUserGroup(dnUser, groups); user = new User(userId, remoteUser, null, ActiveDirectory.toArray(groups), ActiveDirectory.getDisplayString(domain, remoteUser)); Logging.info("USER authenticated: " + user + " DN=" + dnUser); AuthUserCache.INSTANCE.add(remoteUser, domain, user); return user; } catch (NamingException e) { Logging.warn(e); throw new AuthException("LDAP error (NamingException) : " + e.getMessage()); } finally { IOUtils.close(activeDirectory); } }
From source file:org.josso.gateway.assertion.service.store.db.DataSourceAssertionStore.java
/** * Lazy load the datasource instace used by this store. * * @throws org.josso.gateway.assertion.exceptions.AssertionException * *//*ww w . j a va 2 s.c o m*/ protected synchronized DataSource getDataSource() throws AssertionException { if (_datasource == null) { try { if (logger.isDebugEnabled()) logger.debug("[getDatasource() : ]" + _dsJndiName); InitialContext ic = new InitialContext(); _datasource = (DataSource) ic.lookup(_dsJndiName); } catch (NamingException ne) { logger.error("Error during DB connection lookup", ne); throw new AssertionException("Error During Lookup\n" + ne.getMessage()); } } return _datasource; }