Search in sources :

Example 1 with SSOAgentX509Credential

use of org.wso2.carbon.identity.sso.agent.saml.SSOAgentX509Credential in project identity-test-integration by wso2-incubator.

the class SampleContextEventListener method contextInitialized.

public void contextInitialized(ServletContextEvent servletContextEvent) {
    properties = new Properties();
    try {
        if (servletContextEvent.getServletContext().getContextPath().contains("travelocity.com")) {
            properties.load(servletContextEvent.getServletContext().getResourceAsStream("/WEB-INF/classes/travelocity.properties"));
        } else if (servletContextEvent.getServletContext().getContextPath().contains("avis.com")) {
            properties.load(servletContextEvent.getServletContext().getResourceAsStream("/WEB-INF/classes/avis.properties"));
        } else {
            String resourcePath = "/WEB-INF/classes" + servletContextEvent.getServletContext().getContextPath() + ".properties";
            InputStream resourceStream = servletContextEvent.getServletContext().getResourceAsStream(resourcePath);
            if (resourceStream != null) {
                properties.load(servletContextEvent.getServletContext().getResourceAsStream(resourcePath));
            }
        }
        InputStream keyStoreInputStream = servletContextEvent.getServletContext().getResourceAsStream("/WEB-INF/classes/wso2carbon.jks");
        SSOAgentX509Credential credential = new SSOAgentX509KeyStoreCredential(keyStoreInputStream, properties.getProperty("KeyStorePassword").toCharArray(), properties.getProperty("IdPPublicCertAlias"), properties.getProperty("PrivateKeyAlias"), properties.getProperty("PrivateKeyPassword").toCharArray());
        SSOAgentConfig config = new SSOAgentConfig();
        config.initConfig(properties);
        config.getSAML2().setSSOAgentX509Credential(credential);
        config.getOpenId().setAttributesRequestor(new SampleAttributesRequestor());
        servletContextEvent.getServletContext().setAttribute(SSOAgentConstants.CONFIG_BEAN_NAME, config);
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (SSOAgentException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    }
}
Also used : SSOAgentConfig(org.wso2.carbon.identity.sso.agent.bean.SSOAgentConfig) InputStream(java.io.InputStream) SSOAgentX509Credential(org.wso2.carbon.identity.sso.agent.saml.SSOAgentX509Credential) SSOAgentException(org.wso2.carbon.identity.sso.agent.SSOAgentException) IOException(java.io.IOException) Properties(java.util.Properties) SSOAgentX509KeyStoreCredential(org.wso2.carbon.identity.sso.agent.saml.SSOAgentX509KeyStoreCredential)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 SSOAgentException (org.wso2.carbon.identity.sso.agent.SSOAgentException)1 SSOAgentConfig (org.wso2.carbon.identity.sso.agent.bean.SSOAgentConfig)1 SSOAgentX509Credential (org.wso2.carbon.identity.sso.agent.saml.SSOAgentX509Credential)1 SSOAgentX509KeyStoreCredential (org.wso2.carbon.identity.sso.agent.saml.SSOAgentX509KeyStoreCredential)1