All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.mynewtons.starter.oauth2.config.security.CustomLogoutSuccessHandler Maven / Gradle / Ivy

The newest version!
package ru.mynewtons.starter.oauth2.config.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.approval.ApprovalStore;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
import org.springframework.security.web.authentication.AbstractAuthenticationTargetUrlRequestHandler;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

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

@Component
public class CustomLogoutSuccessHandler
        extends AbstractAuthenticationTargetUrlRequestHandler
        implements LogoutSuccessHandler {

    private static final String BEARER_AUTHENTICATION = "Bearer";
    private static final String HEADER_AUTHORIZATION = "authorization";

    @Autowired
    private ApprovalStore approvalStore;

    @Autowired
    private DefaultTokenServices defaultTokenServices;

    @Override
    public void onLogoutSuccess(HttpServletRequest request,
                                HttpServletResponse response,
                                Authentication authentication)
            throws IOException, ServletException {

        String token = request.getHeader(HEADER_AUTHORIZATION);
        if (token != null) {
            String[] chunks = token.split(" ");
            if (chunks[0].equalsIgnoreCase(BEARER_AUTHENTICATION)) {
                // TODO ???
            }

        }
        response.setStatus(HttpServletResponse.SC_OK);

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy