org.apache.shiro.spring.boot.ShiroBizAnnotationProperties Maven / Gradle / Ivy
Show all versions of spring-boot-starter-shiro-biz Show documentation
/*
* Copyright (c) 2018, vindell (https://github.com/vindell).
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.apache.shiro.spring.boot;
import org.springframework.aop.framework.Advised;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.lang.Nullable;
/**
* 扩展shiro主机自动注入,解决Spring Aop冲突
*/
@ConfigurationProperties(ShiroBizAnnotationProperties.PREFIX)
public class ShiroBizAnnotationProperties {
public static final String PREFIX = "shiro.annotations";
/**
* Enable Shiro Annotations.
*/
private boolean enabled = false;
private boolean proxyTargetClass = true;
private boolean optimize = false;
private boolean opaque = false;
private boolean exposeProxy = true;
private boolean frozen = false;
private boolean usePrefix = false;
private String advisorBeanNamePrefix;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* Set whether to proxy the target class directly, instead of just proxying
* specific interfaces. Default is "true".
* Set this to "true" to force proxying for the TargetSource's exposed
* target class. If that target class is an interface, a JDK proxy will be
* created for the given interface. If that target class is any other class,
* a CGLIB proxy will be created for the given class.
*
Note: Depending on the configuration of the concrete proxy factory,
* the proxy-target-class behavior will also be applied if no interfaces
* have been specified (and no interface autodetection is activated).
* @param proxyTargetClass : Whether to proxy the target class directly
*/
public void setProxyTargetClass(boolean proxyTargetClass) {
this.proxyTargetClass = proxyTargetClass;
}
/**
* Return whether to proxy the target class directly as well as any interfaces.
* @return Whether to proxy the target class directly
*/
public boolean isProxyTargetClass() {
return this.proxyTargetClass;
}
/**
* Set whether proxies should perform aggressive optimizations.
* The exact meaning of "aggressive optimizations" will differ
* between proxies, but there is usually some tradeoff.
* Default is "false".
*
For example, optimization will usually mean that advice changes won't
* take effect after a proxy has been created. For this reason, optimization
* is disabled by default. An optimize value of "true" may be ignored
* if other settings preclude optimization: for example, if "exposeProxy"
* is set to "true" and that's not compatible with the optimization.
* @param optimize : Whether proxies should perform aggressive optimizations.
*/
public void setOptimize(boolean optimize) {
this.optimize = optimize;
}
/**
* Return whether proxies should perform aggressive optimizations.
* @return whether proxies should perform aggressive optimizations.
*/
public boolean isOptimize() {
return this.optimize;
}
/**
* Set whether proxies created by this configuration should be prevented
* from being cast to {@link Advised} to query proxy status.
*
Default is "false", meaning that any AOP proxy can be cast to
* {@link Advised}.
* @param opaque : Whether proxies created by this configuration should be prevented
* from being cast to {@link Advised} to query proxy status.
*/
public void setOpaque(boolean opaque) {
this.opaque = opaque;
}
/**
* Return whether proxies created by this configuration should be
* prevented from being cast to {@link Advised}.
* @return true or false
*/
public boolean isOpaque() {
return this.opaque;
}
/**
* Set whether the proxy should be exposed by the AOP framework as a
* ThreadLocal for retrieval via the AopContext class. This is useful
* if an advised object needs to call another advised method on itself.
* (If it uses {@code this}, the invocation will not be advised).
*
Default is "true", in order to avoid unnecessary extra interception.
* This means that no guarantees are provided that AopContext access will
* work consistently within any method of the advised object.
* @param exposeProxy : Whether the proxy should be exposed by the AOP framework as a
* ThreadLocal for retrieval via the AopContext class.
*/
public void setExposeProxy(boolean exposeProxy) {
this.exposeProxy = exposeProxy;
}
/**
* @return Return whether the AOP proxy will expose the AOP proxy for
* each invocation.
*/
public boolean isExposeProxy() {
return this.exposeProxy;
}
/**
* Set whether this config should be frozen.
*
When a config is frozen, no advice changes can be made. This is
* useful for optimization, and useful when we don't want callers to
* be able to manipulate configuration after casting to Advised.
* @param frozen : Whether this config should be frozen.
*/
public void setFrozen(boolean frozen) {
this.frozen = frozen;
}
/**
* Return whether the config is frozen, and no advice changes can be made.
* @return Whether this config should be frozen.
*/
public boolean isFrozen() {
return this.frozen;
}
/**
* Set whether to only include advisors with a certain prefix in the bean name.
*
Default is {@code false}, including all beans of type {@code Advisor}.
* @see #setAdvisorBeanNamePrefix
* @param usePrefix : Whether to only include advisors with a certain prefix in the bean name.
*/
public void setUsePrefix(boolean usePrefix) {
this.usePrefix = usePrefix;
}
/**
* Return whether to only include advisors with a certain prefix in the bean name.
* @return Whether to only include advisors with a certain prefix in the bean name.
*/
public boolean isUsePrefix() {
return this.usePrefix;
}
/**
* Set the prefix for bean names that will cause them to be included for
* auto-proxying by this object. This prefix should be set to avoid circular
* references. Default value is the bean name of this object + a dot.
* @param advisorBeanNamePrefix the exclusion prefix
*/
public void setAdvisorBeanNamePrefix(@Nullable String advisorBeanNamePrefix) {
this.advisorBeanNamePrefix = advisorBeanNamePrefix;
}
/**
* Return the prefix for bean names that will cause them to be included
* for auto-proxying by this object.
* @return the exclusion prefix
*/
public String getAdvisorBeanNamePrefix() {
return this.advisorBeanNamePrefix;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("proxyTargetClass=").append(this.proxyTargetClass).append("; ");
sb.append("optimize=").append(this.optimize).append("; ");
sb.append("opaque=").append(this.opaque).append("; ");
sb.append("exposeProxy=").append(this.exposeProxy).append("; ");
sb.append("frozen=").append(this.frozen);
return sb.toString();
}
}