コード例 #1
0
 /**
  * Verifies that required entities were autowired or set.
  *
  * @throws ServletException
  */
 @Override
 public void afterPropertiesSet() throws ServletException {
   super.afterPropertiesSet();
   Assert.notNull(profile, "Single logout profile must be set");
   Assert.notNull(contextProvider, "Context provider must be set");
   Assert.notNull(samlLogger, "SAML Logger must be set");
 }
コード例 #2
0
  @Test
  public void logoutUrl() throws Exception {
    request.setServletPath("/j_spring_security_logout");

    filter.doFilter(request, response, chain);

    assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_FOUND);
  }
コード例 #3
0
  @Override
  public void afterPropertiesSet() throws ServletException {
    super.afterPropertiesSet();

    if (getTimeOutLogoutUri() == null) {
      throw new ServletException(
          getClass().getName() + ".afterPropertiesSet: timeOutLogoutUri property required.");
    }
  }
コード例 #4
0
  public void testRequiresLogoutUrlWorksWithQueryParams() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/context");
    MockHttpServletResponse response = new MockHttpServletResponse();

    request.setServletPath("/logout");
    request.setRequestURI("/context/logout?param=blah");
    request.setQueryString("otherparam=blah");

    assertTrue(filter.requiresLogout(request, response));
  }
コード例 #5
0
  public void testRequiresLogoutUrlWorksWithPathParams() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    request.setRequestURI("/context/logout;someparam=blah?param=blah");
    request.setServletPath("/logout;someparam=blah");
    request.setQueryString("otherparam=blah");

    DefaultHttpFirewall fw = new DefaultHttpFirewall();
    assertTrue(filter.requiresLogout(fw.getFirewalledRequest(request), response));
  }
コード例 #6
0
  /**
   * In case request parameter of name "local" is set to true or there is no authenticated user only
   * local logout will be performed and user will be redirected to the success page. Otherwise
   * global logout procedure is initialized.
   *
   * @param request http request
   * @param response http response
   * @param chain chain
   * @throws IOException error
   * @throws ServletException error
   */
  public void processLogout(
      HttpServletRequest request, HttpServletResponse response, FilterChain chain)
      throws IOException, ServletException {

    if (requiresLogout(request, response)) {

      try {

        Authentication auth = SecurityContextHolder.getContext().getAuthentication();

        if (auth != null && isGlobalLogout(request, auth)) {

          Assert.isInstanceOf(
              SAMLCredential.class,
              auth.getCredentials(),
              "Authentication object doesn't contain SAML credential, cannot perform global logout");

          // Terminate the session first
          for (LogoutHandler handler : globalHandlers) {
            handler.logout(request, response, auth);
          }

          // Notify session participants using SAML Single Logout profile
          SAMLCredential credential = (SAMLCredential) auth.getCredentials();
          request.setAttribute(SAMLConstants.LOCAL_ENTITY_ID, credential.getLocalEntityID());
          SAMLMessageContext context = contextProvider.getLocalEntity(request, response);
          profile.sendLogoutRequest(context, credential);
          samlLogger.log(SAMLConstants.LOGOUT_REQUEST, SAMLConstants.SUCCESS, context);

        } else {

          super.doFilter(request, response, chain);
        }

      } catch (SAMLException e1) {
        throw new ServletException("Error initializing global logout", e1);
      } catch (MetadataProviderException e1) {
        throw new ServletException("Error processing metadata", e1);
      } catch (MessageEncodingException e1) {
        throw new ServletException("Error encoding outgoing message", e1);
      }

    } else {

      chain.doFilter(request, response);
    }
  }
コード例 #7
0
 @Bean
 public LogoutFilter logoutFilter() {
   LogoutFilter filter = new LogoutFilter("/logout/success", new SecurityContextLogoutHandler());
   filter.setFilterProcessesUrl("/j_spring_security_logout");
   return filter;
 }