de.hybris.platform.acceleratorstorefrontcommons.security.StorefrontLogoutSuccessHandler.java Source code

Java tutorial

Introduction

Here is the source code for de.hybris.platform.acceleratorstorefrontcommons.security.StorefrontLogoutSuccessHandler.java

Source

/*
 * [y] hybris Platform
 *
 * Copyright (c) 2000-2016 hybris AG
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of hybris
 * ("Confidential Information"). You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the
 * license agreement you entered into with hybris.
 *
 *  
 */
package de.hybris.platform.acceleratorstorefrontcommons.security;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;

public class StorefrontLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {
    private GUIDCookieStrategy guidCookieStrategy;
    private List<String> restrictedPages;

    protected GUIDCookieStrategy getGuidCookieStrategy() {
        return guidCookieStrategy;
    }

    @Required
    public void setGuidCookieStrategy(final GUIDCookieStrategy guidCookieStrategy) {
        this.guidCookieStrategy = guidCookieStrategy;
    }

    protected List<String> getRestrictedPages() {
        return restrictedPages;
    }

    public void setRestrictedPages(final List<String> restrictedPages) {
        this.restrictedPages = restrictedPages;
    }

    @Override
    public void onLogoutSuccess(final HttpServletRequest request, final HttpServletResponse response,
            final Authentication authentication) throws IOException, ServletException {
        getGuidCookieStrategy().deleteCookie(request, response);

        // Delegate to default redirect behaviour
        super.onLogoutSuccess(request, response, authentication);
    }

    @Override
    protected String determineTargetUrl(final HttpServletRequest request, final HttpServletResponse response) {
        String targetUrl = super.determineTargetUrl(request, response);

        for (final String restrictedPage : getRestrictedPages()) {
            // When logging out from a restricted page, return user to homepage.
            if (targetUrl.contains(restrictedPage)) {
                targetUrl = super.getDefaultTargetUrl();
            }
        }

        return targetUrl;
    }
}