浏览代码

Polish OAuth2ResourceServerConfigurerTests

To confirm that resource server only produces SCOPE_<scope>
authorities by default.

Issue gh-7596
Josh Cummings 5 年之前
父节点
当前提交
925bf48ec0

+ 7 - 9
config/src/test/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/resource/OAuth2ResourceServerConfigurerTests.java

@@ -76,7 +76,6 @@ import org.springframework.security.config.http.SessionCreationPolicy;
 import org.springframework.security.config.test.SpringTestRule;
 import org.springframework.security.config.test.SpringTestRule;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.annotation.AuthenticationPrincipal;
 import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.userdetails.UserDetailsService;
 import org.springframework.security.core.userdetails.UserDetailsService;
 import org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal;
 import org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal;
@@ -383,7 +382,7 @@ public class OAuth2ResourceServerConfigurerTests {
 		this.mvc.perform(get("/requires-read-scope")
 		this.mvc.perform(get("/requires-read-scope")
 				.with(bearerToken(token)))
 				.with(bearerToken(token)))
 				.andExpect(status().isOk())
 				.andExpect(status().isOk())
-				.andExpect(content().string("SCOPE_message:read"));
+				.andExpect(content().string("[SCOPE_message:read]"));
 	}
 	}
 
 
 	@Test
 	@Test
@@ -469,7 +468,7 @@ public class OAuth2ResourceServerConfigurerTests {
 		this.mvc.perform(get("/ms-requires-read-scope")
 		this.mvc.perform(get("/ms-requires-read-scope")
 				.with(bearerToken(token)))
 				.with(bearerToken(token)))
 				.andExpect(status().isOk())
 				.andExpect(status().isOk())
-				.andExpect(content().string("SCOPE_message:read"));
+				.andExpect(content().string("[SCOPE_message:read]"));
 	}
 	}
 
 
 	@Test
 	@Test
@@ -483,7 +482,7 @@ public class OAuth2ResourceServerConfigurerTests {
 		this.mvc.perform(get("/ms-requires-read-scope")
 		this.mvc.perform(get("/ms-requires-read-scope")
 				.with(bearerToken(token)))
 				.with(bearerToken(token)))
 				.andExpect(status().isOk())
 				.andExpect(status().isOk())
-				.andExpect(content().string("SCOPE_message:read"));
+				.andExpect(content().string("[SCOPE_message:read]"));
 	}
 	}
 
 
 	@Test
 	@Test
@@ -2107,21 +2106,20 @@ public class OAuth2ResourceServerConfigurerTests {
 		}
 		}
 
 
 		@RequestMapping(value = "/authenticated", method = { GET, POST })
 		@RequestMapping(value = "/authenticated", method = { GET, POST })
-		public String authenticated(@AuthenticationPrincipal Authentication authentication) {
+		public String authenticated(Authentication authentication) {
 			return authentication.getName();
 			return authentication.getName();
 		}
 		}
 
 
 		@GetMapping("/requires-read-scope")
 		@GetMapping("/requires-read-scope")
-		public String requiresReadScope(@AuthenticationPrincipal JwtAuthenticationToken token) {
+		public String requiresReadScope(JwtAuthenticationToken token) {
 			return token.getAuthorities().stream()
 			return token.getAuthorities().stream()
 					.map(GrantedAuthority::getAuthority)
 					.map(GrantedAuthority::getAuthority)
-					.filter(auth -> auth.endsWith("message:read"))
-					.findFirst().orElse(null);
+					.collect(Collectors.toList()).toString();
 		}
 		}
 
 
 		@GetMapping("/ms-requires-read-scope")
 		@GetMapping("/ms-requires-read-scope")
 		@PreAuthorize("hasAuthority('SCOPE_message:read')")
 		@PreAuthorize("hasAuthority('SCOPE_message:read')")
-		public String msRequiresReadScope(@AuthenticationPrincipal JwtAuthenticationToken token) {
+		public String msRequiresReadScope(JwtAuthenticationToken token) {
 			return requiresReadScope(token);
 			return requiresReadScope(token);
 		}
 		}