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 2022/10/07 11:23:25 UTC

[shiro] branch aop-1-10-x created (now f33bdd16)

This is an automated email from the ASF dual-hosted git repository.

bdemers pushed a change to branch aop-1-10-x
in repository https://gitbox.apache.org/repos/asf/shiro.git


      at f33bdd16 Migrate aop tests to groovy

This branch includes the following new commits:

     new a99d0b23 Avoid another proxy creator when @EnableAspectJAutoProxy enabled
     new dd1de0da Add unit tests for SHIRO-890
     new 937d1436 Add licenses
     new b5a7c0c0 Fix typos in unit tests
     new ce0a1b37 cleaning up whitespace
     new f33bdd16 Migrate aop tests to groovy

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[shiro] 04/06: Fix typos in unit tests

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdemers pushed a commit to branch aop-1-10-x
in repository https://gitbox.apache.org/repos/asf/shiro.git

commit b5a7c0c0f496626c5ccfa071f784e24f96f1983d
Author: George CAO <ma...@gmail.com>
AuthorDate: Fri Oct 7 17:11:29 2022 +0800

    Fix typos in unit tests
---
 .../spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java    | 2 +-
 .../autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java
index 91146bb7..b2e405b0 100644
--- a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java
+++ b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java
@@ -50,7 +50,7 @@ public class AspectjAndDefaultProxyCreatorTest {
             assertNotNull(creator);
             if (!(creator instanceof DefaultAdvisorAutoProxyCreator
                     || creator instanceof AnnotationAwareAspectJAutoProxyCreator)) {
-                fail("It supposed to be one of these two types olny.");
+                fail("It supposed to be one of these two types only.");
             }
         }
         String[] beanNames = applicationContext.getBeanNamesForType(AbstractAdvisorAutoProxyCreator.class);
