refactoring of pattern matching for targets and channels

This commit is contained in:
Jonas Partner
2008-06-26 12:38:23 +00:00
parent 6812c7eb2e
commit 8623920db5
11 changed files with 199 additions and 6 deletions

View File

@@ -0,0 +1,61 @@
package org.springframework.integration.security.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
/**
*
* @author Jonas Partner
*
*/
public class JdkRegExpOrderedIncludeExcludeListTests {
@Test
public void testSimpleInclusionIncludeByDefaultFalse() {
List<IncludeExcludePattern> patterns = createIncludeExcludeList(new boolean[] { true }, new String[] { ".*" });
JdkRegExpOrderedIncludeExcludeList matcher = new JdkRegExpOrderedIncludeExcludeList(false, patterns);
assertTrue("Did not match expected name", matcher.isIncluded("anyoldthing"));
}
@Test
public void testNoPatternsIncludeByDefaultTrue() {
List<IncludeExcludePattern> patterns = createIncludeExcludeList(new boolean[] {}, new String[] {});
JdkRegExpOrderedIncludeExcludeList matcher = new JdkRegExpOrderedIncludeExcludeList(true, patterns);
assertTrue("Did not match expected name", matcher.isIncluded("anyoldthing"));
}
@Test
public void testNoPatternsIncludeByDefaultFalse() {
List<IncludeExcludePattern> patterns = createIncludeExcludeList(new boolean[] {}, new String[] {});
JdkRegExpOrderedIncludeExcludeList matcher = new JdkRegExpOrderedIncludeExcludeList(false, patterns);
assertFalse("Unexpected match when match by default false and no patterns", matcher.isIncluded("anyoldthing"));
}
@Test
public void testExcludeThenIncludeWithIncludeByDefaultFalse() {
List<IncludeExcludePattern> patterns = createIncludeExcludeList(new boolean[] {false, true}, new String[] {"admin.*",".*"});
JdkRegExpOrderedIncludeExcludeList matcher = new JdkRegExpOrderedIncludeExcludeList(false, patterns);
assertFalse("Unexpected match when match by default false and should have been excluded", matcher.isIncluded("adminChannel"));
}
List<IncludeExcludePattern> createIncludeExcludeList(boolean[] includeExclude, String[] patterns) {
assertEquals("flag and patterns arrays must be same length", includeExclude.length, patterns.length);
List<IncludeExcludePattern> includeExcludePatterns = new ArrayList<IncludeExcludePattern>(patterns.length);
for (int i = 0; i < includeExclude.length; i++) {
includeExcludePatterns.add(new IncludeExcludePattern(includeExclude[i], patterns[i]));
}
return includeExcludePatterns;
}
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security;
package org.springframework.integration.security.target;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
@@ -21,6 +21,7 @@ import org.springframework.integration.message.BlockingTarget;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.StringMessage;
import org.springframework.integration.message.Target;
import org.springframework.integration.security.target.TargetSecuringAdvisor;
import org.springframework.security.AccessDecisionManager;
import org.springframework.security.AccessDeniedException;
import org.springframework.security.Authentication;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security;
package org.springframework.integration.security.target;
import java.util.ArrayList;
import java.util.List;
@@ -25,8 +25,8 @@ import org.springframework.integration.message.Message;
import org.springframework.integration.message.StringMessage;
import org.springframework.integration.message.Target;
import org.springframework.integration.security.SecurityContextUtils;
import org.springframework.integration.security.TargetSecuringInterceptor;
import org.springframework.integration.security.config.SecurityTestUtil;
import org.springframework.integration.security.target.TargetSecuringInterceptor;
import org.springframework.security.AccessDecisionManager;
import org.springframework.security.AccessDeniedException;
import org.springframework.security.ConfigAttributeDefinition;