Search in sources :

Example 6 with SecretResolver

use of org.wso2.securevault.SecretResolver in project carbon-business-process by wso2.

the class UnifiedEndpointFactory method createEndpoint.

public UnifiedEndpoint createEndpoint(OMElement uEPConfigEle) throws AxisFault {
    UnifiedEndpoint unifiedEndpoint = new UnifiedEndpoint();
    EndpointReferenceHelper.fromOM(unifiedEndpoint, uEPConfigEle, AddressingConstants.Final.WSA_NAMESPACE);
    OMElement metadataElem = uEPConfigEle.getFirstChildWithName(UnifiedEndpointConstants.METADATA_Q);
    if (metadataElem != null) {
        OMElement idElem = metadataElem.getFirstChildWithName(UnifiedEndpointConstants.METADATA_ID_Q);
        if (idElem != null) {
            unifiedEndpoint.setUepId(idElem.getText());
        } else {
            log.error("UEP Configuration violation: " + UnifiedEndpointConstants.METADATA_ID_Q + " not found");
        }
        /**
         * Discovery
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.METADATA_DISCOVERY_Q) != null) {
            extractDiscoveryConfig(unifiedEndpoint, metadataElem.getFirstChildWithName(UnifiedEndpointConstants.METADATA_DISCOVERY_Q));
        }
        /**
         * Timeout
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TIMEOUT_Q) != null) {
            extractTimeoutConfig(unifiedEndpoint, metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TIMEOUT_Q));
        }
        /**
         * WSDL Definitions
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.METADATA_WSDL11_DEFINITIONS_Q) != null) {
            unifiedEndpoint.setWsdl11Definitions(metadataElem.getFirstChildWithName(UnifiedEndpointConstants.METADATA_WSDL11_DEFINITIONS_Q));
        }
        /**
         * MessageOutput
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.MESSAGE_OUTPUT_Q) != null) {
            extractMessageOutPutConfig(unifiedEndpoint, metadataElem.getFirstChildWithName(UnifiedEndpointConstants.MESSAGE_OUTPUT_Q));
        }
        /**
         * Transport
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q) != null) {
            extractTransportConfig(unifiedEndpoint, metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q));
            if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q).getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_AUTHORIZATION_USERNAME_Q) != null) {
                unifiedEndpoint.setAuthorizationUserName(metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q).getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_AUTHORIZATION_USERNAME_Q).getText());
            }
            if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q).getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_AUTHORIZATION_PASSWORD_Q) != null) {
                OMElement transport_auth_password = metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q).getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_AUTHORIZATION_PASSWORD_Q);
                String secretAlias = transport_auth_password.getAttributeValue(new QName(UnifiedEndpointConstants.SECURE_VAULT_NS, UnifiedEndpointConstants.SECRET_ALIAS_ATTR_NAME));
                if (secretAlias != null && secretAlias.trim().length() > 0) {
                    secretAlias = secretAlias.trim();
                    SecretResolver secretResolver = SecretResolverFactory.create(metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q), false);
                    /* Setting the secured password */
                    if (secretResolver != null && secretResolver.isInitialized() && secretResolver.isTokenProtected(secretAlias)) {
                        String adminPassword = secretResolver.resolve(secretAlias);
                        unifiedEndpoint.setAuthorizationPassword(adminPassword);
                    } else {
                        /* If secure vault is not configured properly, Reading plain text password */
                        unifiedEndpoint.setAuthorizationPassword(metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q).getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_AUTHORIZATION_PASSWORD_Q).getText());
                    }
                } else {
                    unifiedEndpoint.setAuthorizationPassword(metadataElem.getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_Q).getFirstChildWithName(UnifiedEndpointConstants.TRANSPORT_AUTHORIZATION_PASSWORD_Q).getText());
                }
            }
        }
        /**
         * Monitoring
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.MONITORING_Q) != null) {
            extractMetadataMonitoringConfig(unifiedEndpoint, metadataElem.getFirstChildWithName(UnifiedEndpointConstants.MONITORING_Q));
        }
        /**
         * QoS
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.QOS_Q) != null) {
            extractQoSConfig(unifiedEndpoint, metadataElem.getFirstChildWithName(UnifiedEndpointConstants.QOS_Q));
        }
        /**
         * Session
         */
        if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.SESSION_Q) != null) {
            if (metadataElem.getFirstChildWithName(UnifiedEndpointConstants.SESSION_Q).getAttributeValue(UnifiedEndpointConstants.SESSION_TYPE_Q) != null) {
                unifiedEndpoint.setSessionType(metadataElem.getFirstChildWithName(UnifiedEndpointConstants.SESSION_Q).getAttributeValue(UnifiedEndpointConstants.SESSION_TYPE_Q));
            }
        }
    }
    return unifiedEndpoint;
}
Also used : SecretResolver(org.wso2.securevault.SecretResolver) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 7 with SecretResolver

use of org.wso2.securevault.SecretResolver in project carbon-business-process by wso2.

the class HumanTaskServerConfiguration method getAuthenticationConfig.

