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

com.luues.security.configuration.properties.SecurityMatchersProperties Maven / Gradle / Ivy

package com.luues.security.configuration.properties;

import com.luues.security.enumeration.SecurityConsts;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;

import java.util.*;

@Configuration
@ConfigurationProperties(
        prefix = "spring.luues.security.ignore"
)
@Data
public class SecurityMatchersProperties {

    private List urls = new ArrayList<>();
    private List completelyUrls = new ArrayList<>();

    private Map ignoreMaps = new HashMap<>();
    public SecurityConsts.IgnoreType matches(String requestPath){
        if(requestPath.contains("?")){
            requestPath = requestPath.substring(0, requestPath.indexOf("?"));
        }
        if(null != this.ignoreMaps.get(requestPath)){
            return this.ignoreMaps.get(requestPath);
        }
        if(null != this.completelyUrls && this.completelyUrls.size() > 0){
            for(String url : this.completelyUrls){
                PathMatcher pathMatcher = new AntPathMatcher();
                if(pathMatcher.match(url, requestPath)){
                    this.ignoreMaps.put(requestPath, SecurityConsts.IgnoreType.FULL_RELEASE);
                    break;
                }
            }
        }
        if(null != this.ignoreMaps.get(requestPath)){
            return this.ignoreMaps.get(requestPath);
        }
        if(null != this.urls && this.urls.size() > 0){
            for(String url : this.urls){
                PathMatcher pathMatcher = new AntPathMatcher();
                if(pathMatcher.match(url, requestPath)){
                    this.ignoreMaps.put(requestPath, SecurityConsts.IgnoreType.RELEASE_USER);
                    break;
                }
            }
        }
        if(null == this.ignoreMaps.get(requestPath)){
            this.ignoreMaps.put(requestPath, SecurityConsts.IgnoreType.VERIFICATION_RELEASE);
        }
        return this.ignoreMaps.get(requestPath);
    }

    public void setUrls(List urls) {
        this.urls = urls;
        this.ignoreMaps = new HashMap<>();
    }

    public void setCompletelyUrls(List completelyUrls) {
        this.completelyUrls = completelyUrls;
        this.ignoreMaps = new HashMap<>();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy