Package org.picketlink.identity.federation.web.servlets

Examples of org.picketlink.identity.federation.web.servlets.IDPServlet$SessionHolder


        IdentityServer server = this.getIdentityServer(session);
        servletContext.setAttribute("IDENTITY_SERVER", server);
        MockServletConfig servletConfig = new MockServletConfig(servletContext);

        IDPServlet idp = new IDPServlet();
        // No signing outgoing messages
        servletConfig.addInitParameter(GeneralConstants.SIGN_OUTGOING_MESSAGES, "false");

        // Initialize the servlet
        idp.init(servletConfig);

        // Assume that we already have the principal and roles set in the session
        session.setAttribute(GeneralConstants.PRINCIPAL_ID, new Principal() {
            public String getName() {
                return "anil";
            }
        });
        List<String> rolesList = new ArrayList<String>();
        rolesList.add("manager");
        session.setAttribute(GeneralConstants.ROLES_ID, rolesList);

        MockHttpServletRequest request = new MockHttpServletRequest(session, "POST");
        request.addHeader("Referer", sales);

        String samlMessage = Base64.encodeBytes(createLogOutRequest(sales).getBytes());
        session.setAttribute("SAMLRequest", samlMessage);

        MockHttpServletResponse response = new MockHttpServletResponse();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        response.setOutputStream(baos);

        // The IDP is preloaded with 2 participants : "http://localhost:8080/sales/"
        // and "http://localhost:8080/employee"

        // Lets start the workflow with post
        idp.testPost(request, response);

        String idpResponse = new String(baos.toByteArray());
        assertNotNull(idpResponse);

        Document htmlResponse = DocumentUtil.getDocument(idpResponse);
        assertNotNull(htmlResponse);
        NodeList nodes = htmlResponse.getElementsByTagName("INPUT");
        Element inputElement = (Element) nodes.item(0);
        String logoutOrigResponse = inputElement.getAttributeNode("VALUE").getValue();

        String relayState = null;
        if (nodes.getLength() > 1)
            relayState = ((Element) nodes.item(1)).getAttributeNode("VALUE").getValue();

        String logoutResponse = new String(Base64.decode(logoutOrigResponse));

        SAML2Request samlRequest = new SAML2Request();
        ByteArrayInputStream bis = new ByteArrayInputStream(logoutResponse.getBytes());
        SAML2Object samlObject = samlRequest.getSAML2ObjectFromStream(bis);
        assertTrue(samlObject instanceof LogoutRequestType);

        // Let us feed the LogOutRequest to the SPFilter
        MockContextClassLoader mclSPEmp = setupTCL(profile + "/sp/employee");
        Thread.currentThread().setContextClassLoader(mclSPEmp);
        SPFilter spEmpl = new SPFilter();
        MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
        filterConfig.addInitParameter(GeneralConstants.IGNORE_SIGNATURES, "true");

        spEmpl.init(filterConfig);

        MockHttpSession filterSession = new MockHttpSession();
        MockHttpServletRequest filterRequest = new MockHttpServletRequest(filterSession, "POST");
        filterRequest.addParameter("SAMLResponse", logoutOrigResponse);
        filterRequest.addParameter("RelayState", relayState);

        MockHttpServletResponse filterResponse = new MockHttpServletResponse();
        ByteArrayOutputStream filterbaos = new ByteArrayOutputStream();
        filterResponse.setOutputStream(filterbaos);

        spEmpl.doFilter(filterRequest, filterResponse, new MockFilterChain());
        String spResponse = new String(filterbaos.toByteArray());
        Document spHTMLResponse = DocumentUtil.getDocument(spResponse);
        nodes = spHTMLResponse.getElementsByTagName("INPUT");
        inputElement = (Element) nodes.item(0);
        logoutOrigResponse = inputElement.getAttributeNode("VALUE").getValue();
        relayState = null;
        if (nodes.getLength() > 1)
            relayState = ((Element) nodes.item(1)).getAttributeNode("VALUE").getValue();

        // Now the SP (employee app) has logged out and sending a status response to IDP
        Thread.currentThread().setContextClassLoader(mclIDP);
        session.setAttribute("SAMLResponse", logoutOrigResponse);
        session.setAttribute("RelayState", relayState);

        idp.testPost(request, response);

        idpResponse = new String(filterbaos.toByteArray());
        assertNotNull(idpResponse);

        htmlResponse = DocumentUtil.getDocument(idpResponse);
