List of usage examples for javax.naming NamingException getMessage
public String getMessage()
From source file:de.highbyte_le.weberknecht.ControllerCore.java
private static DbConnectionProvider initDbConnectionProvider() { DbConnectionProvider dbConnectionProvider = null; try {// w w w . j a v a 2 s.c o m dbConnectionProvider = new DefaultWebDbConnectionProvider2("jdbc/mydb"); } catch (NamingException e) { if (log.isInfoEnabled()) log.info("jdbc/mydb not configured (" + e.getMessage() + ")"); //$NON-NLS-1$ } return dbConnectionProvider; }
From source file:org.signserver.admin.gui.SignServerAdminGUIApplication.java
/** * @return The administration interface either EJB remote or web services. *//*from w ww . jav a 2s. c o m*/ public static AdminWS getAdminWS() { if (adminWS == null) { CertTools.installBCProvider(); final ConnectDialog dlg = new ConnectDialog(null, true, connectFile, defaultConnectFile, baseDir, Protocol.WS == protocol); dlg.setVisible(true); protocol = dlg.getProtocol(); if (Protocol.WS == protocol) { adminWS = dlg.getWS(); serverHost = dlg.getServerHost(); adminCertificate = dlg.getAdminCertificate(); } else { try { adminWS = new AdminLayerEJBImpl(); serverHost = "local"; } catch (NamingException ex) { LOG.error("Startup error", ex); JOptionPane.showMessageDialog(null, "Startup failed. Are the application server running?\n" + ex.getMessage(), "SignServer Administration GUI startup", JOptionPane.ERROR_MESSAGE); System.exit(1); } } } return adminWS; }
From source file:org.jkcsoft.java.util.JndiHelper.java
public static void logLdap(Log plog, int level, int nth, Object dirEntry) throws NamingException { try {/*from w ww. j a va 2 s .c om*/ if (dirEntry instanceof NamingEnumeration) { NamingEnumeration nameEnum = (NamingEnumeration) dirEntry; JndiHelper.logLevel(plog, level, nth, "Naming Enumeration: " + nameEnum); try { int nthThis = 0; List nameList = new Vector(Collections.list(nameEnum)); Collections.sort(nameList, new Comparator() { public int compare(Object o1, Object o2) { if (o1 instanceof Attribute) { return String.CASE_INSENSITIVE_ORDER.compare(((Attribute) o1).getID(), ((Attribute) o2).getID()); } return 0; } }); Iterator nameIter = nameList.iterator(); while (nameIter.hasNext()) { logLdap(plog, level + 1, nthThis++, nameIter.next()); } } catch (NamingException ex) { plog.error("Exception iterating thru NamingEnumeration: " + ex.getMessage()); } } else if (dirEntry instanceof Attribute) { Attribute dirAttr = (Attribute) dirEntry; JndiHelper.logLevel(plog, level, nth, "Attribute: [" + dirAttr + "]"); } else if (dirEntry instanceof DirContext) { DirContext lctx = (DirContext) dirEntry; JndiHelper.logLevel(plog, level, nth, "LDAP Context: DN [" + lctx.getNameInNamespace() + "]" + " Attributes ==>"); logLdap(plog, level, nth, lctx.getAttributes("").getAll()); } else if (dirEntry instanceof SearchResult) { SearchResult sr = (SearchResult) dirEntry; JndiHelper.logLevel(plog, level, nth, "SearchResult: ClassName of Bound Object [" + sr.getClassName() + "]" + " Name: [" + sr.getName() + "]" + " Bound Object ==>"); // sr.s logLdap(plog, level, nth, sr.getObject()); logLdap(plog, level, nth, sr.getAttributes().getAll()); } else { JndiHelper.logLevel(plog, level, nth, "(?) class of entry: [" + dirEntry + "]"); } nth++; } catch (NamingException e1) { plog.error("Naming Exception (will try to continue): " + e1.getMessage()); } }
From source file:org.easy.ldap.LdapDao.java
/** * @param attributes/* w w w.ja va 2s.co m*/ * @return */ public static LdapUser toModel(String tenantId, Attributes attributes) { LdapUser out = null; try { out = new LdapUser(tenantId, attributes.get(RdnType.UID.toString()).get().toString()); out.setCommonName(attributes.get(RdnType.CN.toString()).get().toString()); out.setGivenName(attributes.get(RdnType.GIVEN_NAME.toString()).get().toString()); out.setSurname(attributes.get(RdnType.SN.toString()).get().toString()); out.setEmail(attributes.get(RdnType.MAIL.toString()).get().toString()); } catch (NamingException e) { log.error(e.getMessage(), e); } return out; }
From source file:security.AuthenticationManager.java
public static void authenticateUser(String userName, String password) throws NamingException, SQLException { if (userName == null || userName.isEmpty() || password == null || password.isEmpty()) { throw new IllegalArgumentException("Username and password can not be blank."); }//from w w w.j av a 2s . c o m if (UserDAO.authenticate(userName, password)) { UserDAO.insertLoginHistory(userName, "default", "SUCCESS", null); return; } final String contextFactories = Play.application().configuration() .getString(LDAP_CONTEXT_FACTORY_CLASS_KEY); /* three LDAP properties, each is a '|' separated string of same number of tokens. e.g. Url: "ldaps://ldap1.abc.com:1234|ldap://ldap2.abc.com:5678" Principal Domain: "@abc.com|@abc.cn" Search Base: "ou=Staff Users,dc=abc,dc=com|ou=Staff Users,dc=abc,dc=cn" */ final String[] ldapUrls = Play.application().configuration().getString(MASTER_LDAP_URL_KEY) .split("\\s*\\|\\s*"); final String[] principalDomains = Play.application().configuration().getString(MASTER_PRINCIPAL_DOMAIN_KEY) .split("\\s*\\|\\s*"); final String[] ldapSearchBase = Play.application().configuration().getString(LDAP_SEARCH_BASE_KEY) .split("\\s*\\|\\s*"); DirContext ctx = null; int i; for (i = 0; i < ldapUrls.length; i++) { try { Hashtable<String, String> env = buildEnvContext(userName, password, contextFactories, ldapUrls[i], principalDomains[i]); ctx = new InitialDirContext(env); if (!UserDAO.userExist(userName)) { User user = getAttributes(ctx, ldapSearchBase[i], userName, principalDomains[i]); UserDAO.addLdapUser(user); } break; } catch (NamingException e) { // Logger.error("Ldap authentication failed for user " + userName + " - " + principalDomains[i] + " - " + ldapUrls[i], e); // if exhausted all ldap options and can't authenticate user if (i >= ldapUrls.length - 1) { UserDAO.insertLoginHistory(userName, "LDAP", "FAILURE", e.getMessage()); throw e; } } catch (SQLException e) { // Logger.error("Ldap authentication SQL error for user: " + userName, e); UserDAO.insertLoginHistory(userName, "LDAP", "FAILURE", ldapUrls[i] + e.getMessage()); throw e; } finally { if (ctx != null) { ctx.close(); } } } UserDAO.insertLoginHistory(userName, "LDAP", "SUCCESS", ldapUrls[i]); }
From source file:com.ikon.module.jcr.stuff.JCRUtils.java
/** * Get JCR Session/* w ww. j a va 2s . c o m*/ */ public static Session getSession() throws javax.jcr.LoginException, javax.jcr.RepositoryException, DatabaseException { Subject subject = null; Object obj = null; // Resolve subject // Subject userSubject=(Subject)PolicyContext.getContext("javax.security.auth.Subject.container"); if (EnvironmentDetector.isServerJBoss()) { try { InitialContext ctx = new InitialContext(); subject = (Subject) ctx.lookup("java:/comp/env/security/subject"); ctx.close(); } catch (NamingException e) { throw new javax.jcr.LoginException(e.getMessage()); } } else if (EnvironmentDetector.isServerTomcat()) { subject = Subject.getSubject(AccessController.getContext()); } // Obtain JCR session if (subject != null) { obj = Subject.doAs(subject, new PrivilegedAction<Object>() { public Object run() { Session s = null; try { s = JcrRepositoryModule.getRepository().login(); } catch (javax.jcr.LoginException e) { return e; } catch (javax.jcr.RepositoryException e) { return e; } return s; } }); } // Validate JCR session if (obj instanceof javax.jcr.LoginException) { throw (javax.jcr.LoginException) obj; } else if (obj instanceof javax.jcr.RepositoryException) { throw (javax.jcr.RepositoryException) obj; } else if (obj instanceof javax.jcr.Session) { Session session = (javax.jcr.Session) obj; log.debug("#{} - {} Create session {} from {}", new Object[] { ++sessionCreationCount, ++activeSessions, session, StackTraceUtils.whoCalledMe() }); JcrAuthModule.loadUserData(session); return session; } else { return null; } }
From source file:com.cws.esolutions.core.utils.EmailUtils.java
/** * Processes and sends an email message as generated by the requesting * application. This method is utilized with a JNDI datasource. * * @param mailConfig - The {@link com.cws.esolutions.core.config.xml.MailConfig} to utilize * @param message - The email message/* ww w. j av a 2s. c o m*/ * @param isWeb - <code>true</code> if this came from a container, <code>false</code> otherwise * @throws MessagingException {@link javax.mail.MessagingException} if an exception occurs sending the message */ public static final synchronized void sendEmailMessage(final MailConfig mailConfig, final EmailMessage message, final boolean isWeb) throws MessagingException { final String methodName = EmailUtils.CNAME + "#sendEmailMessage(final MailConfig mailConfig, final EmailMessage message, final boolean isWeb) throws MessagingException"; Session mailSession = null; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", mailConfig); DEBUGGER.debug("Value: {}", message); DEBUGGER.debug("Value: {}", isWeb); } SMTPAuthenticator smtpAuth = null; if (DEBUG) { DEBUGGER.debug("MailConfig: {}", mailConfig); } try { if (isWeb) { Context initContext = new InitialContext(); Context envContext = (Context) initContext.lookup(EmailUtils.INIT_DS_CONTEXT); if (DEBUG) { DEBUGGER.debug("InitialContext: {}", initContext); DEBUGGER.debug("Context: {}", envContext); } if (envContext != null) { mailSession = (Session) envContext.lookup(mailConfig.getDataSourceName()); } } else { Properties mailProps = new Properties(); try { mailProps.load( EmailUtils.class.getClassLoader().getResourceAsStream(mailConfig.getPropertyFile())); } catch (NullPointerException npx) { try { mailProps.load(new FileInputStream(mailConfig.getPropertyFile())); } catch (IOException iox) { throw new MessagingException(iox.getMessage(), iox); } } catch (IOException iox) { throw new MessagingException(iox.getMessage(), iox); } if (DEBUG) { DEBUGGER.debug("Properties: {}", mailProps); } if (StringUtils.equals((String) mailProps.get("mail.smtp.auth"), "true")) { smtpAuth = new SMTPAuthenticator(); mailSession = Session.getDefaultInstance(mailProps, smtpAuth); } else { mailSession = Session.getDefaultInstance(mailProps); } } if (DEBUG) { DEBUGGER.debug("Session: {}", mailSession); } if (mailSession == null) { throw new MessagingException("Unable to configure email services"); } mailSession.setDebug(DEBUG); MimeMessage mailMessage = new MimeMessage(mailSession); // Our emailList parameter should contain the following // items (in this order): // 0. Recipients // 1. From Address // 2. Generated-From (if blank, a default value is used) // 3. The message subject // 4. The message content // 5. The message id (optional) // We're only checking to ensure that the 'from' and 'to' // values aren't null - the rest is really optional.. if // the calling application sends a blank email, we aren't // handing it here. if (message.getMessageTo().size() != 0) { for (String to : message.getMessageTo()) { if (DEBUG) { DEBUGGER.debug(to); } mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); } mailMessage.setFrom(new InternetAddress(message.getEmailAddr().get(0))); mailMessage.setSubject(message.getMessageSubject()); mailMessage.setContent(message.getMessageBody(), "text/html"); if (message.isAlert()) { mailMessage.setHeader("Importance", "High"); } Transport mailTransport = mailSession.getTransport("smtp"); if (DEBUG) { DEBUGGER.debug("Transport: {}", mailTransport); } mailTransport.connect(); if (mailTransport.isConnected()) { Transport.send(mailMessage); } } } catch (MessagingException mex) { throw new MessagingException(mex.getMessage(), mex); } catch (NamingException nx) { throw new MessagingException(nx.getMessage(), nx); } }
From source file:com.cws.esolutions.security.utils.DAOInitializer.java
/** * @param properties - The <code>AuthRepo</code> object containing connection information * @param isContainer - A <code>boolean</code> flag indicating if this is in a container * @param bean - The {@link com.cws.esolutions.security.SecurityServiceBean} <code>SecurityServiceBean</code> that holds the connection * @throws SecurityServiceException {@link com.cws.esolutions.security.exception.SecurityServiceException} * if an exception occurs opening the connection *//*from w w w . ja va 2s . co m*/ public synchronized static void configureAndCreateAuthConnection(final InputStream properties, final boolean isContainer, final SecurityServiceBean bean) throws SecurityServiceException { String methodName = DAOInitializer.CNAME + "#configureAndCreateAuthConnection(final String properties, final boolean isContainer, final SecurityServiceBean bean) throws SecurityServiceException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("InputStream: {}", properties); DEBUGGER.debug("isContainer: {}", isContainer); DEBUGGER.debug("SecurityServiceBean: {}", bean); } try { Properties connProps = new Properties(); connProps.load(properties); if (DEBUG) { DEBUGGER.debug("Properties: {}", connProps); } AuthRepositoryType repoType = AuthRepositoryType .valueOf(connProps.getProperty(DAOInitializer.REPO_TYPE)); RepositoryConnectionType connType = RepositoryConnectionType .valueOf(connProps.getProperty(DAOInitializer.CONN_TYPE)); if (DEBUG) { DEBUGGER.debug("AuthRepositoryType: {}", repoType); DEBUGGER.debug("RepositoryConnectionType: {}", connType); } switch (repoType) { case LDAP: SSLUtil sslUtil = null; LDAPConnection ldapConn = null; LDAPConnectionPool connPool = null; LDAPConnectionOptions connOpts = new LDAPConnectionOptions(); connOpts.setAutoReconnect(true); connOpts.setAbandonOnTimeout(true); connOpts.setBindWithDNRequiresPassword(true); connOpts.setConnectTimeoutMillis( Integer.parseInt(connProps.getProperty(DAOInitializer.CONN_TIMEOUT))); connOpts.setResponseTimeoutMillis( Integer.parseInt(connProps.getProperty(DAOInitializer.READ_TIMEOUT))); if (DEBUG) { DEBUGGER.debug("LDAPConnectionOptions: {}", connOpts); } switch (connType) { case CONNECTION_TYPE_INSECURE: ldapConn = new LDAPConnection(connOpts, connProps.getProperty(DAOInitializer.REPOSITORY_HOST), Integer.parseInt(connProps.getProperty(DAOInitializer.REPOSITORY_PORT))); if (DEBUG) { DEBUGGER.debug("LDAPConnection: {}", ldapConn); } if (!(ldapConn.isConnected())) { throw new LDAPException(ResultCode.CONNECT_ERROR, "Failed to establish an LDAP connection"); } connPool = new LDAPConnectionPool(ldapConn, Integer.parseInt(connProps.getProperty(DAOInitializer.MIN_CONNECTIONS)), Integer.parseInt(connProps.getProperty(DAOInitializer.MAX_CONNECTIONS))); break; case CONNECTION_TYPE_SSL: sslUtil = new SSLUtil(new TrustStoreTrustManager( connProps.getProperty(DAOInitializer.TRUST_FILE), PasswordUtils .decryptText(connProps.getProperty(DAOInitializer.TRUST_PASS), connProps.getProperty(DAOInitializer.TRUST_SALT), secConfig.getSecretAlgorithm(), secConfig.getIterations(), secConfig.getKeyBits(), secConfig.getEncryptionAlgorithm(), secConfig.getEncryptionInstance(), systemConfig.getEncoding()) .toCharArray(), connProps.getProperty(DAOInitializer.TRUST_TYPE), true)); if (DEBUG) { DEBUGGER.debug("SSLUtil: {}", sslUtil); } SSLSocketFactory sslSocketFactory = sslUtil.createSSLSocketFactory(); if (DEBUG) { DEBUGGER.debug("SSLSocketFactory: {}", sslSocketFactory); } ldapConn = new LDAPConnection(sslSocketFactory, connOpts, connProps.getProperty(DAOInitializer.REPOSITORY_HOST), Integer.parseInt(connProps.getProperty(DAOInitializer.REPOSITORY_PORT))); if (DEBUG) { DEBUGGER.debug("LDAPConnection: {}", ldapConn); } if (!(ldapConn.isConnected())) { throw new LDAPException(ResultCode.CONNECT_ERROR, "Failed to establish an LDAP connection"); } connPool = new LDAPConnectionPool(ldapConn, Integer.parseInt(connProps.getProperty(DAOInitializer.MIN_CONNECTIONS)), Integer.parseInt(connProps.getProperty(DAOInitializer.MAX_CONNECTIONS))); break; case CONNECTION_TYPE_TLS: ldapConn = new LDAPConnection(connOpts, connProps.getProperty(DAOInitializer.REPOSITORY_HOST), Integer.parseInt(connProps.getProperty(DAOInitializer.REPOSITORY_PORT))); if (DEBUG) { DEBUGGER.debug("LDAPConnection: {}", ldapConn); } if (!(ldapConn.isConnected())) { throw new LDAPException(ResultCode.CONNECT_ERROR, "Failed to establish an LDAP connection"); } sslUtil = new SSLUtil(new TrustStoreTrustManager( connProps.getProperty(DAOInitializer.TRUST_FILE), PasswordUtils .decryptText(connProps.getProperty(DAOInitializer.TRUST_PASS), connProps.getProperty(DAOInitializer.TRUST_SALT), secConfig.getSecretAlgorithm(), secConfig.getIterations(), secConfig.getKeyBits(), secConfig.getEncryptionAlgorithm(), secConfig.getEncryptionInstance(), systemConfig.getEncoding()) .toCharArray(), connProps.getProperty(DAOInitializer.TRUST_TYPE), true)); if (DEBUG) { DEBUGGER.debug("SSLUtil: {}", sslUtil); } SSLContext sslContext = sslUtil.createSSLContext(); if (DEBUG) { DEBUGGER.debug("SSLContext: {}", sslContext); } StartTLSExtendedRequest startTLS = new StartTLSExtendedRequest(sslContext); if (DEBUG) { DEBUGGER.debug("StartTLSExtendedRequest: {}", startTLS); } ExtendedResult extendedResult = ldapConn.processExtendedOperation(startTLS); if (DEBUG) { DEBUGGER.debug("ExtendedResult: {}", extendedResult); } BindRequest bindRequest = new SimpleBindRequest( connProps.getProperty(DAOInitializer.REPOSITORY_USER), PasswordUtils.decryptText(connProps.getProperty(DAOInitializer.TRUST_PASS), connProps.getProperty(DAOInitializer.TRUST_SALT), secConfig.getSecretAlgorithm(), secConfig.getIterations(), secConfig.getKeyBits(), secConfig.getEncryptionAlgorithm(), secConfig.getEncryptionInstance(), systemConfig.getEncoding())); if (DEBUG) { DEBUGGER.debug("BindRequest: {}", bindRequest); } BindResult bindResult = ldapConn.bind(bindRequest); if (DEBUG) { DEBUGGER.debug("BindResult: {}", bindResult); } StartTLSPostConnectProcessor tlsProcessor = new StartTLSPostConnectProcessor(sslContext); if (DEBUG) { DEBUGGER.debug("StartTLSPostConnectProcessor: {}", tlsProcessor); } connPool = new LDAPConnectionPool(ldapConn, Integer.parseInt(connProps.getProperty(DAOInitializer.MIN_CONNECTIONS)), Integer.parseInt(connProps.getProperty(DAOInitializer.MAX_CONNECTIONS)), tlsProcessor); break; } if (DEBUG) { DEBUGGER.debug("LDAPConnectionPool: {}", connPool); } if ((connPool == null) || (connPool.isClosed())) { throw new LDAPException(ResultCode.CONNECT_ERROR, "Failed to establish an LDAP connection"); } bean.setAuthDataSource(connPool); break; case SQL: // the isContainer only matters here if (isContainer) { Context initContext = new InitialContext(); Context envContext = (Context) initContext.lookup(DAOInitializer.DS_CONTEXT); bean.setAuthDataSource(envContext.lookup(DAOInitializer.REPOSITORY_HOST)); } else { BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize( Integer.parseInt(connProps.getProperty(DAOInitializer.MIN_CONNECTIONS))); dataSource .setMaxActive(Integer.parseInt(connProps.getProperty(DAOInitializer.MAX_CONNECTIONS))); dataSource.setDriverClassName(connProps.getProperty(DAOInitializer.CONN_DRIVER)); dataSource.setUrl(connProps.getProperty(DAOInitializer.REPOSITORY_HOST)); dataSource.setUsername(connProps.getProperty(DAOInitializer.REPOSITORY_USER)); dataSource.setPassword(PasswordUtils.decryptText( connProps.getProperty(DAOInitializer.REPOSITORY_PASS), connProps.getProperty(DAOInitializer.REPOSITORY_SALT), secConfig.getSecretAlgorithm(), secConfig.getIterations(), secConfig.getKeyBits(), secConfig.getEncryptionAlgorithm(), secConfig.getEncryptionInstance(), systemConfig.getEncoding())); bean.setAuthDataSource(dataSource); } break; case NONE: return; default: throw new SecurityServiceException("Unhandled ResourceType"); } } catch (LDAPException lx) { throw new SecurityServiceException(lx.getMessage(), lx); } catch (GeneralSecurityException gsx) { throw new SecurityServiceException(gsx.getMessage(), gsx); } catch (NamingException nx) { throw new SecurityServiceException(nx.getMessage(), nx); } catch (FileNotFoundException fnfx) { throw new SecurityServiceException(fnfx.getMessage(), fnfx); } catch (IOException iox) { throw new SecurityServiceException(iox.getMessage(), iox); } }
From source file:com.flexive.shared.EJBLookup.java
/** * Get a reference of the current EJB session context. * * @return the EJB session context// w ww . java2 s . c o m */ public static SessionContext getSessionContext() { try { final InitialContext ctx = new InitialContext(); return (SessionContext) ctx.lookup("java:comp/EJBContext"); } catch (NamingException e) { throw new FxLookupException("Failed to lookup session context: " + e.getMessage(), e) .asRuntimeException(); } }
From source file:com.aurel.track.admin.server.siteConfig.SiteConfigBL.java
public static boolean testLdap(TSiteBean siteApp, String loginName, String ppassword, List<ControlError> errors, Locale locale) {//from w w w . j a va 2s . c o m boolean b = false; try { b = LdapUtil.authenticate(siteApp, loginName, ppassword); } catch (NamingException ex) { LOGGER.error("authenticate failed with " + ex); if (LOGGER.isDebugEnabled()) { LOGGER.error(ExceptionUtils.getStackTrace(ex)); } List<String> controlPath = new LinkedList<String>(); errors.add(new ControlError(controlPath, ex.getMessage())); } if (!b) { List<String> controlPath = new LinkedList<String>(); controlPath.add(LdapTO.JSONFIELDS.tabLdap); controlPath.add(LdapTO.JSONFIELDS.fsLdap); controlPath.addAll(JSONUtility.getPathInHelpWrapper(LdapTO.JSONFIELDS.serverURL)); errors.add(new ControlError(controlPath, getText("admin.server.config.err.invalidLdapServerName", locale))); } return b; }