List of usage examples for javax.naming NamingException NamingException
public NamingException(String explanation)
From source file:com.wso2telco.proxy.util.DBUtils.java
private static void initializeDatasource() throws NamingException { if (dataSource != null) { return;//w w w. j av a 2s .co m } String dataSourceName = null; try { Context ctx = new InitialContext(); dataSourceName = configurationService.getDataHolder().getMobileConnectConfig().getAuthProxy() .getDataSourceName(); if (dataSourceName != null) { dataSource = (DataSource) ctx.lookup(dataSourceName); } else { throw new ConfigurationException("DataSource could not be found in mobile-connect.xml"); } } catch (ConfigurationException e) { throw new ConfigurationException("DataSource could not be found in mobile-connect.xml"); } catch (NamingException e) { throw new NamingException("Exception occurred while initiating data source : " + dataSourceName); } }
From source file:com.gemstone.gemfire.security.NotAuthorizedExceptionTest.java
@Before public void setUp() throws Exception { this.message = testName.getMethodName() + " message"; this.causeMessage = testName.getMethodName() + " cause message"; this.nonSerializableResolvedObj = new Object(); this.nonSerializableNamingException = new NamingException(this.causeMessage); this.nonSerializableNamingException.setResolvedObj(this.nonSerializableResolvedObj); this.serializableResolvedObj = new SerializableObject(this.testName.getMethodName()); this.serializableNamingException = new NamingException(this.causeMessage); this.serializableNamingException.setResolvedObj(this.serializableResolvedObj); this.principalName = "jsmith"; this.nonSerializablePrincipal = mock(Principal.class); this.serializablePrincipal = new SerializablePrincipal(this.principalName); assertPreconditions();//from w w w .ja v a 2 s. c o m }
From source file:de.sub.goobi.helper.ldap.LdapUser.java
/** * configure LdapUser with Userdetails.//from www .j av a2s . c o m * * @param inUser * User object * @param inPassword * String * @param inUidNumber * String */ public void configure(User inUser, String inPassword, String inUidNumber) throws NamingException, NoSuchAlgorithmException { MD4 digester = new MD4(); if (!ConfigCore.getBooleanParameter("ldap_readonly", false)) { this.type = inUser.getLogin(); LdapGroup lp = inUser.getLdapGroup(); if (lp.getObjectClasses() == null) { throw new NamingException("no objectclass defined"); } /* ObjectClasses */ Attribute oc = new BasicAttribute("objectclass"); StringTokenizer tokenizer = new StringTokenizer(lp.getObjectClasses(), ","); while (tokenizer.hasMoreTokens()) { oc.add(tokenizer.nextToken()); } this.myAttrs.put(oc); this.myAttrs.put("uid", ReplaceVariables(lp.getUid(), inUser, inUidNumber)); this.myAttrs.put("cn", ReplaceVariables(lp.getUid(), inUser, inUidNumber)); this.myAttrs.put("displayName", ReplaceVariables(lp.getDisplayName(), inUser, inUidNumber)); this.myAttrs.put("description", ReplaceVariables(lp.getDescription(), inUser, inUidNumber)); this.myAttrs.put("gecos", ReplaceVariables(lp.getGecos(), inUser, inUidNumber)); this.myAttrs.put("loginShell", ReplaceVariables(lp.getLoginShell(), inUser, inUidNumber)); this.myAttrs.put("sn", ReplaceVariables(lp.getSn(), inUser, inUidNumber)); this.myAttrs.put("homeDirectory", ReplaceVariables(lp.getHomeDirectory(), inUser, inUidNumber)); this.myAttrs.put("sambaAcctFlags", ReplaceVariables(lp.getSambaAcctFlags(), inUser, inUidNumber)); this.myAttrs.put("sambaLogonScript", ReplaceVariables(lp.getSambaLogonScript(), inUser, inUidNumber)); this.myAttrs.put("sambaPrimaryGroupSID", ReplaceVariables(lp.getSambaPrimaryGroupSID(), inUser, inUidNumber)); this.myAttrs.put("sambaSID", ReplaceVariables(lp.getSambaSID(), inUser, inUidNumber)); this.myAttrs.put("sambaPwdMustChange", ReplaceVariables(lp.getSambaPwdMustChange(), inUser, inUidNumber)); this.myAttrs.put("sambaPasswordHistory", ReplaceVariables(lp.getSambaPasswordHistory(), inUser, inUidNumber)); this.myAttrs.put("sambaLogonHours", ReplaceVariables(lp.getSambaLogonHours(), inUser, inUidNumber)); this.myAttrs.put("sambaKickoffTime", ReplaceVariables(lp.getSambaKickoffTime(), inUser, inUidNumber)); this.myAttrs.put("sambaPwdLastSet", String.valueOf(System.currentTimeMillis() / 1000l)); this.myAttrs.put("uidNumber", inUidNumber); this.myAttrs.put("gidNumber", ReplaceVariables(lp.getGidNumber(), inUser, inUidNumber)); /* * Samba passwords */ /* LanMgr */ try { this.myAttrs.put("sambaLMPassword", toHexString(lmHash(inPassword))); } catch (Exception e) { logger.error(e); } /* NTLM */ try { byte hmm[] = digester.digest(inPassword.getBytes("UnicodeLittleUnmarked")); this.myAttrs.put("sambaNTPassword", toHexString(hmm)); } catch (UnsupportedEncodingException e) { logger.error(e); } /* * Encryption of password und Base64-Enconding */ MessageDigest md = MessageDigest.getInstance(ConfigCore.getParameter("ldap_encryption", "SHA")); md.update(inPassword.getBytes(StandardCharsets.UTF_8)); String digestBase64 = new String(Base64.encodeBase64(md.digest()), StandardCharsets.UTF_8); this.myAttrs.put("userPassword", "{" + ConfigCore.getParameter("ldap_encryption", "SHA") + "}" + digestBase64); } }
From source file:JNDIUtil.java
/** * Lookup an object through the JNDI context. * * @param objectName The name of the object to be looked up. * @param jndiProperties JNDI properties. * @param classLoaders The {@link ClassLoader ClassLoaders) to be used during the lookup. * @return The object.// ww w . java 2 s . c om * @throws NamingException Error getting object. */ public static Object lookup(final String objectName, final Properties jndiProperties, final ClassLoader[] classLoaders) throws NamingException { ClassLoader tcClassLoader = Thread.currentThread().getContextClassLoader(); try { for (ClassLoader classLoader : classLoaders) { Thread.currentThread().setContextClassLoader(classLoader); try { return JNDIUtil.lookup(objectName, jndiProperties); } catch (NamingException e) { System.out.println( "NamingException while trying to lookup '" + objectName + "' using JNDI Properties '" + jndiProperties + "', classloader used '" + classLoader + "'" + e); // Try the other ClassLoaders... } } } finally { Thread.currentThread().setContextClassLoader(tcClassLoader); } throw new NamingException("JNDI lookup of Object [" + objectName + "] failed."); }
From source file:com.adito.activedirectory.PagedResultTemplate.java
private void assertExceptions(PagedResultMapper mapper) throws NamingException { if (mapper.containsExceptions()) { Exception e = mapper.getLastException(); logger.error(mapper.getExceptionCount() + " exceptions occurred, throwing the last one", e); throw e instanceof NamingException ? (NamingException) e : new NamingException(e.getMessage()); }/*from www. ja v a 2 s . c om*/ }
From source file:com.enioka.jqm.tools.JndiContext.java
/** * Create a new Context/* ww w . j a v a 2s. c om*/ * * @throws NamingException */ private JndiContext() throws NamingException { super(); // List all jars inside ext directory File extDir = new File("ext/"); List<URL> urls = new ArrayList<URL>(); if (extDir.isDirectory()) { for (File f : extDir.listFiles()) { if (!f.canRead()) { throw new NamingException("can't access file " + f.getAbsolutePath()); } try { urls.add(f.toURI().toURL()); } catch (MalformedURLException e) { jqmlogger.error("Error when parsing the content of ext directory. File will be ignored", e); } } // Create classloader final URL[] aUrls = urls.toArray(new URL[0]); for (URL u : aUrls) { jqmlogger.trace(u.toString()); } extResources = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { @Override public URLClassLoader run() { return new URLClassLoader(aUrls, null); } }); } else { throw new NamingException("JQM_ROOT/ext directory does not exist or cannot be read"); } }
From source file:alpine.auth.LdapConnectionWrapper.java
/** * Asserts a users credentials. Returns an LdapContext if assertion is successful * or an exception for any other reason. * * @param userDn the users DN to assert// ww w . ja v a 2s . c om * @param password the password to assert * @return the LdapContext upon a successful connection * @throws NamingException when unable to establish a connection * @since 1.4.0 */ public LdapContext createLdapContext(String userDn, String password) throws NamingException { if (StringUtils.isEmpty(userDn) || StringUtils.isEmpty(password)) { throw new NamingException("Username or password cannot be empty or null"); } final Hashtable<String, String> env = new Hashtable<>(); if (StringUtils.isNotBlank(LDAP_SECURITY_AUTH)) { env.put(Context.SECURITY_AUTHENTICATION, LDAP_SECURITY_AUTH); } env.put(Context.SECURITY_PRINCIPAL, userDn); env.put(Context.SECURITY_CREDENTIALS, password); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, LDAP_URL); if (IS_LDAP_SSLTLS) { env.put("java.naming.ldap.factory.socket", "alpine.crypto.RelaxedSSLSocketFactory"); } try { return new InitialLdapContext(env, null); } catch (CommunicationException e) { LOGGER.error("Failed to connect to directory server", e); throw (e); } catch (NamingException e) { throw new NamingException("Failed to authenticate user"); } }
From source file:occi.infrastructure.Compute.java
public Compute(Architecture architecture, int cores, String hostname, float speed, float memory, State state, Set<String> attributes) throws URISyntaxException, NumberFormatException, IllegalArgumentException, NamingException { super("Compute", links, attributes); this.architecture = architecture; this.cores = cores; this.hostname = hostname; this.speed = speed; this.memory = memory; this.state = state; generateActionNames();/* www .j a v a 2 s . c o m*/ // check if all attributes are correct if ((cores < 1)) { throw new NumberFormatException("Number of cores is negative!"); } else if (speed <= 1) { throw new NumberFormatException("Number of speed is negative!"); } else if (memory <= 1) { throw new NumberFormatException("Number of memory is negative!"); } // check if there is a hostname if (hostname.length() == 0) { throw new NamingException("Name of the Compute resource can not be null"); } /* * set Category */ setKind(new Kind(actionSet, null, null, null, "compute", "Compute", OcciConfig.getInstance().config.getString("occi.scheme") + "/infrastructure#", attributes)); getKind().setActionNames(actionNames); // set uuid for the resource uuid = UUID.randomUUID(); setId(new URI(uuid.toString())); // put resource into compute list computeList.put(uuid, this); // Generate attribute list generateAttributeList(); }
From source file:com.enioka.jqm.tools.ResourceParser.java
private static void importXml() throws NamingException { InputStream is = ResourceParser.class.getClassLoader().getResourceAsStream(Helpers.resourceFile); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); try {/*from www . j a v a 2 s . c o m*/ DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(is); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("resource"); String jndiAlias = null, resourceClass = null, description = "no description", scope = null, auth = "Container", factory = null; boolean singleton = false; for (int i = 0; i < nList.getLength(); i++) { Node n = nList.item(i); Map<String, String> otherParams = new HashMap<String, String>(); NamedNodeMap attrs = n.getAttributes(); for (int j = 0; j < attrs.getLength(); j++) { Node attr = attrs.item(j); String key = attr.getNodeName(); String value = attr.getNodeValue(); if ("name".equals(key)) { jndiAlias = value; } else if ("type".equals(key)) { resourceClass = value; } else if ("description".equals(key)) { description = value; } else if ("factory".equals(key)) { factory = value; } else if ("auth".equals(key)) { auth = value; } else if ("singleton".equals(key)) { singleton = Boolean.parseBoolean(value); } else { otherParams.put(key, value); } } if (resourceClass == null || jndiAlias == null || factory == null) { throw new NamingException("could not load the resource.xml file"); } JndiResourceDescriptor jrd = new JndiResourceDescriptor(resourceClass, description, scope, auth, factory, singleton); for (Map.Entry<String, String> prm : otherParams.entrySet()) { jrd.add(new StringRefAddr(prm.getKey(), prm.getValue())); } xml.put(jndiAlias, jrd); } } catch (Exception e) { NamingException pp = new NamingException("could not initialize the JNDI local resources"); pp.setRootCause(e); throw pp; } finally { IOUtils.closeQuietly(is); } }
From source file:com.netspective.axiom.connection.JndiConnectionProvider.java
public final Connection getConnection(ValueContext vc, String dataSourceId) throws NamingException, SQLException { DataSource source = getDataSource(vc, dataSourceId); if (source == null) { if (log.isDebugEnabled()) log.debug("dataSourceId not found in " + JndiConnectionProvider.class.getName() + ".getConnection('" + dataSourceId + "'). Available: " + getAvailableDataSources()); throw new NamingException( "Data source '" + dataSourceId + "' not found in JNDI provider " + getRootContext()); }//from w w w .ja v a2 s . c o m return source.getConnection(); }