View Full Code Here


        String samlMessage = Base64.encodeBytes(samlAuth.getBytes());
        session.setAttribute("SAMLRequest", samlMessage);

        login.testPost(request, response);

        IDPServlet idp = new IDPServlet();
        // No signing outgoing messages
        servletConfig.addInitParameter(GeneralConstants.SIGN_OUTGOING_MESSAGES, "false");

        // Initialize the servlet
        idp.init(servletConfig);

        // Lets start the workflow with post
        idp.testPost(request, response);

        String idpResponseString = new String(baos.toByteArray());
        Document idpHTMLResponse = DocumentUtil.getDocument(idpResponseString);
        nodes = idpHTMLResponse.getElementsByTagName("INPUT");
        inputElement = (Element) nodes.item(0);
View Full Code Here

  @Before
  public void setUp() throws Exception
    System.out.println("====================start");
        session = SessionFactoryUtils.getSession(sessionFactory, true)
        session.setFlushMode(FlushMode.NEVER)
        TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session))
    }
View Full Code Here

  @Before
  public void setUp() throws Exception
    System.out.println("====================start");
        session = SessionFactoryUtils.getSession(sessionFactory, true)
        session.setFlushMode(FlushMode.NEVER)
        TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session))
    }
View Full Code Here

        participate = true;
      }
      else {
        logger.debug("Opening single Hibernate Session in OpenSessionInViewFilter");
        Session session = getSession(sessionFactory);
        TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
      }
    }
    else {
      // deferred close mode
      if (SessionFactoryUtils.isDeferredCloseActive(sessionFactory)) {
        // Do not modify deferred close: just set the participate flag.
        participate = true;
      }
      else {
        SessionFactoryUtils.initDeferredClose(sessionFactory);
      }
    }

    try {
      filterChain.doFilter(request, response);
    }

    finally {
      if (!participate) {
        if (isSingleSession()) {
          // single session mode
          SessionHolder sessionHolder =
              (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
          logger.debug("Closing single Hibernate Session in OpenSessionInViewFilter");
          closeSession(sessionHolder.getSession(), sessionFactory);
        }
        else {
          // deferred close mode
          SessionFactoryUtils.processDeferredClose(sessionFactory);
        }
View Full Code Here

        // single session mode
        logger.debug("Opening single Hibernate Session in OpenSessionInViewInterceptor");
        Session session = SessionFactoryUtils.getSession(
            getSessionFactory(), getEntityInterceptor(), getJdbcExceptionTranslator());
        applyFlushMode(session, false);
        TransactionSynchronizationManager.bindResource(getSessionFactory(), new SessionHolder(session));
      }
      else {
        // deferred close mode
        SessionFactoryUtils.initDeferredClose(getSessionFactory());
      }
View Full Code Here

   * @see #setFlushMode
   */
  public void postHandle(WebRequest request, ModelMap model) throws DataAccessException {
    if (isSingleSession()) {
      // Only potentially flush in single session mode.
      SessionHolder sessionHolder =
          (SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
      logger.debug("Flushing single Hibernate Session in OpenSessionInViewInterceptor");
      try {
        flushIfNecessary(sessionHolder.getSession(), false);
      }
      catch (HibernateException ex) {
        throw convertHibernateAccessException(ex);
      }
    }
View Full Code Here

      }
    }
    else {
      if (isSingleSession()) {
        // single session mode
        SessionHolder sessionHolder =
            (SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
        logger.debug("Closing single Hibernate Session in OpenSessionInViewInterceptor");
        SessionFactoryUtils.closeSession(sessionHolder.getSession());
      }
      else {
        // deferred close mode
        SessionFactoryUtils.processDeferredClose(getSessionFactory());
      }
View Full Code Here

        // single session mode
        logger.debug("Opening single Hibernate Session in OpenSessionInViewInterceptor");
        Session session = SessionFactoryUtils.getSession(
            getSessionFactory(), getEntityInterceptor(), getJdbcExceptionTranslator());
        applyFlushMode(session, false);
        TransactionSynchronizationManager.bindResource(getSessionFactory(), new SessionHolder(session));
      }
      else {
        // deferred close mode
        SessionFactoryUtils.initDeferredClose(getSessionFactory());
      }
View Full Code Here

   * @see #setFlushMode
   */
  public void postHandle(WebRequest request, ModelMap model) throws DataAccessException {
    if (isSingleSession()) {
      // Only potentially flush in single session mode.
      SessionHolder sessionHolder =
          (SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
      logger.debug("Flushing single Hibernate Session in OpenSessionInViewInterceptor");
      try {
        flushIfNecessary(sessionHolder.getSession(), false);
      }
      catch (HibernateException ex) {
        throw convertHibernateAccessException(ex);
      }
    }
View Full Code Here

TOP

Related Classes of org.picketlink.identity.federation.web.servlets.IDPServlet$SessionHolder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.