Search in sources :

Example 86 with NamingException

use of javax.naming.NamingException in project CloudStack-archive by CloudStack-extras.

the class LDAPConfigCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        boolean result = _configService.updateLDAP(this);
        if (result) {
            LDAPConfigResponse lr = _responseGenerator.createLDAPConfigResponse(getHostname(), getPort(), getUseSSL(), getQueryFilter(), getSearchBase(), getBindDN());
            lr.setResponseName(getCommandName());
            this.setResponseObject(lr);
        }
    } catch (NamingException ne) {
        ne.printStackTrace();
    }
}
Also used : LDAPConfigResponse(com.cloud.api.response.LDAPConfigResponse) NamingException(javax.naming.NamingException)

Example 87 with NamingException

use of javax.naming.NamingException in project ACS by ACS-Community.

the class DefaultSubscriberImpl method subscribe.

/**
   * Method subscribe
   *
   *
   * @param topic
   * @param listener
   * @param selector
   *
   * @return long the subscription handle identifier
   *
   * @throws JMSException
   * @throws NamingException
   *
   */
public long subscribe(String topic, SubscriptionListener listener, String selector) throws JMSException, NamingException {
    cat.info("subscribe(" + topic + ", listener, " + selector + ")");
    if (closed) {
        throw (new JMSException("Subscriber closed."));
    }
    SubscriptionHandle handle = new SubscriptionHandle();
    handle.setSubscriptionTopic(topic);
    handle.setSubscriptionSelector(selector);
    handle.setSubscriptionListener(listener);
    StringBuffer local_selector = new StringBuffer();
    if (NotificationHelper.isNotification(topic)) {
        // this is a subscription to notifications, no further selection is required
        local_selector.append(selector);
    } else {
        // subscription to a generic topic, adding subscriber specific selection
        if (selector != null) {
            local_selector.append(selector);
            local_selector.append(" AND ");
        }
        local_selector.append("( (");
        local_selector.append(NotificationHelper.SUBSCRIPTION_ID_PROPERTY);
        local_selector.append(" IS NULL) OR (");
        local_selector.append(NotificationHelper.SUBSCRIPTION_ID_PROPERTY);
        local_selector.append(" = '");
        local_selector.append(subscriberId);
        local_selector.append("@");
        local_selector.append(handle.getSubscriptionToken());
        local_selector.append("') )");
    }
    TopicSession session = null;
    TopicSubscriber subscriber = null;
    Topic the_topic = createTopic(topic);
    try {
        session = connection.createTopicSession();
        subscriber = session.createSubscriber(the_topic, local_selector.toString(), false);
    } catch (JMSSecurityException jse) {
        cat.error("JMSSecurityException caught");
        throw (new NamingException(jse.getMessage()));
    } catch (JMSException je) {
        cat.error("JMSException caught");
        throw (new NamingException(je.getMessage()));
    } catch (ConnectionException ce) {
        cat.error("ConnectionException caught");
        throw (new JMSException(ce.getMessage()));
    } catch (Exception e) {
        cat.error("Generic exception caught", e);
    }
    subscriber.setMessageListener(listener);
    handle.setSubscriber(subscriber);
    handle.setSession(session);
    synchronized (subscribers) {
        subscribers.put(new Long(handle.getSubscriptionToken()), handle);
    }
    if (!NotificationHelper.isNotification(topic)) {
        publishNotification(NotificationHelper.CONSUMER_OPEN_NOTIFICATION, handle);
    }
    return handle.getSubscriptionToken();
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TopicSession(javax.jms.TopicSession) JMSSecurityException(javax.jms.JMSSecurityException) JMSException(javax.jms.JMSException) NamingException(javax.naming.NamingException) Topic(javax.jms.Topic) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) MOMException(cern.cmw.mom.pubsub.MOMException) JMSSecurityException(javax.jms.JMSSecurityException)

Example 88 with NamingException

use of javax.naming.NamingException in project ACS by ACS-Community.

the class DefaultSubscriberImpl method publishNotification.

/**
   * Method publishNotification
   *
   * @param type
   * @param handle
   * @throws JMSException
   */
