shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdem...@apache.org
Subject [1/2] shiro git commit: unit test against AuthorizationAttributeSourceAdvisor.matches
Date Fri, 06 Jan 2017 19:43:22 GMT
Repository: shiro
Updated Branches:
  refs/heads/master 85edb748e -> 0aec37340


unit test against AuthorizationAttributeSourceAdvisor.matches

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/shiro/repo
Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/98810db1
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/98810db1
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/98810db1

Branch: refs/heads/master
Commit: 98810db1514d515cdf9409bb951140dd38bc4cf2
Parents: 85edb74
Author: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Authored: Thu Dec 29 22:44:08 2016 +0100
Committer: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Committed: Thu Dec 29 22:44:08 2016 +0100

----------------------------------------------------------------------
 ...AuthorizationAttributeSourceAdvisorTest.java | 84 ++++++++++++++++++++
 1 file changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/shiro/blob/98810db1/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/AuthorizationAttributeSourceAdvisorTest.java
----------------------------------------------------------------------
diff --git a/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/AuthorizationAttributeSourceAdvisorTest.java
b/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/AuthorizationAttributeSourceAdvisorTest.java
new file mode 100644
index 0000000..7c33d2f
--- /dev/null
+++ b/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/AuthorizationAttributeSourceAdvisorTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.security.interceptor;
+
+import org.apache.shiro.authz.annotation.RequiresAuthentication;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class AuthorizationAttributeSourceAdvisorTest {
+
+    static class Secured {
+        @RequiresAuthentication
+        public void secureMethod() {
+        }
+
+        public void unsecuredMethod() {
+        }
+    }
+
+    interface ServiceInterface {
+        @RequiresAuthentication
+        String secureMethod();
+
+        String unsecuredMethod();
+    }
+
+    static class ServiceImpl implements ServiceInterface {
+
+        @Override
+        public String secureMethod() {
+            return "";
+        }
+
+        @Override
+        public String unsecuredMethod() {
+            return "";
+        }
+    }
+
+    @Test
+    public void matches() throws NoSuchMethodException {
+        assertTrue(
+                "the method is annotated, should match",
+                new AuthorizationAttributeSourceAdvisor().matches(
+                        Secured.class.getDeclaredMethod("secureMethod"), Secured.class
+                ));
+        assertFalse(
+                "the method is not annotated, should not match",
+                new AuthorizationAttributeSourceAdvisor().matches(
+                        Secured.class.getDeclaredMethod("unsecuredMethod"), Secured.class
+                ));
+
+        assertTrue(
+                "the method declaration is annotated in the interface, should match",
+                new AuthorizationAttributeSourceAdvisor().matches(
+                        ServiceInterface.class.getDeclaredMethod("secureMethod"), ServiceImpl.class
+                ));
+        assertFalse(
+                "not annotated method, should not match",
+                new AuthorizationAttributeSourceAdvisor().matches(
+                        ServiceInterface.class.getDeclaredMethod("unsecuredMethod"), ServiceImpl.class
+                ));
+
+    }
+
+}


Mime
View raw message