/*
 * Copyright (C) 2018 the original author or authors.
 *
 * This file is part of jBB Application Project.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  You may obtain a copy of the License at
 *        http://www.apache.org/licenses/LICENSE-2.0
 */

package org.jbb.security.rest.signin;

import org.jbb.lib.commons.security.SecurityContentUser;
import org.jbb.lib.eventbus.JbbEventBus;
import org.jbb.security.api.lockout.MemberLockoutService;
import org.jbb.security.event.SignInSuccessEvent;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

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

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
@Component("restAuthenticationSuccessHandler")
public class RestAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

    private final MemberLockoutService memberLockoutService;
    private final JbbEventBus eventBus;

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse httpServletResponse, Authentication authentication) {
        SecurityContentUser user = (SecurityContentUser) authentication.getPrincipal();
        log.debug("Member with id '{}' sign in successful", user.getUserId());
        memberLockoutService.cleanFailedAttemptsForMember(user.getUserId());
        eventBus.post(new SignInSuccessEvent(user.getUserId(), request.getSession().getId(), false));
        ServerHttpResponse outputMessage = new ServletServerHttpResponse(httpServletResponse);
        outputMessage.setStatusCode(HttpStatus.NO_CONTENT);
    }

}

@@ -568,133 +568,8 @@
 us;%0A
-import org.springframework.http.server.ServerHttpResponse;%0Aimport org.springframework.http.server.ServletServerHttpResponse;%0A
 impo
@@ -1708,115 +1708,26 @@
     
-ServerHttpResponse outputMessage = new ServletServerHttpResponse(httpServletResponse);%0A        outputMessag
+httpServletRespons
 e.se
@@ -1737,12 +1737,8 @@
 atus
-Code
 (Htt
@@ -1755,16 +1755,24 @@
 _CONTENT
+.value()
 );%0A    %7D

Update RestAuthenticationSuccessHandler