private void publishNotification(int type, SubscriptionHandle handle) throws JMSException {
    if (notificationsEnabled) {
        cat.info("publishNotification(" + type + ", " + handle.getSubscriptionTopic() + ", " + handle.getSubscriptionSelector() + ")");
        notificationMessage.setIntProperty(NotificationHelper.NOTIFICATION_TYPE_PROPERTY, type);
        notificationMessage.setStringProperty(NotificationHelper.SELECTOR_PROPERTY, handle.getSubscriptionSelector());
        notificationMessage.setStringProperty(NotificationHelper.TOPIC_PROPERTY, handle.getSubscriptionTopic());
        notificationMessage.setStringProperty(NotificationHelper.SUBSCRIPTION_ID_PROPERTY, subscriberId + "@" + handle.getSubscriptionToken());
        Topic t = null;
        try {
            t = createTopic(NotificationHelper.CarrierTopics[type]);
        } catch (NamingException ne) {
            ne.printStackTrace();
        }
        notificationPublisher.publish(t, notificationMessage);
    }
}
Also used : NamingException(javax.naming.NamingException) Topic(javax.jms.Topic)

Example 89 with NamingException

use of javax.naming.NamingException in project ACS by ACS-Community.

the class JNDIContext method lookup.

/**
	 * @see Context#lookup(Name)
	 * THIS IS OLD CDB implementation
	public Object lookup(Name name) throws NamingException {
		//System.out.println("CDBContext lookup on " + this.name + " for " + name.toString());
		String nameToLookup = this.name + "/" + name;
		String recordName = nameToLookup.substring(nameToLookup.lastIndexOf('/')+1);
		// get list from the server 
		String elements = dal.list_nodes(nameToLookup);
		try {
			if (elements.indexOf(recordName + ".xml") != -1) {
				String xml = dal.get_DAO(nameToLookup);
				return new JNDIXMLContext(nameToLookup, elements, xml);
			} else {
				if (elements.length() == 0 ) { // inside a XML?
					int slashIndex = nameToLookup.lastIndexOf('/');
					String newName;
					while( slashIndex != -1 ) {
						newName = nameToLookup.substring(0,slashIndex);
						recordName = newName.substring(newName.lastIndexOf('/')+1);
						elements = dal.list_nodes(newName);
						if (elements.indexOf(recordName + ".xml") != -1) {
							String xml = dal.get_DAO(newName);
							recordName = nameToLookup.substring(slashIndex+1);
							return new JNDIXMLContext(newName, elements, xml).lookup(recordName);
						}
						slashIndex = newName.lastIndexOf('/');
					}
					throw new NamingException("No name " + nameToLookup );
				}
				return new JNDIContext(nameToLookup, elements);
			}
		} catch (CDBRecordDoesNotExistEx e) {
			// if it does not exists then it is just a context
			return new JNDIContext(nameToLookup, elements);
		} catch (CDBXMLErrorEx e) {
			AcsJCDBXMLErrorEx acse = new AcsJCDBXMLErrorEx(e);
			throw new NamingException(acse.getFilename());
		}
	}*/
/**
     * This methos returns either a new JNDI_Context or a new JNDI_XMLContxt obj.
     */
