You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bm...@apache.org on 2023/01/27 18:22:40 UTC
[shiro] branch main updated: [SHIRO-902] test quoted wildcard-permission resolving.
This is an automated email from the ASF dual-hosted git repository.
bmarwell pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shiro.git
The following commit(s) were added to refs/heads/main by this push:
new fb593f6c [SHIRO-902] test quoted wildcard-permission resolving.
new 19731730 Merge pull request #664 from bmarwell/SHIRO_902_quoted_permissions
fb593f6c is described below
commit fb593f6ce632c489a2640d55a199c0fa86af60a9
Author: Benjamin Marwell <bm...@apache.org>
AuthorDate: Tue Jan 24 20:36:54 2023 +0100
[SHIRO-902] test quoted wildcard-permission resolving.
---
.../org/apache/shiro/util/PermissionUtils.java | 2 +-
.../org/apache/shiro/util/PermissionUtilsTest.java | 53 ++++++++++++++++++++++
pom.xml | 6 +++
3 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/shiro/util/PermissionUtils.java b/core/src/main/java/org/apache/shiro/util/PermissionUtils.java
index 682d5a96..8d46eb5d 100644
--- a/core/src/main/java/org/apache/shiro/util/PermissionUtils.java
+++ b/core/src/main/java/org/apache/shiro/util/PermissionUtils.java
@@ -49,7 +49,7 @@ public class PermissionUtils {
}
public static Set<Permission> resolvePermissions(Collection<String> permissionStrings, PermissionResolver permissionResolver) {
- Set<Permission> permissions = new LinkedHashSet<Permission>(permissionStrings.size());
+ Set<Permission> permissions = new LinkedHashSet<>(permissionStrings.size());
for (String permissionString : permissionStrings) {
permissions.add(permissionResolver.resolvePermission(permissionString));
}
diff --git a/core/src/test/java/org/apache/shiro/util/PermissionUtilsTest.java b/core/src/test/java/org/apache/shiro/util/PermissionUtilsTest.java
new file mode 100644
index 00000000..b33e0718
--- /dev/null
+++ b/core/src/test/java/org/apache/shiro/util/PermissionUtilsTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.util;
+
+import org.apache.shiro.authz.Permission;
+import org.apache.shiro.authz.permission.PermissionResolver;
+import org.apache.shiro.authz.permission.WildcardPermission;
+import org.apache.shiro.authz.permission.WildcardPermissionResolver;
+import org.junit.jupiter.api.DisplayNameGeneration;
+import org.junit.jupiter.api.DisplayNameGenerator;
+import org.junit.jupiter.api.Test;
+
+import java.util.Set;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
+class PermissionUtilsTest {
+
+ private static final PermissionResolver RESOLVER = new WildcardPermissionResolver(true);
+
+ @Test
+ void SHIRO_902_quoted_permissions() {
+ // given
+ var permission = "user:read,write:*";
+ var quotedPermission = "\"" + permission + "\"";
+
+ // when
+ final Set<Permission> permissions = PermissionUtils.resolveDelimitedPermissions(quotedPermission, RESOLVER);
+
+ // then
+ assertThat(permissions)
+ .containsExactly(new WildcardPermission(permission))
+ ;
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 8295c50e..bc7c9e62 100644
--- a/pom.xml
+++ b/pom.xml
@@ -849,6 +849,12 @@
<version>2.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>3.24.2</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>