Search in sources :

Example 1 with MessageListenerType

use of com.tremolosecurity.config.xml.MessageListenerType in project OpenUnison by TremoloSecurity.

the class LoadQueueListenersFromK8s method createQueue.

private void createQueue(TremoloType tremolo, String name, JSONObject item) throws ProvisioningException {
    JSONObject spec = (JSONObject) item.get("spec");
    MessageListenerType mlt = new MessageListenerType();
    mlt.setQueueName(name);
    StringBuffer b = new StringBuffer();
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("className"));
    mlt.setClassName(b.toString());
    JSONArray params = (JSONArray) spec.get("params");
    for (Object o : params) {
        JSONObject param = (JSONObject) o;
        ParamType pt = new ParamType();
        b.setLength(0);
        OpenUnisonConfigLoader.integrateIncludes(b, (String) param.get("name"));
        pt.setName(b.toString());
        b.setLength(0);
        OpenUnisonConfigLoader.integrateIncludes(b, (String) param.get("value"));
        pt.setValue(b.toString());
        mlt.getParams().add(pt);
    }
    HttpCon nonwatchHttp = null;
    JSONArray secretParams = (JSONArray) spec.get("secretParams");
    if (secretParams != null) {
        try {
            nonwatchHttp = this.k8sWatch.getK8s().createClient();
            String token = this.k8sWatch.getK8s().getAuthToken();
            for (Object o : secretParams) {
                JSONObject secretParam = (JSONObject) o;
                String paramName = (String) secretParam.get("name");
                String secretName = (String) secretParam.get("secretName");
                String secretKey = (String) secretParam.get("secretKey");
                String secretValue = this.k8sWatch.getSecretValue(secretName, secretKey, token, nonwatchHttp);
                ParamType pt = new ParamType();
                pt.setName(paramName);
                pt.setValue(secretValue);
                mlt.getParams().add(pt);
            }
        } catch (Exception e) {
            throw new ProvisioningException("Could not load secrets for '" + name + "'");
        } finally {
            if (nonwatchHttp != null) {
                try {
                    nonwatchHttp.getHttp().close();
                } catch (IOException e) {
                }
                nonwatchHttp.getBcm().close();
            }
        }
    }
    try {
        this.cfgMgr.getProvisioningEngine().addMessageListener(mlt);
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | ProvisioningException | JMSException e) {
        logger.warn("Could not create listener " + name, e);
    }
}
Also used : JSONArray(org.json.simple.JSONArray) JMSException(javax.jms.JMSException) IOException(java.io.IOException) ParamType(com.tremolosecurity.config.xml.ParamType) ClientProtocolException(org.apache.http.client.ClientProtocolException) ParseException(org.json.simple.parser.ParseException) HttpResponseException(org.apache.http.client.HttpResponseException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) HttpCon(com.tremolosecurity.provisioning.util.HttpCon) JSONObject(org.json.simple.JSONObject) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) JSONObject(org.json.simple.JSONObject) MessageListenerType(com.tremolosecurity.config.xml.MessageListenerType)

Example 2 with MessageListenerType

use of com.tremolosecurity.config.xml.MessageListenerType in project OpenUnison by TremoloSecurity.

the class SendMessageThread method initListeners.

@Override
public void initListeners() throws ProvisioningException {
    this.listenerSessions = new HashMap<String, JMSSessionHolder>();
    if (this.cfgMgr.getCfg().getProvisioning() == null || this.cfgMgr.getCfg().getProvisioning().getListeners() == null) {
        logger.warn("No listeners defined");
        return;
    }
    try {
        for (MessageListenerType mlt : this.cfgMgr.getCfg().getProvisioning().getListeners().getListener()) {
            addMessageListener(mlt);
        }
        if (cfgMgr.getCfg().getProvisioning().getListeners().getDynamicListeners() != null && cfgMgr.getCfg().getProvisioning().getListeners().getDynamicListeners().isEnabled()) {
            DynamicPortalUrlsType dynamicMessageListeners = cfgMgr.getCfg().getProvisioning().getListeners().getDynamicListeners();
            String className = dynamicMessageListeners.getClassName();
            HashMap<String, Attribute> cfgAttrs = new HashMap<String, Attribute>();
            for (ParamType pt : dynamicMessageListeners.getParams()) {
                Attribute attr = cfgAttrs.get(pt.getName());
                if (attr == null) {
                    attr = new Attribute(pt.getName());
                    cfgAttrs.put(pt.getName(), attr);
                }
                attr.getValues().add(pt.getValue());
            }
            DynamicQueueListeners dynamicQueueListener = (DynamicQueueListeners) Class.forName(className).newInstance();
            dynamicQueueListener.loadDynamicQueueListeners(cfgMgr, this, cfgAttrs);
        }
    } catch (Exception e) {
        logger.warn("Could not initialize listeners", e);
    }
}
Also used : Attribute(com.tremolosecurity.saml.Attribute) LDAPAttribute(com.novell.ldap.LDAPAttribute) HashMap(java.util.HashMap) DynamicPortalUrlsType(com.tremolosecurity.config.xml.DynamicPortalUrlsType) JMSSessionHolder(com.tremolosecurity.provisioning.jms.JMSSessionHolder) DynamicQueueListeners(com.tremolosecurity.provisioning.listeners.DynamicQueueListeners) ParamType(com.tremolosecurity.config.xml.ParamType) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) LDAPException(com.novell.ldap.LDAPException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SocketException(java.net.SocketException) SQLException(java.sql.SQLException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) MessagingException(javax.mail.MessagingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) JMSException(javax.jms.JMSException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) BadPaddingException(javax.crypto.BadPaddingException) MessageListenerType(com.tremolosecurity.config.xml.MessageListenerType)

Aggregations

MessageListenerType (com.tremolosecurity.config.xml.MessageListenerType)2 ParamType (com.tremolosecurity.config.xml.ParamType)2 IOException (java.io.IOException)2 JMSException (javax.jms.JMSException)2 LDAPAttribute (com.novell.ldap.LDAPAttribute)1 LDAPException (com.novell.ldap.LDAPException)1 DynamicPortalUrlsType (com.tremolosecurity.config.xml.DynamicPortalUrlsType)1 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 JMSSessionHolder (com.tremolosecurity.provisioning.jms.JMSSessionHolder)1 DynamicQueueListeners (com.tremolosecurity.provisioning.listeners.DynamicQueueListeners)1 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)1 Attribute (com.tremolosecurity.saml.Attribute)1 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SocketException (java.net.SocketException)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SQLException (java.sql.SQLException)1