private void getAuthenticationConfig(File file, TRegServiceAuth authentication) {
    // Since secretResolver only accept Element we have to build Element here.
    SecretResolver secretResolver = null;
    InputStream in = null;
    try {
        in = new FileInputStream(file);
        StAXOMBuilder builder = new StAXOMBuilder(in);
        secretResolver = SecretResolverFactory.create(builder.getDocumentElement(), true);
    } catch (Exception e) {
        log.warn("Error occurred while retrieving secured TaskEngineProtocolHandler configuration.", e);
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
            log.error(e.getLocalizedMessage(), e);
        }
    }
    // Get Username
    if (secretResolver != null && secretResolver.isInitialized() && secretResolver.isTokenProtected(HumanTaskConstants.B4P_REGISTRATIONS_USERNAME_ALIAS)) {
        this.registrationServiceAuthUsername = secretResolver.resolve(HumanTaskConstants.B4P_REGISTRATIONS_USERNAME_ALIAS);
        if (log.isDebugEnabled()) {
            log.debug("Loaded Registration service admin username from secure vault");
        }
    } else {
        if (authentication.getUsername() != null) {
            this.registrationServiceAuthUsername = authentication.getUsername();
        }
    }
    // Get Password
    if (secretResolver != null && secretResolver.isInitialized() && secretResolver.isTokenProtected(HumanTaskConstants.B4P_REGISTRATIONS_PASSWORD_ALIAS)) {
        this.registrationServiceAuthPassword = secretResolver.resolve(HumanTaskConstants.B4P_REGISTRATIONS_PASSWORD_ALIAS);
        if (log.isDebugEnabled()) {
            log.debug("Loaded  Registration service admin password from secure vault");
        }
    } else {
        if (authentication.getPassword() != null) {
            this.registrationServiceAuthPassword = authentication.getPassword();
        }
    }
}
Also used : SecretResolver(org.wso2.securevault.SecretResolver) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) XmlException(org.apache.xmlbeans.XmlException)

Example 8 with SecretResolver

use of org.wso2.securevault.SecretResolver in project wso2-axis2-transports by wso2.

the class JMSSender method init.

/**
 * Initialize the transport sender by reading pre-defined connection factories for
 * outgoing messages.
 *
 * @param cfgCtx the configuration context
 * @param transportOut the transport sender definition from axis2.xml
 * @throws AxisFault on error
 */
@Override
public void init(ConfigurationContext cfgCtx, TransportOutDescription transportOut) throws AxisFault {
    super.init(cfgCtx, transportOut);
    SecretResolver secretResolver = cfgCtx.getAxisConfiguration().getSecretResolver();
    connFacManager = new JMSConnectionFactoryManager(transportOut, secretResolver);
    log.info("JMS Transport Sender initialized...");
}
Also used : SecretResolver(org.wso2.securevault.SecretResolver)

Example 9 with SecretResolver

use of org.wso2.securevault.SecretResolver in project carbon-business-process by wso2.

the class CoordinationConfiguration method getAuthenticationConfig.

/**
 * Get protocol handler admin username and password from secure vault. If secure vault not set then
 * parse authentication configuration and extract protocol handler admin username and password
 *
 * @param file
 * @param authentication
 */
private void getAuthenticationConfig(File file, TTaskAuthenticationConfig authentication) {
    // Since secretResolver only accept Element we have to build Element here.
    SecretResolver secretResolver = null;
    InputStream in = null;
    try {
        in = new FileInputStream(file);
        StAXOMBuilder builder = new StAXOMBuilder(in);
        secretResolver = SecretResolverFactory.create(builder.getDocumentElement(), true);
    } catch (Exception e) {
        log.warn("Error occurred while retrieving secured TaskEngineProtocolHandler configuration.", e);
    } finally {
        try {
            in.close();
        } catch (IOException e) {
            log.error(e.getLocalizedMessage(), e);
        }
    }
    // Get Username
    if (secretResolver != null && secretResolver.isInitialized() && secretResolver.isTokenProtected(PROTOCOL_HANDLER_USERNAME_ALIAS)) {
        protocolHandlerAdminUser = secretResolver.resolve(PROTOCOL_HANDLER_USERNAME_ALIAS);
        if (log.isDebugEnabled()) {
            log.debug("Loaded TaskEngine's protocol handler username from secure vault");
        }
    } else {
        if (authentication.getUsername() != null) {
            this.protocolHandlerAdminUser = authentication.getUsername();
        }
    }
    // Get Password
    if (secretResolver != null && secretResolver.isInitialized() && secretResolver.isTokenProtected(PROTOCOL_HANDLER_PASSWORD_ALIAS)) {
        protocolHandlerAdminPassword = secretResolver.resolve(PROTOCOL_HANDLER_PASSWORD_ALIAS);
        if (log.isDebugEnabled()) {
            log.debug("Loaded TaskEngine's protocol handler password from secure vault");
        }
    } else {
        if (authentication.getPassword() != null) {
            this.protocolHandlerAdminPassword = authentication.getPassword();
        }
    }
}
Also used : SecretResolver(org.wso2.securevault.SecretResolver) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlException(org.apache.xmlbeans.XmlException)

Aggregations

SecretResolver (org.wso2.securevault.SecretResolver)8 StAXOMBuilder (org.apache.axiom.om.impl.builder.StAXOMBuilder)3 XmlException (org.apache.xmlbeans.XmlException)3 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 QName (javax.xml.namespace.QName)2 OMElement (org.apache.axiom.om.OMElement)2 Properties (java.util.Properties)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 Parameter (org.apache.axis2.description.Parameter)1 SynapseCommonsException (org.apache.synapse.commons.SynapseCommonsException)1 TBPSAnalytics (org.wso2.carbon.bps.common.analytics.config.TBPSAnalytics)1 SecureVaultException (org.wso2.securevault.SecureVaultException)1 SecretInformation (org.wso2.securevault.secret.SecretInformation)1