From 068fc3620193bdf7a62fa172a8df6ee77f039d17 Mon Sep 17 00:00:00 2001 From: "yadong.zhang" Date: Thu, 6 May 2021 21:14:08 +0800 Subject: [PATCH] :mute: Remove `IdsScopeProvider#initScopes(List)`. --- .../jap/ids/provider/IdsScopeProvider.java | 27 ++++--------------- .../ids/provider/IdsScopeProviderTest.java | 7 ----- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/jap-ids/src/main/java/com/fujieid/jap/ids/provider/IdsScopeProvider.java b/jap-ids/src/main/java/com/fujieid/jap/ids/provider/IdsScopeProvider.java index 7ffae62..c274640 100644 --- a/jap-ids/src/main/java/com/fujieid/jap/ids/provider/IdsScopeProvider.java +++ b/jap-ids/src/main/java/com/fujieid/jap/ids/provider/IdsScopeProvider.java @@ -26,8 +26,6 @@ import java.util.stream.Collectors; * Read, write, openid, email, and phone are supported by default. * If developers need to modify the scope, they can use the following methods: *

- * {@link com.fujieid.jap.ids.provider.IdsScopeProvider#initScopes(List)} - *

* {@link com.fujieid.jap.ids.provider.IdsScopeProvider#addScope(IdsScope)} *

* Note: Whether it is a custom scope or a system built-in scope, openid must be included, which is a required option for enabling OIDC @@ -38,11 +36,9 @@ import java.util.stream.Collectors; */ public class IdsScopeProvider { - private static List scopes = new ArrayList<>(); + private static final List SCOPES = new ArrayList<>(); static { - addScope(new IdsScope().setCode("read").setDescription("Allows to read resources, including users, protected resources, etc.")); - addScope(new IdsScope().setCode("write").setDescription("Allows to modify resources, including adding, deleting, and modifying resources such as users and protected resources.")); addScope(new IdsScope().setCode("openid").setDescription("OpenID connect must include scope.")); addScope(new IdsScope().setCode("profile").setDescription("Allow access to user's basic information.")); addScope(new IdsScope().setCode("email").setDescription("Allow access to user's mailbox.")); @@ -50,19 +46,6 @@ public class IdsScopeProvider { addScope(new IdsScope().setCode("address").setDescription("Allow access to the user's address.")); } - /** - * Initialize scope - *

- * Note: This method will reset the existing scope collection - * - * @param idsScopes scope collection - */ - public static void initScopes(List idsScopes) { - if (ObjectUtil.isNotEmpty(idsScopes)) { - scopes = idsScopes; - } - } - /** * Add a single scope. * Note: This method is to add data to the existing scope collection @@ -70,7 +53,7 @@ public class IdsScopeProvider { * @param idsScope single scope */ public static void addScope(IdsScope idsScope) { - scopes.add(idsScope); + SCOPES.add(idsScope); } /** @@ -79,7 +62,7 @@ public class IdsScopeProvider { * @return Unique scope collection */ public static List getScopes() { - return scopes.stream().collect(Collectors.collectingAndThen( + return SCOPES.stream().collect(Collectors.collectingAndThen( Collectors.toCollection(() -> new TreeSet<>( Comparator.comparing( IdsScope::getCode))), ArrayList::new)); @@ -95,7 +78,7 @@ public class IdsScopeProvider { if (ObjectUtil.isEmpty(codes)) { return new ArrayList<>(0); } - return Optional.ofNullable(scopes.stream().filter((scope) -> codes.contains(scope.getCode())) + return Optional.ofNullable(SCOPES.stream().filter((scope) -> codes.contains(scope.getCode())) .collect(Collectors.collectingAndThen( Collectors.toCollection(() -> new TreeSet<>( Comparator.comparing( @@ -109,7 +92,7 @@ public class IdsScopeProvider { * @return code of all scopes */ public static List getScopeCodes() { - return scopes.stream().map(IdsScope::getCode).distinct().collect(Collectors.toList()); + return SCOPES.stream().map(IdsScope::getCode).distinct().collect(Collectors.toList()); } } diff --git a/jap-ids/src/test/java/com/fujieid/jap/ids/provider/IdsScopeProviderTest.java b/jap-ids/src/test/java/com/fujieid/jap/ids/provider/IdsScopeProviderTest.java index 37818fa..7fd989e 100644 --- a/jap-ids/src/test/java/com/fujieid/jap/ids/provider/IdsScopeProviderTest.java +++ b/jap-ids/src/test/java/com/fujieid/jap/ids/provider/IdsScopeProviderTest.java @@ -9,13 +9,6 @@ import java.util.List; public class IdsScopeProviderTest { - @Test - public void initScopes() { - IdsScopeProvider.initScopes(Collections.singletonList(new IdsScope().setCode("code").setDescription("aasdasd"))); - Assert.assertEquals(1, IdsScopeProvider.getScopes().size()); - Assert.assertEquals("code", IdsScopeProvider.getScopes().get(0).getCode()); - } - @Test public void addScope() { IdsScopeProvider.addScope(new IdsScope().setCode("code").setDescription("aasdasd"));