public Object lookup(Name name) throws NamingException {
    final String lookupName = name.toString();
    final String fullLookupName = this.name + "/" + lookupName;
    String daoElements = dal.list_daos(fullLookupName);
    if (daoElements.length() == 0)
        daoElements = null;
    // is subnode
    StringTokenizer token = new StringTokenizer(elements);
    while (token.hasMoreTokens()) if (token.nextElement().equals(lookupName)) {
        // is DAO?
        if (daoElements != null) {
            try {
                return new JNDIXMLContext(fullLookupName, dal.list_nodes(fullLookupName), dal.get_DAO(fullLookupName), logger);
            } catch (CDBXMLErrorEx th) {
                AcsJCDBXMLErrorEx jex = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(th);
                NamingException ex2 = new NamingException(jex.getFilename() + ": " + jex.getErrorString());
                ex2.setRootCause(jex);
                throw ex2;
            } catch (Throwable th) {
                throw new NamingException("Failed to retrieve DAO: " + fullLookupName);
            }
        } else
            return new JNDIContext(fullLookupName, dal.list_nodes(fullLookupName), logger);
    }
    if (daoElements != null) {
        // lookup in DAO
        token = new StringTokenizer(daoElements);
        while (token.hasMoreTokens()) if (token.nextElement().equals(lookupName)) {
            try {
                return new JNDIXMLContext(fullLookupName, dal.list_nodes(fullLookupName), dal.get_DAO(fullLookupName), logger);
            } catch (CDBXMLErrorEx th) {
                AcsJCDBXMLErrorEx jex = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(th);
                NamingException ex2 = new NamingException(jex.getFilename() + ": " + jex.getErrorString());
                ex2.setRootCause(jex);
                throw ex2;
            } catch (Throwable th) {
                throw new NamingException("Failed to retrieve DAO: " + fullLookupName);
            }
        }
    }
    // not found
    throw new NamingException("No name " + fullLookupName);
}
Also used : StringTokenizer(java.util.StringTokenizer) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) NamingException(javax.naming.NamingException)

Example 90 with NamingException

use of javax.naming.NamingException in project Activiti by Activiti.

the class LDAPUserManager method findUserByQueryCriteria.

@Override
public List<User> findUserByQueryCriteria(final UserQueryImpl query, final Page page) {
    if (query.getId() != null) {
        List<User> result = new ArrayList<User>();
        result.add(findUserById(query.getId()));
        return result;
    } else if (query.getFullNameLike() != null) {
        final String fullNameLike = query.getFullNameLike().replaceAll("%", "");
        LDAPTemplate ldapTemplate = new LDAPTemplate(ldapConfigurator);
        return ldapTemplate.execute(new LDAPCallBack<List<User>>() {

            public List<User> executeInContext(InitialDirContext initialDirContext) {
                List<User> result = new ArrayList<User>();
                try {
                    String searchExpression = ldapConfigurator.getLdapQueryBuilder().buildQueryByFullNameLike(ldapConfigurator, fullNameLike);
                    String baseDn = ldapConfigurator.getUserBaseDn() != null ? ldapConfigurator.getUserBaseDn() : ldapConfigurator.getBaseDn();
                    NamingEnumeration<?> namingEnum = initialDirContext.search(baseDn, searchExpression, createSearchControls());
                    while (namingEnum.hasMore()) {
                        SearchResult searchResult = (SearchResult) namingEnum.next();
                        UserEntity user = new UserEntity();
                        mapSearchResultToUser(searchResult, user);
                        result.add(user);
                    }
                    namingEnum.close();
                } catch (NamingException ne) {
                    logger.debug("Could not execute LDAP query: " + ne.getMessage(), ne);
                    return null;
                }
                return result;
            }
        });
    } else {
        throw new ActivitiIllegalArgumentException("Query is currently not supported by LDAPUserManager.");
    }
}
Also used : User(org.activiti.engine.identity.User) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ArrayList(java.util.ArrayList) SearchResult(javax.naming.directory.SearchResult) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) UserEntity(org.activiti.engine.impl.persistence.entity.UserEntity)

Aggregations

NamingException (javax.naming.NamingException)698 InitialContext (javax.naming.InitialContext)234 Context (javax.naming.Context)169 IOException (java.io.IOException)82 NameNotFoundException (javax.naming.NameNotFoundException)67 SQLException (java.sql.SQLException)58 Reference (javax.naming.Reference)53 DataSource (javax.sql.DataSource)52 Test (org.junit.Test)51 Attribute (javax.naming.directory.Attribute)49 DirContext (javax.naming.directory.DirContext)48 Properties (java.util.Properties)45 ArrayList (java.util.ArrayList)41 Name (javax.naming.Name)36 SearchResult (javax.naming.directory.SearchResult)35 Hashtable (java.util.Hashtable)34 InitialDirContext (javax.naming.directory.InitialDirContext)34 Connection (java.sql.Connection)33 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)32 Attributes (javax.naming.directory.Attributes)30