Java Code Examples for javax.naming.NamingException#printStackTrace()
The following examples show how to use
javax.naming.NamingException#printStackTrace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Tomcat8-Source-Read File: TestNamingContext.java License: MIT License | 7 votes |
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/plain;UTF-8"); PrintWriter out = resp.getWriter(); try { Context ctx = new InitialContext(); Object obj = ctx.lookup("java:comp/env/bug50351"); TesterObject to = (TesterObject) obj; out.print(to.getFoo()); } catch (NamingException ne) { ne.printStackTrace(out); } }
Example 2
Source Project: primefaces-blueprints File: LoginDAO.java License: The Unlicense | 6 votes |
public LoginDAO() throws SQLException { try { Context ctx = new InitialContext(); ds = (DataSource) ctx.lookup("java:comp/env/jdbc/blueprintsdb"); if (ds == null) { throw new SQLException("Can't get data source"); } // get database connection con = ds.getConnection(); if (con == null) { throw new SQLException("Can't get database connection"); } } catch (NamingException e) { e.printStackTrace(); } }
Example 3
Source Project: MaxKey File: Group2Ldap.java License: Apache License 2.0 | 6 votes |
@Override public boolean create(Groups group) throws Exception{ logger.info("create"); try { Attributes attributes = new BasicAttributes(); attributes.put(new BasicAttribute("objectClass","groupOfUniqueNames")); attributes.put(new BasicAttribute("cn",group.getName())); attributes.put(new BasicAttribute("uniqueMember","uid=dummy")); String dn="cn="+group.getName()+",dc=groups,"+ldapUtils.getBaseDN(); ldapUtils.getCtx().createSubcontext(dn, attributes); ldapUtils.close(); } catch (NamingException e) { e.printStackTrace(); } return true; }
Example 4
Source Project: MaxKey File: Password2Ldap.java License: Apache License 2.0 | 6 votes |
@Override public boolean sync(UserInfo userInfo) throws Exception{ logger.info("changePassword"); try { ModificationItem[] modificationItems = new ModificationItem[1]; modificationItems[0]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("userPassword",ReciprocalUtils.decoder(userInfo.getDecipherable()))); String dn="uid="+userInfo.getUsername()+",dc=users,"+ldapUtils.getBaseDN(); ldapUtils.getCtx().modifyAttributes(dn, modificationItems); ldapUtils.close(); } catch (NamingException e) { e.printStackTrace(); } return true; }
Example 5
Source Project: JVoiceXML File: JVoiceXMLPingThread.java License: GNU Lesser General Public License v2.1 | 6 votes |
/** * Constructs a new object. * @param jsb reference to the server behavior to update the status. */ public JVoiceXMLPingThread(final JVoiceXMLServerBehaviour jsb) { behaviour = jsb; check = false; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); env.put(Context.PROVIDER_URL, "rmi://localhost:1099"); try { context = new InitialContext(env); } catch (NamingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example 6
Source Project: MaxKey File: Organization2Activedirectory.java License: Apache License 2.0 | 6 votes |
@Override public boolean delete(Organizations organization) throws Exception { try { SearchControls constraints = new SearchControls(); constraints.setSearchScope(ldapUtils.getSearchScope()); NamingEnumeration<SearchResult> results = ldapUtils.getConnection() .search(ldapUtils.getBaseDN(), "(&(objectClass=organizationalUnit)(description="+organization.getId()+"))", constraints); String dn=""; if (results == null || !results.hasMore()) { }else{ SearchResult sr = (SearchResult) results.next(); dn =sr.getNameInNamespace(); ldapUtils.getCtx().destroySubcontext(dn); } ldapUtils.close(); } catch (NamingException e) { e.printStackTrace(); } return super.delete(organization); }
Example 7
Source Project: olat File: VFSDirContext.java License: Apache License 2.0 | 5 votes |
@Override public Binding nextElement() { try { return next(); } catch (NamingException e) { e.printStackTrace(); return null; } }
Example 8
Source Project: MaxKey File: Group2Activedirectory.java License: Apache License 2.0 | 5 votes |
@Override public boolean update(Groups group) throws Exception{ logger.info("update"); try { SearchControls constraints = new SearchControls(); constraints.setSearchScope(ldapUtils.getSearchScope()); NamingEnumeration<SearchResult> results = ldapUtils.getConnection() .search(ldapUtils.getBaseDN(), "(cn="+group.getName()+")", constraints); String oldDn=""; String rdn=""; if (results == null || !results.hasMore()) { return create(group); }else{ SearchResult sr = (SearchResult) results.next(); oldDn =sr.getNameInNamespace(); String[] dnSplit=oldDn.split(","); rdn=oldDn.substring(oldDn.indexOf(","), oldDn.length()); String groupName=dnSplit[0].split("=")[1]; if(group.getName()!=groupName){ String newDn="cn="+group.getName()+","+rdn; ldapUtils.getCtx().rename(oldDn, newDn); ModificationItem[] modificationItems = new ModificationItem[1]; modificationItems[0]=new ModificationItem(DirContext.REMOVE_ATTRIBUTE,new BasicAttribute("cn",groupName)); ldapUtils.getCtx().modifyAttributes(newDn, modificationItems); } } ldapUtils.close(); } catch (NamingException e) { e.printStackTrace(); } return true; }
Example 9
Source Project: MaxKey File: Group2Ldap.java License: Apache License 2.0 | 5 votes |
@Override public boolean update(Groups group) throws Exception{ logger.info("update"); try { SearchControls constraints = new SearchControls(); constraints.setSearchScope(ldapUtils.getSearchScope()); NamingEnumeration<SearchResult> results = ldapUtils.getConnection() .search(ldapUtils.getBaseDN(), "(cn="+group.getName()+")", constraints); String oldDn=""; String rdn=""; if (results == null || !results.hasMore()) { return create(group); }else{ SearchResult sr = (SearchResult) results.next(); oldDn =sr.getNameInNamespace(); String[] dnSplit=oldDn.split(","); rdn=oldDn.substring(oldDn.indexOf(","), oldDn.length()); String groupName=dnSplit[0].split("=")[1]; if(group.getName()!=groupName){ String newDn="cn="+group.getName()+","+rdn; ldapUtils.getCtx().rename(oldDn, newDn); ModificationItem[] modificationItems = new ModificationItem[1]; modificationItems[0]=new ModificationItem(DirContext.REMOVE_ATTRIBUTE,new BasicAttribute("cn",groupName)); ldapUtils.getCtx().modifyAttributes(newDn, modificationItems); } } ldapUtils.close(); } catch (NamingException e) { e.printStackTrace(); } return true; }
Example 10
Source Project: rice File: EntityNamePrincipalNameMapper.java License: Educational Community License v2.0 | 5 votes |
EntityNamePrincipalName.Builder mapBuilderFromContext(DirContextOperations context) { final EntityNamePrincipalName.Builder person = EntityNamePrincipalName.Builder.create(); try { person.setDefaultName((EntityName.Builder) getDefaultNameMapper().mapFromContext(context)); } catch (NamingException e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } person.setPrincipalName(context.getStringAttribute(getConstants().getKimLdapNameProperty())); return person; }
Example 11
Source Project: ralasafe File: DataSourceProviderJndiImpl.java License: MIT License | 5 votes |
public void setup( Properties prop ) { this.prop=prop; String jndiName=prop.getProperty( "jndiName" ); try { InitialContext ctx=new InitialContext(); dataSource=(javax.sql.DataSource) ctx.lookup( jndiName ); } catch( NamingException e ) { e.printStackTrace(); throw new RuntimeException( e ); } }
Example 12
Source Project: spiracle File: CreateJndiConnectionPool.java License: Apache License 2.0 | 5 votes |
public void contextInitialized(ServletContextEvent arg0) { try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/oracle"); ServletContext application = arg0.getServletContext(); application.setAttribute("jndiConnectionPool", ds); logger.info("Added jndi connection pool " + ds + " to application context."); } catch (NamingException e) { logger.error("JNDI reference not found."); e.printStackTrace(); } }
Example 13
Source Project: iaf File: JndiMap.java License: Apache License 2.0 | 5 votes |
public Object get(Object key) { String name = keyToString(key); try { Object o = context.lookup(name); return o; } catch (NamingException e) { e.printStackTrace(); return null; } }
Example 14
Source Project: MaxKey File: Organization2Activedirectory.java License: Apache License 2.0 | 5 votes |
@Override public boolean create(Organizations organization) throws Exception { try { SearchControls constraints = new SearchControls(); constraints.setSearchScope(ldapUtils.getSearchScope()); NamingEnumeration<SearchResult> results = ldapUtils.getConnection() .search(ldapUtils.getBaseDN(), "(&(objectClass=organizationalUnit)(description="+organization.getpId()+"))", constraints); String rdn=""; if (results == null || !results.hasMore()) { rdn=ldapUtils.getBaseDN(); }else{ SearchResult sr = (SearchResult) results.next(); rdn =sr.getNameInNamespace(); } Attributes attributes = new BasicAttributes(); attributes.put(new BasicAttribute("objectClass","organizationalUnit")); attributes.put(new BasicAttribute("ou",organization.getName())); //attributes.put(new BasicAttribute("name",organization.getName())); //attributes.put(new BasicAttribute("id",organization.getId())); //attributes.put(new BasicAttribute("porgname",organization.getpName())); //attributes.put(new BasicAttribute("porgid",organization.getpId())); attributes.put(new BasicAttribute("description",organization.getId())); String dn="ou="+organization.getName()+","+rdn; ldapUtils.getCtx().createSubcontext(dn, attributes); ldapUtils.close(); } catch (NamingException e) { e.printStackTrace(); } return super.create(organization); }
Example 15
Source Project: MaxKey File: Group2Activedirectory.java License: Apache License 2.0 | 4 votes |
@Override public boolean addMember(GroupMember groupMember) throws Exception { try { SearchControls constraints = new SearchControls(); constraints.setSearchScope(ldapUtils.getSearchScope()); NamingEnumeration<SearchResult> results = ldapUtils.getConnection() .search(ldapUtils.getBaseDN(), "(cn="+groupMember.getGroupName()+")", constraints); if (results == null || !results.hasMore()) { Groups group =new Groups(); group.setName(groupMember.getGroupName()); return create(group); } String uniqueMember=""; SearchControls memberSearchControls = new SearchControls(); logger.debug("user Search : "+"(sAMAccountName="+groupMember.getMemberName()+")"); memberSearchControls.setSearchScope(ldapUtils.getSearchScope()); NamingEnumeration<SearchResult> memberResults = ldapUtils.getConnection() .search(ldapUtils.getBaseDN(), "(sAMAccountName="+groupMember.getMemberName()+")", memberSearchControls); if (memberResults == null || !memberResults.hasMore()) { }else{ SearchResult memberSr = (SearchResult) memberResults.next(); uniqueMember =memberSr.getNameInNamespace(); logger.debug("uniqueMember : "+uniqueMember); ModificationItem[] modificationItems = new ModificationItem[1]; modificationItems[0]=new ModificationItem(DirContext.ADD_ATTRIBUTE,new BasicAttribute("member",uniqueMember)); String dn="cn="+groupMember.getGroupName()+",cn=groups,"+ldapUtils.getBaseDN(); ldapUtils.getCtx().modifyAttributes(dn, modificationItems); } ldapUtils.close(); } catch (NamingException e) { e.printStackTrace(); } return true; }
Example 16
Source Project: TencentKona-8 File: LDAPCertStore.java License: GNU General Public License v2.0 | 4 votes |
/** * Create InitialDirContext. * * @param server Server DNS name hosting LDAP service * @param port Port at which server listens for requests * @throws InvalidAlgorithmParameterException if creation fails */ private void createInitialDirContext(String server, int port) throws InvalidAlgorithmParameterException { String url = "ldap://" + server + ":" + port; Hashtable<String,Object> env = new Hashtable<>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); // If property is set to true, disable application resource file lookup. boolean disableAppResourceFiles = AccessController.doPrivileged( new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES)); if (disableAppResourceFiles) { if (debug != null) { debug.println("LDAPCertStore disabling app resource files"); } env.put("com.sun.naming.disable.app.resource.files", "true"); } try { ctx = new InitialDirContext(env); /* * By default, follow referrals unless application has * overridden property in an application resource file. */ Hashtable<?,?> currentEnv = ctx.getEnvironment(); if (currentEnv.get(Context.REFERRAL) == null) { ctx.addToEnvironment(Context.REFERRAL, "throw"); } } catch (NamingException e) { if (debug != null) { debug.println("LDAPCertStore.engineInit about to throw " + "InvalidAlgorithmParameterException"); e.printStackTrace(); } Exception ee = new InvalidAlgorithmParameterException ("unable to create InitialDirContext using supplied parameters"); ee.initCause(e); throw (InvalidAlgorithmParameterException)ee; } }
Example 17
Source Project: openjdk-jdk8u File: LDAPCertStore.java License: GNU General Public License v2.0 | 4 votes |
/** * Create InitialDirContext. * * @param server Server DNS name hosting LDAP service * @param port Port at which server listens for requests * @throws InvalidAlgorithmParameterException if creation fails */ private void createInitialDirContext(String server, int port) throws InvalidAlgorithmParameterException { String url = "ldap://" + server + ":" + port; Hashtable<String,Object> env = new Hashtable<>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); // If property is set to true, disable application resource file lookup. boolean disableAppResourceFiles = AccessController.doPrivileged( new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES)); if (disableAppResourceFiles) { if (debug != null) { debug.println("LDAPCertStore disabling app resource files"); } env.put("com.sun.naming.disable.app.resource.files", "true"); } try { ctx = new InitialDirContext(env); /* * By default, follow referrals unless application has * overridden property in an application resource file. */ Hashtable<?,?> currentEnv = ctx.getEnvironment(); if (currentEnv.get(Context.REFERRAL) == null) { ctx.addToEnvironment(Context.REFERRAL, "throw"); } } catch (NamingException e) { if (debug != null) { debug.println("LDAPCertStore.engineInit about to throw " + "InvalidAlgorithmParameterException"); e.printStackTrace(); } Exception ee = new InvalidAlgorithmParameterException ("unable to create InitialDirContext using supplied parameters"); ee.initCause(e); throw (InvalidAlgorithmParameterException)ee; } }
Example 18
Source Project: MaxKey File: UserInfo2Ldap.java License: Apache License 2.0 | 4 votes |
@Override public boolean update(UserInfo userInfo) throws Exception{ logger.info("update"); try { SearchControls constraints = new SearchControls(); constraints.setSearchScope(ldapUtils.getSearchScope()); NamingEnumeration<SearchResult> results = ldapUtils.getConnection() .search(ldapUtils.getBaseDN(), "(&(objectClass=inetOrgPerson)(uid="+userInfo.getUsername()+"))", constraints); if (results == null || !results.hasMore()) { return create(loadUser(userInfo)); } ModificationItem[] modificationItems = new ModificationItem[10]; modificationItems[0]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("displayName",userInfo.getDisplayName())); modificationItems[1]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("cn",userInfo.getDisplayName())); modificationItems[2]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("givenName",userInfo.getGivenName())); modificationItems[3]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("sn",userInfo.getFamilyName())); modificationItems[4]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("mobile",userInfo.getWorkPhoneNumber()==null?"":userInfo.getWorkPhoneNumber())); modificationItems[5]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("mail",userInfo.getWorkEmail()==null?"":userInfo.getWorkEmail())); modificationItems[6]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("employeeNumber",userInfo.getEmployeeNumber()==null?"":userInfo.getEmployeeNumber())); modificationItems[7]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("ou",userInfo.getDepartment()==null?"":userInfo.getDepartment())); modificationItems[8]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("departmentNumber",userInfo.getDepartmentId()==null?"":userInfo.getDepartmentId())); modificationItems[9]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("title",userInfo.getJobTitle()==null?"":userInfo.getJobTitle())); String managerDn="uid=dummy"; if(userInfo.getManagerId()==null||userInfo.getManagerId().equals("")){ }else{ UserInfo queryManager=new UserInfo(); queryManager.setId(userInfo.getManagerId()); UserInfo manager=loadUser(queryManager); managerDn="uid="+manager.getUsername()+",dc=users,"+ldapUtils.getBaseDN(); } modificationItems[9]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("manager",managerDn)); String dn="uid="+userInfo.getUsername()+",dc=users,"+ldapUtils.getBaseDN(); ldapUtils.getCtx().modifyAttributes(dn, modificationItems); ldapUtils.close(); } catch (NamingException e) { e.printStackTrace(); } return true; }
Example 19
Source Project: jdk8u-dev-jdk File: LDAPCertStore.java License: GNU General Public License v2.0 | 4 votes |
/** * Create InitialDirContext. * * @param server Server DNS name hosting LDAP service * @param port Port at which server listens for requests * @throws InvalidAlgorithmParameterException if creation fails */ private void createInitialDirContext(String server, int port) throws InvalidAlgorithmParameterException { String url = "ldap://" + server + ":" + port; Hashtable<String,Object> env = new Hashtable<>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); // If property is set to true, disable application resource file lookup. boolean disableAppResourceFiles = AccessController.doPrivileged( new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES)); if (disableAppResourceFiles) { if (debug != null) { debug.println("LDAPCertStore disabling app resource files"); } env.put("com.sun.naming.disable.app.resource.files", "true"); } try { ctx = new InitialDirContext(env); /* * By default, follow referrals unless application has * overridden property in an application resource file. */ Hashtable<?,?> currentEnv = ctx.getEnvironment(); if (currentEnv.get(Context.REFERRAL) == null) { ctx.addToEnvironment(Context.REFERRAL, "follow"); } } catch (NamingException e) { if (debug != null) { debug.println("LDAPCertStore.engineInit about to throw " + "InvalidAlgorithmParameterException"); e.printStackTrace(); } Exception ee = new InvalidAlgorithmParameterException ("unable to create InitialDirContext using supplied parameters"); ee.initCause(e); throw (InvalidAlgorithmParameterException)ee; } }
Example 20
Source Project: openjdk-8-source File: LDAPCertStore.java License: GNU General Public License v2.0 | 4 votes |
/** * Create InitialDirContext. * * @param server Server DNS name hosting LDAP service * @param port Port at which server listens for requests * @throws InvalidAlgorithmParameterException if creation fails */ private void createInitialDirContext(String server, int port) throws InvalidAlgorithmParameterException { String url = "ldap://" + server + ":" + port; Hashtable<String,Object> env = new Hashtable<>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); // If property is set to true, disable application resource file lookup. boolean disableAppResourceFiles = AccessController.doPrivileged( new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES)); if (disableAppResourceFiles) { if (debug != null) { debug.println("LDAPCertStore disabling app resource files"); } env.put("com.sun.naming.disable.app.resource.files", "true"); } try { ctx = new InitialDirContext(env); /* * By default, follow referrals unless application has * overridden property in an application resource file. */ Hashtable<?,?> currentEnv = ctx.getEnvironment(); if (currentEnv.get(Context.REFERRAL) == null) { ctx.addToEnvironment(Context.REFERRAL, "follow"); } } catch (NamingException e) { if (debug != null) { debug.println("LDAPCertStore.engineInit about to throw " + "InvalidAlgorithmParameterException"); e.printStackTrace(); } Exception ee = new InvalidAlgorithmParameterException ("unable to create InitialDirContext using supplied parameters"); ee.initCause(e); throw (InvalidAlgorithmParameterException)ee; } }