de.hybris.telcotrail.storefront.security.GUIDAuthenticationSuccessHandler.java Source code

Java tutorial

Introduction

Here is the source code for de.hybris.telcotrail.storefront.security.GUIDAuthenticationSuccessHandler.java

Source

/*
 * [y] hybris Platform
 *
 * Copyright (c) 2000-2015 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.telcotrail.storefront.security;

import de.hybris.platform.core.model.user.CustomerModel;
import de.hybris.platform.servicelayer.model.ModelService;
import de.hybris.platform.servicelayer.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Default implementation of {@link AuthenticationSuccessHandler}
 */
public class GUIDAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
    @Autowired
    private UserService userService;
    @Autowired
    private ModelService modelService;

    private GUIDCookieStrategy guidCookieStrategy;
    private AuthenticationSuccessHandler authenticationSuccessHandler;

    @Override
    public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response,
            final Authentication authentication) throws IOException, ServletException {
        CustomerModel customerModel = (CustomerModel) userService.getUserForUID(authentication.getName());
        customerModel.setAttemptCount(0);
        modelService.save(customerModel);

        getGuidCookieStrategy().setCookie(request, response);
        getAuthenticationSuccessHandler().onAuthenticationSuccess(request, response, authentication);
    }

    protected GUIDCookieStrategy getGuidCookieStrategy() {
        return guidCookieStrategy;
    }

    /**
     * @param guidCookieStrategy
     *           the guidCookieStrategy to set
     */
    @Required
    public void setGuidCookieStrategy(final GUIDCookieStrategy guidCookieStrategy) {
        this.guidCookieStrategy = guidCookieStrategy;
    }

    protected AuthenticationSuccessHandler getAuthenticationSuccessHandler() {
        return authenticationSuccessHandler;
    }

    /**
     * @param authenticationSuccessHandler
     *           the authenticationSuccessHandler to set
     */
    @Required
    public void setAuthenticationSuccessHandler(final AuthenticationSuccessHandler authenticationSuccessHandler) {
        this.authenticationSuccessHandler = authenticationSuccessHandler;
    }
}