diff --git a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java
index 2a33f2a1..fad98549 100644
--- a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java
+++ b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java
@@ -44,7 +44,7 @@ public class ShiroAnnotationProcessorAutoConfigurationTest {
         //  There is only one proxy creator, and it's AnnotationAwareAspectJAutoProxyCreator as expected.
         Object creator = applicationContext.getBean(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
         if (!(creator instanceof AnnotationAwareAspectJAutoProxyCreator)) {
-            fail("@EnableAspectJAutoProxy will create in instance of AnnotationAwareAspectJAutoProxyCreator");
+            fail("@EnableAspectJAutoProxy will create an instance of AnnotationAwareAspectJAutoProxyCreator");
         }
         String[] names = applicationContext.getBeanNamesForType(AbstractAdvisorAutoProxyCreator.class);
         assertEquals(1, names.length);


[shiro] 03/06: Add licenses

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdemers pushed a commit to branch aop-1-10-x
in repository https://gitbox.apache.org/repos/asf/shiro.git

commit 937d1436c77a3e5120027781bee98c773ecf04cc
Author: George CAO <ma...@gmail.com>
AuthorDate: Fri Oct 7 17:07:48 2022 +0800

    Add licenses
---
 .../AspectjAndDefaultProxyCreatorTest.java             | 18 ++++++++++++++++++
 .../ShiroAnnotationProcessorAutoConfigurationTest.java | 18 ++++++++++++++++++
 .../AspectjAndDefaultProxyCreatorApplication.java      | 18 ++++++++++++++++++
 .../boot/autoconfigure/AspectjEnabledApplication.java  | 18 ++++++++++++++++++
 4 files changed, 72 insertions(+)

diff --git a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java
index 95896954..91146bb7 100644
--- a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java
+++ b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.autoconfigure;
 
 import org.junit.Test;
diff --git a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java
index e3552623..2a33f2a1 100644
--- a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java
+++ b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.autoconfigure;
 
 import org.junit.Test;
diff --git a/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorApplication.java b/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorApplication.java
index 8e541beb..3c918e53 100644
--- a/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorApplication.java
+++ b/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorApplication.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.autoconfigure;
 
 import org.apache.shiro.realm.Realm;
diff --git a/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjEnabledApplication.java b/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjEnabledApplication.java
index dc7073b8..f7cdc34d 100644
--- a/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjEnabledApplication.java
+++ b/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjEnabledApplication.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.autoconfigure;
 
 import org.apache.shiro.realm.Realm;


[shiro] 05/06: cleaning up whitespace

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdemers pushed a commit to branch aop-1-10-x
in repository https://gitbox.apache.org/repos/asf/shiro.git

commit ce0a1b37ef4327ffb8004d7b01c7d3d160a345ed
Author: Brian Demers <br...@gmail.com>
AuthorDate: Fri Oct 7 06:32:11 2022 -0400

    cleaning up whitespace
---
 support/spring-boot/spring-boot-starter/pom.xml | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/support/spring-boot/spring-boot-starter/pom.xml b/support/spring-boot/spring-boot-starter/pom.xml
index 1e168399..e39d5725 100644
--- a/support/spring-boot/spring-boot-starter/pom.xml
+++ b/support/spring-boot/spring-boot-starter/pom.xml
@@ -18,8 +18,7 @@
   ~ under the License.
   -->
 <!--suppress osmorcNonOsgiMavenDependency -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
 
     <modelVersion>4.0.0</modelVersion>
 
@@ -33,10 +32,12 @@
     <name>Apache Shiro :: Support :: Spring Boot</name>
 
     <dependencies>
+
         <dependency>
             <groupId>org.apache.shiro</groupId>
             <artifactId>shiro-spring</artifactId>
         </dependency>
+
         <!-- Spring -->
         <dependency>
             <groupId>org.springframework.boot</groupId>
@@ -57,6 +58,7 @@
             <artifactId>spring-boot-configuration-processor</artifactId>
             <optional>true</optional>
         </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-test</artifactId>
@@ -67,11 +69,13 @@
             <artifactId>spring-test</artifactId>
             <scope>test</scope>
         </dependency>
+
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
             <scope>test</scope>
         </dependency>
+
         <dependency>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>


[shiro] 02/06: Add unit tests for SHIRO-890

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdemers pushed a commit to branch aop-1-10-x
in repository https://gitbox.apache.org/repos/asf/shiro.git

commit dd1de0da829d87459da68006ca72f66836bf1ef8
Author: George CAO <ma...@gmail.com>
AuthorDate: Fri Oct 7 16:57:51 2022 +0800

    Add unit tests for SHIRO-890
---
 support/spring-boot/spring-boot-starter/pom.xml    | 14 +++----
 .../AspectjAndDefaultProxyCreatorTest.java         | 44 ++++++++++++++++++++++
 ...roAnnotationProcessorAutoConfigurationTest.java | 34 +++++++++++++++++
 .../AspectjAndDefaultProxyCreatorApplication.java  | 42 +++++++++++++++++++++
 .../autoconfigure/AspectjEnabledApplication.java   | 31 +++++++++++++++
 5 files changed, 158 insertions(+), 7 deletions(-)

diff --git a/support/spring-boot/spring-boot-starter/pom.xml b/support/spring-boot/spring-boot-starter/pom.xml
index 20775410..1e168399 100644
--- a/support/spring-boot/spring-boot-starter/pom.xml
+++ b/support/spring-boot/spring-boot-starter/pom.xml
@@ -18,7 +18,8 @@
   ~ under the License.
   -->
 <!--suppress osmorcNonOsgiMavenDependency -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
 
     <modelVersion>4.0.0</modelVersion>
 
@@ -32,12 +33,10 @@
     <name>Apache Shiro :: Support :: Spring Boot</name>
 
     <dependencies>
-
         <dependency>
             <groupId>org.apache.shiro</groupId>
             <artifactId>shiro-spring</artifactId>
         </dependency>
-
         <!-- Spring -->
         <dependency>
             <groupId>org.springframework.boot</groupId>
@@ -58,7 +57,6 @@
             <artifactId>spring-boot-configuration-processor</artifactId>
             <optional>true</optional>
         </dependency>
-
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-test</artifactId>
@@ -69,20 +67,22 @@
             <artifactId>spring-test</artifactId>
             <scope>test</scope>
         </dependency>
-
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
             <scope>test</scope>
         </dependency>
-
         <dependency>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>
             <version>${commons.logging.version}</version>
             <scope>test</scope>
         </dependency>
-
+        <dependency>
+            <groupId>org.aspectj</groupId>
+            <artifactId>aspectjweaver</artifactId>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java
new file mode 100644
index 00000000..95896954
--- /dev/null
+++ b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java
@@ -0,0 +1,44 @@
+package org.apache.shiro.spring.boot.autoconfigure;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator;
+import org.springframework.aop.config.AopConfigUtils;
+import org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator;
+import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.Arrays;
+
+import static org.junit.Assert.*;
+
+@SpringBootTest(classes = AspectjAndDefaultProxyCreatorApplication.class)
+@RunWith(SpringJUnit4ClassRunner.class)
+public class AspectjAndDefaultProxyCreatorTest {
+
+    @Autowired
+    private ApplicationContext applicationContext;
+
+    @Test
+    public void defaultAdvisorAutoProxyCreator() throws BeansException {
+        // There are two proxy creators before SHIRO-890 which causes problem when @EnableAspectJAutoProxy is enabled.
+        String[] names = new String[]{"defaultAdvisorAutoProxyCreator", AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME};
+        for (String name : names) {
+            Object creator = applicationContext.getBean(name);
+            assertNotNull(creator);
+            if (!(creator instanceof DefaultAdvisorAutoProxyCreator
+                    || creator instanceof AnnotationAwareAspectJAutoProxyCreator)) {
+                fail("It supposed to be one of these two types olny.");
+            }
+        }
+        String[] beanNames = applicationContext.getBeanNamesForType(AbstractAdvisorAutoProxyCreator.class);
+        assertEquals(2, beanNames.length);
+        Arrays.sort(names);
+        Arrays.sort(beanNames);
+        assertArrayEquals(names, beanNames);
+    }
+}
\ No newline at end of file
diff --git a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java
new file mode 100644
index 00000000..e3552623
--- /dev/null
+++ b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java
@@ -0,0 +1,34 @@
+package org.apache.shiro.spring.boot.autoconfigure;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator;
+import org.springframework.aop.config.AopConfigUtils;
+import org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
+
+@SpringBootTest(classes = AspectjEnabledApplication.class)
+@RunWith(SpringJUnit4ClassRunner.class)
+public class ShiroAnnotationProcessorAutoConfigurationTest {
+
+    @Autowired
+    private ApplicationContext applicationContext;
+
+    @Test
+    public void defaultAdvisorAutoProxyCreator() throws BeansException {
+        //  There is only one proxy creator, and it's AnnotationAwareAspectJAutoProxyCreator as expected.
+        Object creator = applicationContext.getBean(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
+        if (!(creator instanceof AnnotationAwareAspectJAutoProxyCreator)) {
+            fail("@EnableAspectJAutoProxy will create in instance of AnnotationAwareAspectJAutoProxyCreator");
+        }
+        String[] names = applicationContext.getBeanNamesForType(AbstractAdvisorAutoProxyCreator.class);
+        assertEquals(1, names.length);
+    }
+}
\ No newline at end of file
diff --git a/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorApplication.java b/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorApplication.java
new file mode 100644
index 00000000..8e541beb
--- /dev/null
+++ b/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorApplication.java
@@ -0,0 +1,42 @@
+package org.apache.shiro.spring.boot.autoconfigure;
+
+import org.apache.shiro.realm.Realm;
+import org.apache.shiro.realm.text.TextConfigurationRealm;
+import org.springframework.aop.config.AopConfigUtils;
+import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.DependsOn;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+
+@EnableAutoConfiguration
+@EnableAspectJAutoProxy
+public class AspectjAndDefaultProxyCreatorApplication {
+
+    public static void main(String... args) {
+        SpringApplication.run(AspectjAndDefaultProxyCreatorApplication.class);
+    }
+
+    @Bean
+    @SuppressWarnings("Duplicates")
+    Realm getTextConfigurationRealm() {
+
+        TextConfigurationRealm realm = new TextConfigurationRealm();
+        realm.setUserDefinitions("joe.coder=password,user\n" +
+                "jill.coder=password,admin");
+
+        realm.setRoleDefinitions("admin=read,write\n" +
+                "user=read");
+        realm.setCachingEnabled(true);
+        return realm;
+    }
+
+    @Bean
+    @DependsOn("lifecycleBeanPostProcessor")
+    @ConditionalOnMissingBean(value = DefaultAdvisorAutoProxyCreator.class, name = AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME)
+    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
+        return new DefaultAdvisorAutoProxyCreator();
+    }
+}
\ No newline at end of file
diff --git a/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjEnabledApplication.java b/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjEnabledApplication.java
new file mode 100644
index 00000000..dc7073b8
--- /dev/null
+++ b/support/spring-boot/spring-boot-starter/src/test/java/org/apache/shiro/spring/boot/autoconfigure/AspectjEnabledApplication.java
@@ -0,0 +1,31 @@
+package org.apache.shiro.spring.boot.autoconfigure;
+
+import org.apache.shiro.realm.Realm;
+import org.apache.shiro.realm.text.TextConfigurationRealm;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+
+@EnableAutoConfiguration
+@EnableAspectJAutoProxy
+public class AspectjEnabledApplication {
+
+    public static void main(String... args) {
+        SpringApplication.run(AspectjEnabledApplication.class);
+    }
+
+    @Bean
+    @SuppressWarnings("Duplicates")
+    Realm getTextConfigurationRealm() {
+
+        TextConfigurationRealm realm = new TextConfigurationRealm();
+        realm.setUserDefinitions("joe.coder=password,user\n" +
+                "jill.coder=password,admin");
+
+        realm.setRoleDefinitions("admin=read,write\n" +
+                "user=read");
+        realm.setCachingEnabled(true);
+        return realm;
+    }
+}
\ No newline at end of file


[shiro] 06/06: Migrate aop tests to groovy

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdemers pushed a commit to branch aop-1-10-x
in repository https://gitbox.apache.org/repos/asf/shiro.git

commit f33bdd1673d95b496aa01934f06a8b704d830bbf
Author: Brian Demers <bd...@apache.org>
AuthorDate: Fri Oct 7 06:04:18 2022 -0500

    Migrate aop tests to groovy
---
 ...va => AspectjAndDefaultProxyCreatorTest.groovy} | 53 ++++++++++------------
 ...nnotationProcessorAutoConfigurationTest.groovy} | 41 ++++++++---------
 2 files changed, 44 insertions(+), 50 deletions(-)

