Skip to content

Commit 3a0dfa4

Browse files
author
Dave Syer
committed
Use Java 8 APIs to match org
1 parent 7900000 commit 3a0dfa4

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

custom-error/README.adoc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,9 @@ public AuthoritiesExtractor authoritiesExtractor(OAuth2RestOperations template)
134134
String url = (String) map.get("organizations_url");
135135
@SuppressWarnings("unchecked")
136136
List<Map<String, Object>> orgs = template.getForObject(url, List.class);
137-
for (Map<String, Object> org : orgs) {
138-
if ("spring-projects".equals(org.get("login"))) {
139-
return AuthorityUtils
140-
.commaSeparatedStringToAuthorityList("ROLE_USER");
141-
}
137+
if (orgs.stream()
138+
.anyMatch(org -> "spring-projects".equals(org.get("login")))) {
139+
return AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER");
142140
}
143141
throw new BadCredentialsException("Not in Spring Projects origanization");
144142
};

custom-error/src/main/java/com/example/SocialApplication.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ public AuthoritiesExtractor authoritiesExtractor(OAuth2RestOperations template)
6262
String url = (String) map.get("organizations_url");
6363
@SuppressWarnings("unchecked")
6464
List<Map<String, Object>> orgs = template.getForObject(url, List.class);
65-
for (Map<String, Object> org : orgs) {
66-
if ("spring-projects".equals(org.get("login"))) {
67-
return AuthorityUtils
68-
.commaSeparatedStringToAuthorityList("ROLE_USER");
69-
}
65+
if (orgs.stream()
66+
.anyMatch(org -> "spring-projects".equals(org.get("login")))) {
67+
return AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER");
7068
}
7169
throw new BadCredentialsException("Not in Spring Team");
7270
};

0 commit comments

Comments
 (0)