List of usage examples for javax.naming NamingException getMessage
public String getMessage()
From source file:org.apache.cloudstack.ldap.OpenLdapUserManagerImpl.java
@Override public List<LdapUser> getUsersInGroup(String groupName, LdapContext context) throws NamingException { String attributeName = _ldapConfiguration.getGroupUniqueMemeberAttribute(); final SearchControls controls = new SearchControls(); controls.setSearchScope(_ldapConfiguration.getScope()); controls.setReturningAttributes(new String[] { attributeName }); NamingEnumeration<SearchResult> result = context.search(_ldapConfiguration.getBaseDn(), generateGroupSearchFilter(groupName), controls); final List<LdapUser> users = new ArrayList<LdapUser>(); //Expecting only one result which has all the users if (result.hasMoreElements()) { Attribute attribute = result.nextElement().getAttributes().get(attributeName); NamingEnumeration<?> values = attribute.getAll(); while (values.hasMoreElements()) { String userdn = String.valueOf(values.nextElement()); try { users.add(getUserForDn(userdn, context)); } catch (NamingException e) { s_logger.info("Userdn: " + userdn + " Not Found:: Exception message: " + e.getMessage()); }//w ww . jav a2 s . c o m } } Collections.sort(users); return users; }
From source file:de.iai.ilcd.configuration.ConfigurationService.java
ConfigurationService() { try {//from w w w .j a v a 2 s . c o m this.appConfig = new PropertiesConfiguration("app.properties"); } catch (ConfigurationException e) { throw new RuntimeException("FATAL ERROR: application properties could not be initialized", e); } // log application version message this.versionTag = this.appConfig.getString("version.tag"); this.logger.info(this.versionTag); // validate/migrate database schema this.migrateDatabaseSchema(); URL resourceUrl = Thread.currentThread().getContextClassLoader().getResource("log4j.properties"); String decodedPath = ""; // now extract path and decode it try { // note, that URLs getPath() method does not work, because it don't // decode encoded Urls, but URI's does this decodedPath = resourceUrl.toURI().getPath(); } catch (URISyntaxException ex) { this.logger.error("Cannot extract base path from resource files", ex); } // base path it relative to web application root directory this.basePath = decodedPath.replace("/WEB-INF/classes/log4j.properties", ""); this.logger.info("base path of web application: {}", this.basePath); // Obtain our environment naming context Context initCtx; Context envCtx; String propertiesFilePath = null; try { initCtx = new InitialContext(); envCtx = (Context) initCtx.lookup("java:comp/env"); propertiesFilePath = (String) envCtx.lookup("soda4LCAProperties"); } catch (NamingException e1) { this.logger.error(e1.getMessage()); } if (propertiesFilePath == null) { this.logger.info("using default application properties at {}", this.defaultPropertiesFile); propertiesFilePath = this.defaultPropertiesFile; } else { this.logger.info("reading application configuration properties from {}", propertiesFilePath); } try { // OK, now load configuration file this.fileConfig = new PropertiesConfiguration(propertiesFilePath); this.featureNetworking = this.fileConfig.getString("feature.networking"); configureLanguages(); } catch (ConfigurationException ex) { this.logger.error( "Cannot find application configuration properties file under {}, either put it there or set soda4LCAProperties environment entry via JNDI.", propertiesFilePath, ex); throw new RuntimeException("application configuration properties not found", ex); } }
From source file:org.mule.transport.jms.Jms11Support.java
protected Destination getJndiDestination(String name) throws JMSException { Object temp;// w w w . jav a 2s .c om try { if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("Looking up {0} from JNDI", name)); } temp = connector.lookupFromJndi(name); } catch (NamingException e) { if (logger.isDebugEnabled()) { logger.debug(e); } String message = MessageFormat.format("Failed to look up destination {0}. Reason: {1}", name, e.getMessage()); throw new JMSException(message); } if (temp != null) { if (temp instanceof Destination) { return (Destination) temp; } } return null; }
From source file:org.pepstock.jem.ant.tasks.utilities.sort.DefaultComparator.java
/** * Checks if COMMAND data description is allocated. If not, uses the default string * comparator. Otherwise loads all comparators. * //from w w w . j a va2 s .c o m * @throws Exception if any IO of parsing commands exception occurs * */ public DefaultComparator() { // new initial context to access by JNDI to COMMAND DataDescription InitialContext ic; try { ic = ContextUtils.getContext(); // gets inputstream Object filein = (Object) ic.lookup(DATA_DESCRIPTION_NAME); // reads content of inout stream StringBuilder recordsSB = read((InputStream) filein); // trims result to see if is empty String records = recordsSB.toString().trim(); // loads commands loadCommands(records); } catch (NamingException e) { LogAppl.getInstance().emit(AntMessage.JEMA044W, e, e.getMessage()); } catch (ParseException e) { LogAppl.getInstance().emit(AntMessage.JEMA058W, e, e.getMessage()); } catch (IOException e) { LogAppl.getInstance().emit(AntMessage.JEMA058W, e, e.getMessage()); } }
From source file:org.pepstock.jem.jbpm.tasks.utilities.sort.DefaultComparator.java
/** * Checks if COMMAND data description is allocated. If not, uses the default string * comparator. Otherwise loads all comparators. * /*w w w.ja va 2 s .co m*/ * @throws Exception if any IO of parsing commands exception occurs * */ public DefaultComparator() { // new initial context to access by JNDI to COMMAND DataDescription InitialContext ic; try { ic = ContextUtils.getContext(); // gets inputstream Object filein = (Object) ic.lookup(DATA_DESCRIPTION_NAME); // reads content of inout stream StringBuilder recordsSB = read((InputStream) filein); // trims result to see if is empty String records = recordsSB.toString().trim(); // loads commands loadCommands(records); } catch (NamingException e) { LogAppl.getInstance().emit(JBpmMessage.JEMM044W, e, e.getMessage()); } catch (ParseException e) { LogAppl.getInstance().emit(JBpmMessage.JEMM058W, e, e.getMessage()); } catch (IOException e) { LogAppl.getInstance().emit(JBpmMessage.JEMM058W, e, e.getMessage()); } }
From source file:com.espertech.esper.core.context.factory.StatementAgentInstanceFactoryCreateWindow.java
public StatementAgentInstanceFactoryCreateWindowResult newContext( final AgentInstanceContext agentInstanceContext, boolean isRecoveringResilient) { final List<StopCallback> stopCallbacks = new ArrayList<StopCallback>(); String windowName = statementSpec.getCreateWindowDesc().getWindowName(); Viewable finalView;//from w w w . j av a 2 s . c om Viewable eventStreamParentViewable; StatementAgentInstancePostLoad postLoad = null; Viewable topView; try { // Register interest ViewableActivationResult activationResult = activator.activate(agentInstanceContext, false, isRecoveringResilient); stopCallbacks.add(activationResult.getStopCallback()); eventStreamParentViewable = activationResult.getViewable(); // Obtain processor for this named window NamedWindowProcessor processor = services.getNamedWindowService().getProcessor(windowName); if (processor == null) { throw new RuntimeException( "Failed to obtain named window processor for named window '" + windowName + "'"); } // Allocate processor instance NamedWindowProcessorInstance processorInstance = processor.addInstance(agentInstanceContext); View rootView = processorInstance.getRootViewInstance(); eventStreamParentViewable.addView(rootView); // Materialize views AgentInstanceViewFactoryChainContext viewFactoryChainContext = new AgentInstanceViewFactoryChainContext( agentInstanceContext, true, null, null); ViewServiceCreateResult createResult = services.getViewService().createViews(rootView, unmaterializedViewChain.getViewFactoryChain(), viewFactoryChainContext, false); topView = createResult.getTopViewable(); finalView = createResult.getFinalViewable(); // If this is a virtual data window implementation, bind it to the context for easy lookup StopCallback envStopCallback = null; if (finalView instanceof VirtualDWView) { final String objectName = "/virtualdw/" + windowName; final VirtualDWView virtualDWView = (VirtualDWView) finalView; try { services.getEngineEnvContext().bind(objectName, virtualDWView.getVirtualDataWindow()); } catch (NamingException e) { throw new ViewProcessingException("Invalid name for adding to context:" + e.getMessage(), e); } envStopCallback = new StopCallback() { public void stop() { try { virtualDWView.destroy(); services.getEngineEnvContext().unbind(objectName); } catch (NamingException e) { } } }; } final StopCallback environmentStopCallback = envStopCallback; // create stop method using statement stream specs StopCallback allInOneStopMethod = new StopCallback() { public void stop() { String windowName = statementSpec.getCreateWindowDesc().getWindowName(); NamedWindowProcessor processor = services.getNamedWindowService().getProcessor(windowName); if (processor == null) { log.warn("Named window processor by name '" + windowName + "' has not been found"); } else { NamedWindowProcessorInstance instance = processor .getProcessorInstance(agentInstanceContext); if (instance != null && instance.getRootViewInstance().isVirtualDataWindow()) { instance.getRootViewInstance().getVirtualDataWindow().handleStopWindow(); } if (instance != null) { processor.removeProcessorInstance(instance); } } if (environmentStopCallback != null) { environmentStopCallback.stop(); } } }; stopCallbacks.add(allInOneStopMethod); // Attach tail view NamedWindowTailViewInstance tailView = processorInstance.getTailViewInstance(); finalView.addView(tailView); finalView = tailView; // obtain result set processor ResultSetProcessor resultSetProcessor = EPStatementStartMethodHelperAssignExpr .getAssignResultSetProcessor(agentInstanceContext, resultSetProcessorPrototype); // Attach output view View outputView = outputProcessViewFactory.makeView(resultSetProcessor, agentInstanceContext); finalView.addView(outputView); finalView = outputView; // obtain post load postLoad = processorInstance.getPostLoad(); // Handle insert case if (statementSpec.getCreateWindowDesc().isInsert() && !isRecoveringStatement) { String insertFromWindow = statementSpec.getCreateWindowDesc().getInsertFromWindow(); NamedWindowProcessor namedWindowProcessor = services.getNamedWindowService() .getProcessor(insertFromWindow); NamedWindowProcessorInstance sourceWindowInstances = namedWindowProcessor .getProcessorInstance(agentInstanceContext); List<EventBean> events = new ArrayList<EventBean>(); if (statementSpec.getCreateWindowDesc().getInsertFilter() != null) { EventBean[] eventsPerStream = new EventBean[1]; ExprEvaluator filter = statementSpec.getCreateWindowDesc().getInsertFilter().getExprEvaluator(); for (Iterator<EventBean> it = sourceWindowInstances.getTailViewInstance().iterator(); it .hasNext();) { EventBean candidate = it.next(); eventsPerStream[0] = candidate; Boolean result = (Boolean) filter.evaluate(eventsPerStream, true, agentInstanceContext); if ((result == null) || (!result)) { continue; } events.add(candidate); } } else { for (Iterator<EventBean> it = sourceWindowInstances.getTailViewInstance().iterator(); it .hasNext();) { events.add(it.next()); } } if (events.size() > 0) { EventType rootViewType = rootView.getEventType(); EventBean[] convertedEvents = services.getEventAdapterService().typeCast(events, rootViewType); rootView.update(convertedEvents, null); } } } catch (RuntimeException ex) { StopCallback stopCallback = StatementAgentInstanceUtil.getStopCallback(stopCallbacks, agentInstanceContext); StatementAgentInstanceUtil.stopSafe(stopCallback, statementContext); throw ex; } log.debug(".start Statement start completed"); StopCallback stopCallback = StatementAgentInstanceUtil.getStopCallback(stopCallbacks, agentInstanceContext); return new StatementAgentInstanceFactoryCreateWindowResult(finalView, stopCallback, agentInstanceContext, eventStreamParentViewable, postLoad, topView); }
From source file:org.wso2.carbon.user.core.ldap.LDAPConnectionContext.java
public DirContext getContext() throws UserStoreException { DirContext context = null;/*from ww w.j a v a2 s . c o m*/ //if dcMap is not populated, it is not DNS case if (dcMap == null) { try { context = new InitialDirContext(environment); } catch (NamingException e) { log.error("Error obtaining connection. " + e.getMessage(), e); log.error("Trying again to get connection."); try { context = new InitialDirContext(environment); } catch (Exception e1) { log.error("Error obtaining connection for the second time" + e.getMessage(), e); throw new UserStoreException("Error obtaining connection. " + e.getMessage(), e); } } } else if (dcMap != null && dcMap.size() != 0) { try { //first try the first entry in dcMap, if it fails, try iteratively Integer firstKey = dcMap.firstKey(); SRVRecord firstRecord = dcMap.get(firstKey); //compose the connection URL environment.put(Context.PROVIDER_URL, getLDAPURLFromSRVRecord(firstRecord)); context = new InitialDirContext(environment); } catch (NamingException e) { log.error("Error obtaining connection to first Domain Controller." + e.getMessage(), e); log.info("Trying to connect with other Domain Controllers"); for (Integer integer : dcMap.keySet()) { try { SRVRecord srv = dcMap.get(integer); environment.put(Context.PROVIDER_URL, getLDAPURLFromSRVRecord(srv)); context = new InitialDirContext(environment); break; } catch (NamingException e1) { if (integer == (dcMap.lastKey())) { log.error("Error obtaining connection for all " + integer + " Domain Controllers." + e.getMessage(), e); throw new UserStoreException("Error obtaining connection. " + e.getMessage(), e); } } } } } return (context); }
From source file:com.aurel.track.util.LdapUtil.java
static TPersonBean getLdapUser(String providerUrl, String bindDN, String bindPassword, String loginAttributeName, String searchStr) throws Exception { LdapContext ctx = null;/*w w w . j a va 2 s. co m*/ try { ctx = getInitialContext(providerUrl, bindDN, bindPassword); if (ctx == null) { LOGGER.warn("The context is null"); } // Control the search SearchControls ctls = new SearchControls(); ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); // Don't ask for more than we can handle anyways if (ldapMap == null || ldapMap.isEmpty()) { LOGGER.error("There is no LDAP mapping in quartz-jobs.xml. Please provide!"); return null; } String firstNameAttributeName = ldapMap.get(LdapUtil.LDAP_CONFIG.FIRST_NAME); String lastNameAttributName = ldapMap.get(LdapUtil.LDAP_CONFIG.LAST_NAME); String emailAttributeName = ldapMap.get(LdapUtil.LDAP_CONFIG.EMAIL); String phoneAttributName = ldapMap.get(LdapUtil.LDAP_CONFIG.PHONE); NamingEnumeration<SearchResult> results = ctx.search("", searchStr, ctls); /* for each entry print out name + all attrs and values */ while (results != null && results.hasMore()) { SearchResult sr = (SearchResult) results.next(); return getPersonBean(sr, loginAttributeName, firstNameAttributeName, lastNameAttributName, emailAttributeName, phoneAttributName); } } catch (NamingException e) { LOGGER.warn( "Searching from " + providerUrl + " by filter " + searchStr + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } finally { if (ctx != null) { ctx.close(); } } return null; }
From source file:org.libreplan.web.users.services.LDAPCustomAuthenticationProvider.java
private List<String> getRolesUsingBranchStrategy(Set<ConfigurationRolesLDAP> rolesLdap, String queryRoles, LDAPConfiguration configuration) { String roleProperty = configuration.getLdapRoleProperty(); String groupsPath = configuration.getLdapGroupPath(); List<String> rolesReturn = new ArrayList<>(); for (ConfigurationRolesLDAP roleLdap : rolesLdap) { if (roleLdap.getRoleLdap().equals(WILDCHAR_ALL)) { rolesReturn.add(roleLdap.getRoleLibreplan()); continue; }//from ww w . j a v a 2 s . com // We must make a search for each role matching DirContextAdapter adapter = null; try { adapter = (DirContextAdapter) ldapTemplate.lookup(roleLdap.getRoleLdap() + "," + groupsPath); } catch (org.springframework.ldap.NamingException ne) { LOG.error(ne.getMessage()); } if (adapter != null && adapter.attributeExists(roleProperty)) { Attributes atrs = adapter.getAttributes(); if (atrs.get(roleProperty).contains(queryRoles)) { rolesReturn.add(roleLdap.getRoleLibreplan()); } } } return rolesReturn; }