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

com.luues.security.core.invoke.SecurityInvoke Maven / Gradle / Ivy

package com.luues.security.core.invoke;

import com.luues.security.core.authentication.expand.ExpandAuthenticationDetails;
import com.luues.security.core.entity.SysUser;
import com.luues.security.core.interfaces.SecurityAuthenticationProvider;
import com.luues.security.core.interfaces.SecurityInvalidProvider;
import com.luues.security.enumeration.VerifyType;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.ui.Model;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class SecurityInvoke {

    private List securityInvalidProviderList = new ArrayList<>();
    private List securityAuthenticationProviderList = new ArrayList<>();
    public SecurityInvoke(List securityAuthenticationProviderList, List securityInvalidProviderList){
        this.securityAuthenticationProviderList.clear();
        securityAuthenticationProviderList.forEach((v) -> this.securityAuthenticationProviderList.add(v));
        this.securityInvalidProviderList.clear();
        securityInvalidProviderList.forEach((v) -> this.securityInvalidProviderList.add(v));
    }


    public ModelAndView loginPage(HttpServletRequest request, HttpServletResponse response, Model model){
        if(securityAuthenticationProviderList.size() == 0)
            return null;
        return securityAuthenticationProviderList.get(0).loginPage(request, response, model);
    }
    public SysUser authenticate(Authentication authentication, ExpandAuthenticationDetails captchaAuthenticationDetails) throws AuthenticationException {
        if(securityAuthenticationProviderList.size() == 0)
            return null;
        return securityAuthenticationProviderList.get(0).authenticate(authentication, captchaAuthenticationDetails);
    }
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication, VerifyType verifyType, String identity) throws IOException, ServletException {
        if(securityAuthenticationProviderList.size() == 0)
            return;
        securityAuthenticationProviderList.get(0).onAuthenticationSuccess(request, response, authentication, verifyType, identity);
    }
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        if(securityAuthenticationProviderList.size() == 0)
            return;
        securityAuthenticationProviderList.get(0).onAuthenticationFailure(request, response, exception);
    }
    public void onAuthenticationFail(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception, Authentication authentication) throws IOException, ServletException {
        if(securityInvalidProviderList.size() == 0)
            return;
        securityInvalidProviderList.get(0).onAuthenticationFail(request, response, exception, authentication);
    }
    public void onSqueezeOut(HttpServletRequest request, HttpServletResponse response, List userIds) {
        if(securityInvalidProviderList.size() == 0)
            return;
        securityInvalidProviderList.get(0).onSqueezeOut(request, response, userIds);
    }
    public void onBlack(HttpServletRequest request, HttpServletResponse response, String ip){
        if(securityInvalidProviderList.size() == 0)
            return;
        securityInvalidProviderList.get(0).onBlack(request, response, ip);
    }
    public PasswordEncoder passwordEncoder(){
        if(securityAuthenticationProviderList.size() == 0)
            return null;
        return securityAuthenticationProviderList.get(0).passwordEncoder();
    }
    public List findUserRoles(SysUser sysUser){
        if(securityAuthenticationProviderList.size() == 0)
            return null;
        return securityAuthenticationProviderList.get(0).findUserRoles(sysUser);
    }
    public List findUserPermissions(SysUser sysUser){
        if(securityAuthenticationProviderList.size() == 0)
            return null;
        return securityAuthenticationProviderList.get(0).findUserPermissions(sysUser);
    }
    public void onForbidden(HttpServletRequest request, HttpServletResponse response, AccessDeniedException exception) throws IOException, ServletException {
        if(securityInvalidProviderList.size() == 0)
            return;
        securityInvalidProviderList.get(0).onForbidden(request, response, exception);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy