List of usage examples for javax.naming NamingException NamingException
public NamingException(String explanation)
From source file:org.josso.gateway.identity.service.store.ldap.LDAPIdentityStore.java
/** * Creates an InitialLdapContext by logging into the configured Ldap Server using the configured * username and credential./*from w ww .jav a2 s . c om*/ * * @return the Initial Ldap Context to be used to perform searches, etc. * @throws NamingException LDAP binding error. * @throws IOException */ protected InitialLdapContext createLdapInitialContext(Boolean useBindCredentials) throws NamingException, IOException { String securityPrincipal = getSecurityPrincipal(); if (securityPrincipal == null) securityPrincipal = ""; String securityCredential = getSecurityCredential(); if (securityCredential == null) securityCredential = ""; SSOSession session = SSOContext.getCurrent().getSession(); if (useBindCredentials && session != null) { //String username = session.getUsername(); String username = getUsername(session.getSubject().getPublicCredentials()); securityPrincipal = selectUserDN(username); if (securityPrincipal == null) { // in case of virtual identity store throw new NamingException("User not found."); } securityCredential = getPassword(session.getSubject().getPrivateCredentials()); } return createLdapInitialContext(securityPrincipal, securityCredential); }
From source file:org.jsecurity.jndi.JndiTemplate.java
/** * Look up the object with the given name in the current JNDI context. * * @param name the JNDI name of the object * @param requiredType type the JNDI object must match. Can be an interface or * superclass of the actual class, or <code>null</code> for any match. For example, * if the value is <code>Object.class</code>, this method will succeed whatever * the class of the returned instance. * @return object found (cannot be <code>null</code>; if a not so well-behaved * JNDI implementations returns null, a NamingException gets thrown) * @throws NamingException if there is no object with the given * name bound to JNDI *///from w w w.j a v a 2 s .co m public Object lookup(String name, Class requiredType) throws NamingException { Object jndiObject = lookup(name); if (requiredType != null && !requiredType.isInstance(jndiObject)) { String msg = "Jndi object acquired under name '" + name + "' is of type [" + jndiObject.getClass().getName() + "] and not assignable to the required type [" + requiredType.getName() + "]."; throw new NamingException(msg); } return jndiObject; }
From source file:org.kitodo.production.ldap.LdapUser.java
/** * configure LdapUser with User data.//from w ww . j a v a 2 s . c om * * @param user * User object * @param inPassword * String * @param inUidNumber * String */ public void configure(User user, String inPassword, String inUidNumber) throws NamingException, NoSuchAlgorithmException { MD4 digester = new MD4(); if (!user.getLdapGroup().getLdapServer().isReadOnly()) { if (Objects.nonNull(user.getLdapLogin())) { this.ldapLogin = user.getLdapLogin(); } else { this.ldapLogin = user.getLogin(); } LdapGroup ldapGroup = user.getLdapGroup(); if (Objects.isNull(ldapGroup.getObjectClasses())) { throw new NamingException("no objectclass defined"); } prepareAttributes(ldapGroup, user, inUidNumber); /* * Samba passwords */ /* LanMgr */ try { this.attributes.put("sambaLMPassword", toHexString(lmHash(inPassword))); } catch (InvalidKeyException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException | RuntimeException e) { logger.error(e.getMessage(), e); } /* NTLM */ byte[] hmm = digester.digest(inPassword.getBytes(StandardCharsets.UTF_16LE)); this.attributes.put("sambaNTPassword", toHexString(hmm)); /* * Encryption of password und Base64-Enconding */ String passwordEncrytion = ldapGroup.getLdapServer().getPasswordEncryption().getTitle(); MessageDigest md = MessageDigest.getInstance(passwordEncrytion); md.update(inPassword.getBytes(StandardCharsets.UTF_8)); String encodedDigest = new String(Base64.encodeBase64(md.digest()), StandardCharsets.UTF_8); this.attributes.put("userPassword", "{" + passwordEncrytion + "}" + encodedDigest); } }
From source file:org.lsc.jndi.JndiServices.java
private void initConnection() throws NamingException, IOException { // log new connection with it's details logConnectingTo(connProps);/*from w w w .j a va 2s . c om*/ /* should we negotiate TLS? */ if (connProps.get(TLS_CONFIGURATION) != null && (Boolean) connProps.get(TLS_CONFIGURATION)) { /* if we're going to do TLS, we mustn't BIND before the STARTTLS operation * so we remove credentials from the properties to stop JNDI from binding */ /* duplicate properties to avoid changing them (they are used as a cache key in getInstance() */ Properties localConnProps = new Properties(); localConnProps.putAll(connProps); String jndiContextAuthentication = localConnProps.getProperty(Context.SECURITY_AUTHENTICATION); String jndiContextPrincipal = localConnProps.getProperty(Context.SECURITY_PRINCIPAL); String jndiContextCredentials = localConnProps.getProperty(Context.SECURITY_CREDENTIALS); localConnProps.remove(Context.SECURITY_AUTHENTICATION); localConnProps.remove(Context.SECURITY_PRINCIPAL); localConnProps.remove(Context.SECURITY_CREDENTIALS); /* open the connection */ ctx = new InitialLdapContext(localConnProps, null); /* initiate the STARTTLS extended operation */ try { tlsResponse = (StartTlsResponse) ctx.extendedOperation(new StartTlsRequest()); tlsResponse.negotiate(); } catch (IOException e) { LOGGER.error("Error starting TLS encryption on connection to {}", localConnProps.getProperty(Context.PROVIDER_URL)); LOGGER.debug(e.toString(), e); throw e; } catch (NamingException e) { LOGGER.error("Error starting TLS encryption on connection to {}", localConnProps.getProperty(Context.PROVIDER_URL)); LOGGER.debug(e.toString(), e); throw e; } /* now we add the credentials back to the context, to BIND once TLS is started */ ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, jndiContextAuthentication); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, jndiContextPrincipal); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, jndiContextCredentials); } else { /* don't start TLS, just connect normally (this can be on ldap:// or ldaps://) */ ctx = new InitialLdapContext(connProps, null); } /* get LDAP naming context */ try { namingContext = new LdapUrl((String) ctx.getEnvironment().get(Context.PROVIDER_URL)); } catch (LdapURLEncodingException e) { LOGGER.error(e.toString()); LOGGER.debug(e.toString(), e); throw new NamingException(e.getMessage()); } /* handle options */ contextDn = namingContext.getDn() != null ? namingContext.getDn() : null; String pageSizeStr = (String) ctx.getEnvironment().get("java.naming.ldap.pageSize"); if (pageSizeStr != null) { pageSize = Integer.parseInt(pageSizeStr); } else { pageSize = -1; } sortedBy = (String) ctx.getEnvironment().get("java.naming.ldap.sortedBy"); String recursiveDeleteStr = (String) ctx.getEnvironment().get("java.naming.recursivedelete"); if (recursiveDeleteStr != null) { recursiveDelete = Boolean.parseBoolean(recursiveDeleteStr); } else { recursiveDelete = false; } /* Load SyncRepl response control */ LdapApiService ldapApiService = LdapApiServiceFactory.getSingleton(); ControlFactory<?> factory = new SyncStateValueFactory(ldapApiService); ldapApiService.registerControl(factory); /* Load Persistent Search response control */ factory = new PersistentSearchFactory(ldapApiService); ldapApiService.registerControl(factory); }
From source file:org.mule.transport.ldap.util.DSManager.java
public static IoFilterChainBuilder init(final KeyStore ks) throws NamingException { SSLContext sslCtx;/*from w ww.j ava 2 s .c om*/ try { // Set up key manager factory to use our key store String algorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm"); if (algorithm == null) { algorithm = "SunX509"; } final KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm); kmf.init(ks, "changeit".toCharArray()); // Initialize the SSLContext to work with our key managers. sslCtx = SSLContext.getInstance("TLS"); sslCtx.init(kmf.getKeyManagers(), new TrustManager[] { new ServerX509TrustManager() }, new SecureRandom()); logger.debug("ssl set"); } catch (final Exception e) { throw (NamingException) new NamingException("Failed to create a SSL context.").initCause(e); } final DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder(); chain.addLast("sslFilter", new SSLFilter(sslCtx)); return chain; }
From source file:org.nuxeo.ecm.core.storage.sql.ra.PoolingRepositoryFactory.java
protected static ConnectionManager lookupConnectionManager(RepositoryDescriptor descriptor) throws NamingException { String repositoryName = descriptor.getName(); // Check in container ConnectionManager cm = NuxeoContainer.getConnectionManager(repositoryName); if (cm != null) { return cm; }//from w w w .j ava2s . c o m // Check in JNDI InitialContext context = new InitialContext(); for (String name : CM_NAMES_PREFIXES) { try { cm = (ConnectionManager) context.lookup(name + repositoryName); if (cm != null) { return cm; } } catch (NamingException e) { // try next one } } // Creation from descriptor pool config cm = NuxeoContainer.installConnectionManager(repositoryName, descriptor.getPool()); if (cm != null) { return cm; } throw new NamingException("NuxeoConnectionManager not found in JNDI"); }
From source file:org.nuxeo.runtime.jtajca.NuxeoContainer.java
protected static void uninstall() throws NamingException { if (installContext == null) { throw new RuntimeException("Nuxeo container not installed"); }/*from w w w .j a v a 2s . c o m*/ try { NamingException errors = new NamingException("Cannot shutdown connection managers"); for (ConnectionManagerWrapper cm : connectionManagers.values()) { try { cm.dispose(); } catch (RuntimeException cause) { errors.addSuppressed(cause); } } if (errors.getSuppressed().length > 0) { log.error("Cannot shutdown some pools", errors); throw errors; } } finally { log.trace("Uninstalling nuxeo container", installContext); installContext = null; rootContext = null; tm = null; tmRecoverable = null; tmSynchRegistry = null; ut = null; connectionManagers.clear(); } }
From source file:org.nuxeo.runtime.jtajca.NuxeoContainer.java
public static <T> T lookup(String name, Class<T> type) throws NamingException { if (rootContext == null) { throw new NamingException("no naming context available"); }// w w w.ja v a2s.c o m return lookup(rootContext, name, type); }
From source file:org.nuxeo.runtime.transaction.TransactionHelper.java
/** * Looks up the User Transaction in JNDI. * * @return the User Transaction/*w ww. ja v a 2 s .c o m*/ * @throws NamingException if not found */ public static UserTransaction lookupUserTransaction() throws NamingException { UserTransaction ut = NuxeoContainer.getUserTransaction(); if (ut == null) { throw new NamingException("tx manager not installed"); } return ut; }
From source file:org.nuxeo.runtime.transaction.TransactionHelper.java
/** * Looks up the TransactionManager in JNDI. * * @return the TransactionManager/*from w w w. j a v a 2s . c om*/ * @throws NamingException if not found */ public static TransactionManager lookupTransactionManager() throws NamingException { TransactionManager tm = NuxeoContainer.getTransactionManager(); if (tm == null) { throw new NamingException("tx manager not installed"); } return tm; }