Search in sources :

Example 1 with SSOAgentConfig

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

the class SSOAgentSampleFilter method doFilter.

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    String httpBinding = servletRequest.getParameter(SSOAgentConstants.SSOAgentConfig.SAML2.HTTP_BINDING);
    if (httpBinding != null && !httpBinding.isEmpty()) {
        if ("HTTP-POST".equals(httpBinding)) {
            httpBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST";
        } else if ("HTTP-Redirect".equals(httpBinding)) {
            httpBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect";
        } else {
            LOGGER.log(Level.INFO, "Unknown SAML2 HTTP Binding. Defaulting to HTTP-POST");
            httpBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST";
        }
    } else {
        LOGGER.log(Level.INFO, "SAML2 HTTP Binding not found in request. Defaulting to HTTP-POST");
        httpBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST";
    }
    SSOAgentConfig config = (SSOAgentConfig) filterConfig.getServletContext().getAttribute(SSOAgentConstants.CONFIG_BEAN_NAME);
    config.getSAML2().setHttpBinding(httpBinding);
    config.getOpenId().setClaimedId(servletRequest.getParameter(SSOAgentConstants.SSOAgentConfig.OpenID.CLAIMED_ID));
    config.getOpenId().setMode(servletRequest.getParameter(SSOAgentConstants.OpenID.OPENID_MODE));
    if (StringUtils.isNotEmpty(servletRequest.getParameter(USERNAME)) && StringUtils.isNotEmpty(servletRequest.getParameter(PASSWORD))) {
        String authorization = servletRequest.getParameter(USERNAME) + ":" + servletRequest.getParameter(PASSWORD);
        // Base64 encoded username:password value
        authorization = new String(Base64.encode(authorization.getBytes(CHARACTER_ENCODING)));
        String htmlPayload = "<html>\n" + "<body>\n" + "<p>You are now redirected back to " + properties.getProperty("SAML2.IdPURL") + " \n" + "If the redirection fails, please click the post button.</p>\n" + "<form method='post' action='" + properties.getProperty("SAML2.IdPURL") + "'>\n" + "<input type='hidden' name='sectoken' value='" + authorization + "'/>\n" + "<p>\n" + "<!--$saml_params-->\n" + "<button type='submit'>POST</button>\n" + "</p>\n" + "</form>\n" + "<script type='text/javascript'>\n" + "document.forms[0].submit();\n" + "</script>\n" + "</body>\n" + "</html>";
        config.getSAML2().setPostBindingRequestHTMLPayload(htmlPayload);
    } else {
        // Reset previously sent HTML payload
        config.getSAML2().setPostBindingRequestHTMLPayload(null);
    }
    servletRequest.setAttribute(SSOAgentConstants.CONFIG_BEAN_NAME, config);
    super.doFilter(servletRequest, servletResponse, filterChain);
}
Also used : SSOAgentConfig(org.wso2.carbon.identity.sso.agent.bean.SSOAgentConfig)

Example 2 with SSOAgentConfig

use of org.wso2.carbon.identity.sso.agent.bean.SSOAgentConfig 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

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