package com.qianwen.core.secure.registry;
|
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.List;
|
import com.qianwen.core.secure.props.AuthSecure;
|
import com.qianwen.core.secure.props.BasicSecure;
|
import com.qianwen.core.secure.props.SignSecure;
|
import com.qianwen.core.secure.provider.HttpMethod;
|
|
public class SecureRegistry {
|
private boolean enabled = false;
|
private boolean authEnabled = true;
|
private boolean basicEnabled = true;
|
private boolean signEnabled = true;
|
private boolean clientEnabled = true;
|
private final List<String> defaultExcludePatterns = new ArrayList<>();
|
private final List<String> excludePatterns = new ArrayList<>();
|
private final List<AuthSecure> authSecures = new ArrayList<>();
|
private final List<BasicSecure> basicSecures = new ArrayList<>();
|
private final List<SignSecure> signSecures = new ArrayList<>();
|
|
public void setEnabled(final boolean enabled) {
|
this.enabled = enabled;
|
}
|
|
public void setAuthEnabled(final boolean authEnabled) {
|
this.authEnabled = authEnabled;
|
}
|
|
public void setBasicEnabled(final boolean basicEnabled) {
|
this.basicEnabled = basicEnabled;
|
}
|
|
public void setSignEnabled(final boolean signEnabled) {
|
this.signEnabled = signEnabled;
|
}
|
|
public void setClientEnabled(final boolean clientEnabled) {
|
this.clientEnabled = clientEnabled;
|
}
|
|
public boolean equals(final Object o) {
|
if (o == this) {
|
return true;
|
}
|
if (o instanceof SecureRegistry) {
|
SecureRegistry other = (SecureRegistry) o;
|
if (other.canEqual(this) && isEnabled() == other.isEnabled() && isAuthEnabled() == other.isAuthEnabled() && isBasicEnabled() == other.isBasicEnabled() && isSignEnabled() == other.isSignEnabled() && isClientEnabled() == other.isClientEnabled()) {
|
Object this$defaultExcludePatterns = getDefaultExcludePatterns();
|
Object other$defaultExcludePatterns = other.getDefaultExcludePatterns();
|
if (this$defaultExcludePatterns == null) {
|
if (other$defaultExcludePatterns != null) {
|
return false;
|
}
|
} else if (!this$defaultExcludePatterns.equals(other$defaultExcludePatterns)) {
|
return false;
|
}
|
Object this$excludePatterns = getExcludePatterns();
|
Object other$excludePatterns = other.getExcludePatterns();
|
if (this$excludePatterns == null) {
|
if (other$excludePatterns != null) {
|
return false;
|
}
|
} else if (!this$excludePatterns.equals(other$excludePatterns)) {
|
return false;
|
}
|
Object this$authSecures = getAuthSecures();
|
Object other$authSecures = other.getAuthSecures();
|
if (this$authSecures == null) {
|
if (other$authSecures != null) {
|
return false;
|
}
|
} else if (!this$authSecures.equals(other$authSecures)) {
|
return false;
|
}
|
Object this$basicSecures = getBasicSecures();
|
Object other$basicSecures = other.getBasicSecures();
|
if (this$basicSecures == null) {
|
if (other$basicSecures != null) {
|
return false;
|
}
|
} else if (!this$basicSecures.equals(other$basicSecures)) {
|
return false;
|
}
|
Object this$signSecures = getSignSecures();
|
Object other$signSecures = other.getSignSecures();
|
return this$signSecures == null ? other$signSecures == null : this$signSecures.equals(other$signSecures);
|
}
|
return false;
|
}
|
return false;
|
}
|
|
protected boolean canEqual(final Object other) {
|
return other instanceof SecureRegistry;
|
}
|
|
public int hashCode() {
|
int result = (1 * 59) + (isEnabled() ? 79 : 97);
|
int result2 = (((((((result * 59) + (isAuthEnabled() ? 79 : 97)) * 59) + (isBasicEnabled() ? 79 : 97)) * 59) + (isSignEnabled() ? 79 : 97)) * 59) + (isClientEnabled() ? 79 : 97);
|
Object $defaultExcludePatterns = getDefaultExcludePatterns();
|
int result3 = (result2 * 59) + ($defaultExcludePatterns == null ? 43 : $defaultExcludePatterns.hashCode());
|
Object $excludePatterns = getExcludePatterns();
|
int result4 = (result3 * 59) + ($excludePatterns == null ? 43 : $excludePatterns.hashCode());
|
Object $authSecures = getAuthSecures();
|
int result5 = (result4 * 59) + ($authSecures == null ? 43 : $authSecures.hashCode());
|
Object $basicSecures = getBasicSecures();
|
int result6 = (result5 * 59) + ($basicSecures == null ? 43 : $basicSecures.hashCode());
|
Object $signSecures = getSignSecures();
|
return (result6 * 59) + ($signSecures == null ? 43 : $signSecures.hashCode());
|
}
|
|
public String toString() {
|
return "SecureRegistry(enabled=" + isEnabled() + ", authEnabled=" + isAuthEnabled() + ", basicEnabled=" + isBasicEnabled() + ", signEnabled=" + isSignEnabled() + ", clientEnabled=" + isClientEnabled() + ", defaultExcludePatterns=" + getDefaultExcludePatterns() + ", excludePatterns=" + getExcludePatterns() + ", authSecures=" + getAuthSecures() + ", basicSecures=" + getBasicSecures() + ", signSecures=" + getSignSecures() + ")";
|
}
|
|
public boolean isEnabled() {
|
return this.enabled;
|
}
|
|
public boolean isAuthEnabled() {
|
return this.authEnabled;
|
}
|
|
public boolean isBasicEnabled() {
|
return this.basicEnabled;
|
}
|
|
public boolean isSignEnabled() {
|
return this.signEnabled;
|
}
|
|
public boolean isClientEnabled() {
|
return this.clientEnabled;
|
}
|
|
public List<String> getDefaultExcludePatterns() {
|
return this.defaultExcludePatterns;
|
}
|
|
public List<String> getExcludePatterns() {
|
return this.excludePatterns;
|
}
|
|
public SecureRegistry() {
|
this.defaultExcludePatterns.add("/actuator/health/**");
|
this.defaultExcludePatterns.add("/v2/api-docs/**");
|
this.defaultExcludePatterns.add("/auth/**");
|
this.defaultExcludePatterns.add("/token/**");
|
this.defaultExcludePatterns.add("/log/**");
|
this.defaultExcludePatterns.add("/menu/routes");
|
this.defaultExcludePatterns.add("/menu/auth-routes");
|
this.defaultExcludePatterns.add("/menu/top-menu");
|
this.defaultExcludePatterns.add("/process/resource-view");
|
this.defaultExcludePatterns.add("/process/diagram-view");
|
this.defaultExcludePatterns.add("/manager/check-upload");
|
this.defaultExcludePatterns.add("/error/**");
|
this.defaultExcludePatterns.add("/assets/**");
|
}
|
|
public SecureRegistry excludePathPattern(String pattern) {
|
this.excludePatterns.add(pattern);
|
return this;
|
}
|
|
public SecureRegistry excludePathPatterns(String... patterns) {
|
this.excludePatterns.addAll(Arrays.asList(patterns));
|
return this;
|
}
|
|
public SecureRegistry excludePathPatterns(List<String> patterns) {
|
this.excludePatterns.addAll(patterns);
|
return this;
|
}
|
|
public SecureRegistry addAuthPattern(HttpMethod method, String pattern, String expression) {
|
this.authSecures.add(new AuthSecure(method, pattern, expression));
|
return this;
|
}
|
|
public SecureRegistry addAuthPatterns(List<AuthSecure> authSecures) {
|
this.authSecures.addAll(authSecures);
|
return this;
|
}
|
|
public List<AuthSecure> getAuthSecures() {
|
return this.authSecures;
|
}
|
|
public SecureRegistry addBasicPattern(HttpMethod method, String pattern, String username, String password) {
|
this.basicSecures.add(new BasicSecure(method, pattern, username, password));
|
return this;
|
}
|
|
public SecureRegistry addBasicPatterns(List<BasicSecure> basicSecures) {
|
this.basicSecures.addAll(basicSecures);
|
return this;
|
}
|
|
public List<BasicSecure> getBasicSecures() {
|
return this.basicSecures;
|
}
|
|
public SecureRegistry addSignPattern(HttpMethod method, String pattern, String crypto) {
|
this.signSecures.add(new SignSecure(method, pattern, crypto));
|
return this;
|
}
|
|
public SecureRegistry addSignPatterns(List<SignSecure> signSecures) {
|
this.signSecures.addAll(signSecures);
|
return this;
|
}
|
|
public List<SignSecure> getSignSecures() {
|
return this.signSecures;
|
}
|
}
|