You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bd...@apache.org on 2016/10/18 18:56:45 UTC
[11/23] shiro git commit: SHIRO-593 - Moved 'defaultBeans' to
IniFactorySupport
SHIRO-593 - Moved 'defaultBeans' to IniFactorySupport
Project: http://git-wip-us.apache.org/repos/asf/shiro/repo
Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/4af5e182
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/4af5e182
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/4af5e182
Branch: refs/heads/master
Commit: 4af5e182474ea0017c292a342fa70a525f4cb085
Parents: af75fb5
Author: Brian Demers <bd...@apache.org>
Authored: Mon Sep 26 21:30:52 2016 -0400
Committer: Brian Demers <bd...@apache.org>
Committed: Tue Oct 18 12:46:24 2016 -0400
----------------------------------------------------------------------
.../apache/shiro/config/IniFactorySupport.java | 25 ++++++++++++++++++++
.../shiro/config/IniSecurityManagerFactory.java | 6 +++++
.../config/IniFilterChainResolverFactory.java | 9 ++++---
3 files changed, 35 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/shiro/blob/4af5e182/core/src/main/java/org/apache/shiro/config/IniFactorySupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/shiro/config/IniFactorySupport.java b/core/src/main/java/org/apache/shiro/config/IniFactorySupport.java
index aaa4ad1..17ebff0 100644
--- a/core/src/main/java/org/apache/shiro/config/IniFactorySupport.java
+++ b/core/src/main/java/org/apache/shiro/config/IniFactorySupport.java
@@ -25,6 +25,9 @@ import org.apache.shiro.util.Factory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Base support class for {@link Factory} implementations that generate their instance(s) based on
* {@link Ini} configuration.
@@ -41,6 +44,8 @@ public abstract class IniFactorySupport<T> extends AbstractFactory<T> {
private Ini ini;
+ private Map<String, ?> defaultBeans;
+
protected IniFactorySupport() {
}
@@ -57,6 +62,26 @@ public abstract class IniFactorySupport<T> extends AbstractFactory<T> {
}
/**
+ * Returns a mapping of String to bean representing the default set of object used by the factory.
+ * These beans can be used by this factory in conjunction with objects parsed from the INI configuration.
+ * @return A Map of default objects, or <code>null</code>.
+ * @since 1.4
+ */
+ protected Map<String, ?> getDefaults() {
+ return defaultBeans;
+ }
+
+ /**
+ * Sets the default objects used by this factory. These defaults may be used in conjunction with the INI
+ * configuration.
+ * @param defaultBeans String to object mapping used for default configuration in this factory.
+ * @since 1.4
+ */
+ public void setDefaults(Map<String, ?> defaultBeans) {
+ this.defaultBeans = defaultBeans;
+ }
+
+ /**
* Returns a new Ini instance created from the default {@code classpath:shiro.ini} file, or {@code null} if
* the file does not exist.
*
http://git-wip-us.apache.org/repos/asf/shiro/blob/4af5e182/core/src/main/java/org/apache/shiro/config/IniSecurityManagerFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/shiro/config/IniSecurityManagerFactory.java b/core/src/main/java/org/apache/shiro/config/IniSecurityManagerFactory.java
index 2333220..628f0b5 100644
--- a/core/src/main/java/org/apache/shiro/config/IniSecurityManagerFactory.java
+++ b/core/src/main/java/org/apache/shiro/config/IniSecurityManagerFactory.java
@@ -161,6 +161,12 @@ public class IniSecurityManagerFactory extends IniFactorySupport<SecurityManager
}
}
+ // The values from 'getDefaults()' will override the above.
+ Map<String, ?> defaultBeans = getDefaults();
+ if (!CollectionUtils.isEmpty(defaultBeans)) {
+ defaults.putAll(defaultBeans);
+ }
+
return defaults;
}
http://git-wip-us.apache.org/repos/asf/shiro/blob/4af5e182/web/src/main/java/org/apache/shiro/web/config/IniFilterChainResolverFactory.java
----------------------------------------------------------------------
diff --git a/web/src/main/java/org/apache/shiro/web/config/IniFilterChainResolverFactory.java b/web/src/main/java/org/apache/shiro/web/config/IniFilterChainResolverFactory.java
index ad7e7f0..fb9f822 100644
--- a/web/src/main/java/org/apache/shiro/web/config/IniFilterChainResolverFactory.java
+++ b/web/src/main/java/org/apache/shiro/web/config/IniFilterChainResolverFactory.java
@@ -49,8 +49,6 @@ public class IniFilterChainResolverFactory extends IniFactorySupport<FilterChain
private FilterConfig filterConfig;
- private Map<String, ?> defaultBeans;
-
public IniFilterChainResolverFactory() {
super();
}
@@ -61,7 +59,7 @@ public class IniFilterChainResolverFactory extends IniFactorySupport<FilterChain
public IniFilterChainResolverFactory(Ini ini, Map<String, ?> defaultBeans) {
this(ini);
- this.defaultBeans = defaultBeans;
+ this.setDefaults(defaultBeans);
}
public FilterConfig getFilterConfig() {
@@ -113,8 +111,9 @@ public class IniFilterChainResolverFactory extends IniFactorySupport<FilterChain
}
//User-provided objects must come _after_ the default filters - to allow the user-provided
//ones to override the default filters if necessary.
- if (!CollectionUtils.isEmpty(this.defaultBeans)) {
- defaults.putAll(this.defaultBeans);
+ Map<String, ?> defaultBeans = getDefaults();
+ if (!CollectionUtils.isEmpty(defaultBeans)) {
+ defaults.putAll(defaultBeans);
}
Map<String, Filter> filters = getFilters(section, defaults);