diff --git a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.groovy
similarity index 53%
rename from support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java
rename to support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.groovy
index b2e405b0..bfedb915 100644
--- a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.java
+++ b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/AspectjAndDefaultProxyCreatorTest.groovy
@@ -18,45 +18,40 @@
  */
 package org.apache.shiro.spring.boot.autoconfigure;
 
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator;
-import org.springframework.aop.config.AopConfigUtils;
-import org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator;
-import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.context.ApplicationContext;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
+import org.springframework.aop.config.AopConfigUtils
+import org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator
+import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator
+import org.springframework.beans.BeansException
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.context.ApplicationContext
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
 
-import java.util.Arrays;
-
-import static org.junit.Assert.*;
+import static org.hamcrest.Matchers.*
+import static org.hamcrest.MatcherAssert.assertThat
 
 @SpringBootTest(classes = AspectjAndDefaultProxyCreatorApplication.class)
 @RunWith(SpringJUnit4ClassRunner.class)
-public class AspectjAndDefaultProxyCreatorTest {
+class AspectjAndDefaultProxyCreatorTest {
 
     @Autowired
-    private ApplicationContext applicationContext;
+    private ApplicationContext applicationContext
 
     @Test
-    public void defaultAdvisorAutoProxyCreator() throws BeansException {
+    void defaultAdvisorAutoProxyCreator() throws BeansException {
         // There are two proxy creators before SHIRO-890 which causes problem when @EnableAspectJAutoProxy is enabled.
-        String[] names = new String[]{"defaultAdvisorAutoProxyCreator", AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME};
+        String[] names = ["defaultAdvisorAutoProxyCreator", AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME]
         for (String name : names) {
-            Object creator = applicationContext.getBean(name);
-            assertNotNull(creator);
-            if (!(creator instanceof DefaultAdvisorAutoProxyCreator
-                    || creator instanceof AnnotationAwareAspectJAutoProxyCreator)) {
-                fail("It supposed to be one of these two types only.");
-            }
+            Object creator = applicationContext.getBean(name)
+            assertThat(creator, anyOf(
+                    instanceOf(DefaultAdvisorAutoProxyCreator.class),
+                    instanceOf(AnnotationAwareAspectJAutoProxyCreator.class)
+            ))
         }
-        String[] beanNames = applicationContext.getBeanNamesForType(AbstractAdvisorAutoProxyCreator.class);
-        assertEquals(2, beanNames.length);
-        Arrays.sort(names);
-        Arrays.sort(beanNames);
-        assertArrayEquals(names, beanNames);
+        String[] beanNames = applicationContext.getBeanNamesForType(AbstractAdvisorAutoProxyCreator.class)
+        assertThat(names, arrayContainingInAnyOrder(beanNames))
     }
 }
\ No newline at end of file
diff --git a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.groovy
similarity index 58%
rename from support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java
rename to support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.groovy
index fad98549..68602321 100644
--- a/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.java
+++ b/support/spring-boot/spring-boot-starter/src/test/groovy/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfigurationTest.groovy
@@ -18,35 +18,34 @@
  */
 package org.apache.shiro.spring.boot.autoconfigure;
 
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator;
-import org.springframework.aop.config.AopConfigUtils;
-import org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.context.ApplicationContext;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
+import org.springframework.aop.config.AopConfigUtils
+import org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator
+import org.springframework.beans.BeansException
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.context.ApplicationContext
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.hamcrest.MatcherAssert.assertThat
+import static org.hamcrest.Matchers.*
 
 @SpringBootTest(classes = AspectjEnabledApplication.class)
 @RunWith(SpringJUnit4ClassRunner.class)
-public class ShiroAnnotationProcessorAutoConfigurationTest {
+class ShiroAnnotationProcessorAutoConfigurationTest {
 
     @Autowired
-    private ApplicationContext applicationContext;
+    private ApplicationContext applicationContext
 
     @Test
-    public void defaultAdvisorAutoProxyCreator() throws BeansException {
+    void defaultAdvisorAutoProxyCreator() throws BeansException {
         //  There is only one proxy creator, and it's AnnotationAwareAspectJAutoProxyCreator as expected.
-        Object creator = applicationContext.getBean(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
-        if (!(creator instanceof AnnotationAwareAspectJAutoProxyCreator)) {
-            fail("@EnableAspectJAutoProxy will create an instance of AnnotationAwareAspectJAutoProxyCreator");
-        }
-        String[] names = applicationContext.getBeanNamesForType(AbstractAdvisorAutoProxyCreator.class);
-        assertEquals(1, names.length);
+        Object creator = applicationContext.getBean(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME)
+        assertThat("@EnableAspectJAutoProxy will create an instance of AnnotationAwareAspectJAutoProxyCreator",
+                creator, instanceOf(AnnotationAwareAspectJAutoProxyCreator.class))
+        String[] names = applicationContext.getBeanNamesForType(AbstractAdvisorAutoProxyCreator.class)
+        assertThat(names, arrayWithSize(1))
     }
 }
\ No newline at end of file


[shiro] 01/06: Avoid another proxy creator when @EnableAspectJAutoProxy enabled

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdemers pushed a commit to branch aop-1-10-x
in repository https://gitbox.apache.org/repos/asf/shiro.git

commit a99d0b235870fdefab38b27424bd6522a127fd3a
Author: George CAO <ma...@gmail.com>
AuthorDate: Fri Oct 7 11:43:24 2022 +0800

    Avoid another proxy creator when @EnableAspectJAutoProxy enabled
---
 .../autoconfigure/ShiroAnnotationProcessorAutoConfiguration.java    | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/support/spring-boot/spring-boot-starter/src/main/java/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfiguration.java b/support/spring-boot/spring-boot-starter/src/main/java/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfiguration.java
index 6c00d293..b17fa1b1 100644
--- a/support/spring-boot/spring-boot-starter/src/main/java/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfiguration.java
+++ b/support/spring-boot/spring-boot-starter/src/main/java/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfiguration.java
@@ -21,7 +21,10 @@ package org.apache.shiro.spring.boot.autoconfigure;
 import org.apache.shiro.mgt.SecurityManager;
 import org.apache.shiro.spring.config.AbstractShiroAnnotationProcessorConfiguration;
 import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
+import org.springframework.aop.config.AopConfigUtils;
 import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Bean;
@@ -32,13 +35,14 @@ import org.springframework.context.annotation.DependsOn;
  * @since 1.4.0
  */
 @SuppressWarnings("SpringFacetCodeInspection")
+@AutoConfigureAfter(AopAutoConfiguration.class)
 @Configuration
 @ConditionalOnProperty(name = "shiro.annotations.enabled", matchIfMissing = true)
 public class ShiroAnnotationProcessorAutoConfiguration extends AbstractShiroAnnotationProcessorConfiguration {
 
     @Bean
     @DependsOn("lifecycleBeanPostProcessor")
-    @ConditionalOnMissingBean
+    @ConditionalOnMissingBean(name = AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME)
     @Override
     public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
         return super.defaultAdvisorAutoProxyCreator();