Merge Formatting Changes
Issue gh-8945
This commit is contained in:
+2
-1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -52,7 +53,7 @@ public class HelloRSocketApplicationITests {
|
||||
public void messageWhenAuthenticatedThenSuccess() {
|
||||
UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("user", "password");
|
||||
RSocketRequester requester = this.requester
|
||||
.rsocketStrategies(builder -> builder.encoder(new BasicAuthenticationEncoder()))
|
||||
.rsocketStrategies((builder) -> builder.encoder(new BasicAuthenticationEncoder()))
|
||||
.setupMetadata(credentials, BASIC_AUTHENTICATION_MIME_TYPE)
|
||||
.connectTcp("localhost", this.port)
|
||||
.block();
|
||||
|
||||
+3
-2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
@@ -69,11 +70,11 @@ public class HelloWebfluxMethodApplicationITests {
|
||||
}
|
||||
|
||||
private Consumer<HttpHeaders> robsCredentials() {
|
||||
return httpHeaders -> httpHeaders.setBasicAuth("rob", "rob");
|
||||
return (httpHeaders) -> httpHeaders.setBasicAuth("rob", "rob");
|
||||
}
|
||||
|
||||
private Consumer<HttpHeaders> adminCredentials() {
|
||||
return httpHeaders -> httpHeaders.setBasicAuth("admin", "admin");
|
||||
return (httpHeaders) -> httpHeaders.setBasicAuth("admin", "admin");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SecurityConfig {
|
||||
return http
|
||||
// Demonstrate that method security works
|
||||
// Best practice to use both for defense in depth
|
||||
.authorizeExchange(exchanges -> exchanges
|
||||
.authorizeExchange((exchanges) -> exchanges
|
||||
.anyExchange().permitAll()
|
||||
)
|
||||
.httpBasic(withDefaults())
|
||||
|
||||
+3
-8
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockUser;
|
||||
@@ -58,8 +59,6 @@ public class HelloWebfluxMethodApplicationTests {
|
||||
.expectStatus().isUnauthorized();
|
||||
}
|
||||
|
||||
// --- Basic Authentication ---
|
||||
|
||||
@Test
|
||||
public void messageWhenUserThenForbidden() {
|
||||
this.rest
|
||||
@@ -81,8 +80,6 @@ public class HelloWebfluxMethodApplicationTests {
|
||||
.expectBody(String.class).isEqualTo("Hello World!");
|
||||
}
|
||||
|
||||
// --- WithMockUser ---
|
||||
|
||||
@Test
|
||||
@WithMockUser
|
||||
public void messageWhenWithMockUserThenForbidden() {
|
||||
@@ -104,8 +101,6 @@ public class HelloWebfluxMethodApplicationTests {
|
||||
.expectBody(String.class).isEqualTo("Hello World!");
|
||||
}
|
||||
|
||||
// --- mutateWith mockUser ---
|
||||
|
||||
@Test
|
||||
public void messageWhenMutateWithMockUserThenForbidden() {
|
||||
this.rest
|
||||
@@ -128,10 +123,10 @@ public class HelloWebfluxMethodApplicationTests {
|
||||
}
|
||||
|
||||
private Consumer<HttpHeaders> robsCredentials() {
|
||||
return httpHeaders -> httpHeaders.setBasicAuth("rob", "rob");
|
||||
return (httpHeaders) -> httpHeaders.setBasicAuth("rob", "rob");
|
||||
}
|
||||
|
||||
private Consumer<HttpHeaders> adminCredentials() {
|
||||
return httpHeaders -> httpHeaders.setBasicAuth("admin", "admin");
|
||||
return (httpHeaders) -> httpHeaders.setBasicAuth("admin", "admin");
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
@@ -68,10 +69,10 @@ public class HelloWebfluxApplicationITests {
|
||||
}
|
||||
|
||||
private Consumer<HttpHeaders> userCredentials() {
|
||||
return httpHeaders -> httpHeaders.setBasicAuth("user", "user");
|
||||
return (httpHeaders) -> httpHeaders.setBasicAuth("user", "user");
|
||||
}
|
||||
|
||||
private Consumer<HttpHeaders> invalidCredentials() {
|
||||
return httpHeaders -> httpHeaders.setBasicAuth("user", "INVALID");
|
||||
return (httpHeaders) -> httpHeaders.setBasicAuth("user", "INVALID");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockUser;
|
||||
@@ -104,10 +105,10 @@ public class HelloWebfluxApplicationTests {
|
||||
}
|
||||
|
||||
private Consumer<HttpHeaders> userCredentials() {
|
||||
return httpHeaders -> httpHeaders.setBasicAuth("user", "user");
|
||||
return (httpHeaders) -> httpHeaders.setBasicAuth("user", "user");
|
||||
}
|
||||
|
||||
private Consumer<HttpHeaders> invalidCredentials() {
|
||||
return httpHeaders -> httpHeaders.setBasicAuth("user", "INVALID");
|
||||
return (httpHeaders) -> httpHeaders.setBasicAuth("user", "INVALID");
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
@@ -74,10 +75,10 @@ public class HelloWebfluxFnApplicationITests {
|
||||
}
|
||||
|
||||
private Consumer<HttpHeaders> userCredentials() {
|
||||
return httpHeaders -> httpHeaders.setBasicAuth("user", "user");
|
||||
return (httpHeaders) -> httpHeaders.setBasicAuth("user", "user");
|
||||
}
|
||||
|
||||
private Consumer<HttpHeaders> invalidCredentials() {
|
||||
return httpHeaders -> httpHeaders.setBasicAuth("user", "INVALID");
|
||||
return (httpHeaders) -> httpHeaders.setBasicAuth("user", "INVALID");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class HelloUserController {
|
||||
public Mono<ServerResponse> hello(ServerRequest serverRequest) {
|
||||
return serverRequest.principal()
|
||||
.map(Principal::getName)
|
||||
.flatMap(username ->
|
||||
.flatMap((username) ->
|
||||
ServerResponse.ok()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.syncBody(Collections.singletonMap("message", "Hello " + username + "!"))
|
||||
|
||||
+3
-2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockUser;
|
||||
@@ -105,10 +106,10 @@ public class HelloWebfluxFnApplicationTests {
|
||||
}
|
||||
|
||||
private Consumer<HttpHeaders> userCredentials() {
|
||||
return httpHeaders -> httpHeaders.setBasicAuth("user", "user");
|
||||
return (httpHeaders) -> httpHeaders.setBasicAuth("user", "user");
|
||||
}
|
||||
|
||||
private Consumer<HttpHeaders> invalidCredentials() {
|
||||
return httpHeaders -> httpHeaders.setBasicAuth("user", "INVALID");
|
||||
return (httpHeaders) -> httpHeaders.setBasicAuth("user", "INVALID");
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.security.samples;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.security.samples;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+3
-2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.security.samples.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -34,11 +35,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeRequests(authorize -> authorize
|
||||
.authorizeRequests((authorize) -> authorize
|
||||
.antMatchers("/css/**", "/index").permitAll()
|
||||
.antMatchers("/user/**").hasRole("USER")
|
||||
)
|
||||
.formLogin(formLogin -> formLogin
|
||||
.formLogin((formLogin) -> formLogin
|
||||
.loginPage("/login")
|
||||
.failureUrl("/login-error")
|
||||
);
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.security.samples.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.security.samples;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.security.samples;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.security.samples.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import java.math.BigInteger;
|
||||
@@ -166,7 +167,7 @@ class UserConfig extends WebSecurityConfigurerAdapter {
|
||||
.and()
|
||||
.httpBasic()
|
||||
.and()
|
||||
.csrf().ignoringRequestMatchers(request -> "/introspect".equals(request.getRequestURI()));
|
||||
.csrf().ignoringRequestMatchers((request) -> "/introspect".equals(request.getRequestURI()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -45,7 +46,7 @@ public class OAuth2LoginApplicationTests {
|
||||
@Test
|
||||
public void requestWhenMockOidcLoginThenIndex() {
|
||||
this.clientRegistrationRepository.findByRegistrationId("github")
|
||||
.map(clientRegistration ->
|
||||
.map((clientRegistration) ->
|
||||
this.test.mutateWith(mockOAuth2Login().clientRegistration(clientRegistration))
|
||||
.get().uri("/")
|
||||
.exchange()
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+2
-2
@@ -65,12 +65,12 @@ public class OAuth2LoginControllerTests {
|
||||
.bindToController(this.controller)
|
||||
.apply(springSecurity())
|
||||
.webFilter(new SecurityContextServerWebExchangeWebFilter())
|
||||
.argumentResolvers(c -> {
|
||||
.argumentResolvers((c) -> {
|
||||
c.addCustomResolver(new AuthenticationPrincipalArgumentResolver(new ReactiveAdapterRegistry()));
|
||||
c.addCustomResolver(new OAuth2AuthorizedClientArgumentResolver
|
||||
(this.clientRegistrationRepository, this.authorizedClientRepository));
|
||||
})
|
||||
.viewResolvers(c -> c.viewResolver(this.viewResolver))
|
||||
.viewResolvers((c) -> c.viewResolver(this.viewResolver))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -307,7 +308,7 @@ public class OAuth2LoginApplicationTests {
|
||||
|
||||
private HtmlAnchor getClientAnchorElement(HtmlPage page, ClientRegistration clientRegistration) {
|
||||
Optional<HtmlAnchor> clientAnchorElement = page.getAnchors().stream()
|
||||
.filter(e -> e.asText().equals(clientRegistration.getClientName())).findFirst();
|
||||
.filter((e) -> e.asText().equals(clientRegistration.getClientName())).findFirst();
|
||||
|
||||
return (clientAnchorElement.orElse(null));
|
||||
}
|
||||
@@ -334,17 +335,17 @@ public class OAuth2LoginApplicationTests {
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeRequests(authorizeRequests ->
|
||||
.authorizeRequests((authorizeRequests) ->
|
||||
authorizeRequests
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.oauth2Login(oauth2Login ->
|
||||
.oauth2Login((oauth2Login) ->
|
||||
oauth2Login
|
||||
.tokenEndpoint(tokenEndpoint ->
|
||||
.tokenEndpoint((tokenEndpoint) ->
|
||||
tokenEndpoint
|
||||
.accessTokenResponseClient(this.mockAccessTokenResponseClient())
|
||||
)
|
||||
.userInfoEndpoint(userInfoEndpoint ->
|
||||
.userInfoEndpoint((userInfoEndpoint) ->
|
||||
userInfoEndpoint
|
||||
.userService(this.mockUserService())
|
||||
)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.web;
|
||||
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class OAuth2LoginControllerTests {
|
||||
|
||||
this.mvc.perform(get("/").with(oauth2Login()
|
||||
.clientRegistration(clientRegistration)
|
||||
.attributes(a -> a.put("sub", "spring-security"))))
|
||||
.attributes((a) -> a.put("sub", "spring-security"))))
|
||||
.andExpect(model().attribute("userName", "spring-security"))
|
||||
.andExpect(model().attribute("clientName", "my-client-name"))
|
||||
.andExpect(model().attribute("userAttributes", Collections.singletonMap("sub", "spring-security")));
|
||||
|
||||
+1
-2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -60,8 +61,6 @@ public class OAuth2ResourceServerApplicationITests {
|
||||
.andExpect(content().string(containsString("Hello, subject!")));
|
||||
}
|
||||
|
||||
// -- tests with scopes
|
||||
|
||||
@Test
|
||||
public void performWhenValidBearerTokenThenScopedRequestsAlsoWork()
|
||||
throws Exception {
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
|
||||
+3
-2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import java.net.URL;
|
||||
@@ -68,12 +69,12 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
// @formatter:off
|
||||
http
|
||||
.authorizeRequests(authorizeRequests ->
|
||||
.authorizeRequests((authorizeRequests) ->
|
||||
authorizeRequests
|
||||
.antMatchers("/message/**").hasAuthority("SCOPE_message:read")
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.oauth2ResourceServer(oauth2ResourceServer ->
|
||||
.oauth2ResourceServer((oauth2ResourceServer) ->
|
||||
oauth2ResourceServer
|
||||
.jwt(withDefaults())
|
||||
);
|
||||
|
||||
+1
-4
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -60,8 +61,6 @@ public class OAuth2ResourceServerApplicationITests {
|
||||
.andExpect(content().string(containsString("Hello, subject for tenant one!")));
|
||||
}
|
||||
|
||||
// -- tests with scopes
|
||||
|
||||
@Test
|
||||
public void tenantOnePerformWhenValidBearerTokenThenScopedRequestsAlsoWork()
|
||||
throws Exception {
|
||||
@@ -96,8 +95,6 @@ public class OAuth2ResourceServerApplicationITests {
|
||||
.andExpect(content().string(containsString("Hello, subject for tenant two!")));
|
||||
}
|
||||
|
||||
// -- tests with scopes
|
||||
|
||||
@Test
|
||||
public void tenantTwoPerformWhenValidBearerTokenThenScopedRequestsAlsoWork()
|
||||
throws Exception {
|
||||
|
||||
+6
-6
@@ -156,10 +156,10 @@ public class MockWebServerPropertySource extends PropertySource<MockWebServer> i
|
||||
|
||||
if ("/introspect".equals(request.getPath())) {
|
||||
return Optional.ofNullable(request.getHeader(HttpHeaders.AUTHORIZATION))
|
||||
.filter(authorization -> isAuthorized(authorization, "client", "secret"))
|
||||
.map(authorization -> parseBody(request.getBody()))
|
||||
.map(parameters -> parameters.get("token"))
|
||||
.map(token -> {
|
||||
.filter((authorization) -> isAuthorized(authorization, "client", "secret"))
|
||||
.map((authorization) -> parseBody(request.getBody()))
|
||||
.map((parameters) -> parameters.get("token"))
|
||||
.map((token) -> {
|
||||
if ("00ed5855-1869-47a0-b0c9-0f3ce520aee7".equals(token)) {
|
||||
return NO_SCOPES_RESPONSE;
|
||||
} else if ("b43d1500-c405-4dc9-b9c9-6cfd966c34c9".equals(token)) {
|
||||
@@ -181,8 +181,8 @@ public class MockWebServerPropertySource extends PropertySource<MockWebServer> i
|
||||
|
||||
private Map<String, Object> parseBody(Buffer body) {
|
||||
return Stream.of(body.readUtf8().split("&"))
|
||||
.map(parameter -> parameter.split("="))
|
||||
.collect(Collectors.toMap(parts -> parts[0], parts -> parts[1]));
|
||||
.map((parameter) -> parameter.split("="))
|
||||
.collect(Collectors.toMap((parts) -> parts[0], (parts) -> parts[1]));
|
||||
}
|
||||
|
||||
private static MockResponse response(String body, int status) {
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
|
||||
+3
-2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -36,11 +37,11 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
// @formatter:off
|
||||
http
|
||||
.authorizeRequests(authz -> authz
|
||||
.authorizeRequests((authz) -> authz
|
||||
.antMatchers("/message/**").hasAuthority("SCOPE_message:read")
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.oauth2ResourceServer(oauth2 -> oauth2
|
||||
.oauth2ResourceServer((oauth2) -> oauth2
|
||||
.authenticationManagerResolver(this.authenticationManagerResolver)
|
||||
);
|
||||
// @formatter:on
|
||||
|
||||
+1
-2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -60,8 +61,6 @@ public class OAuth2ResourceServerApplicationITests {
|
||||
.andExpect(content().string(containsString("Hello, subject!")));
|
||||
}
|
||||
|
||||
// -- tests with scopes
|
||||
|
||||
@Test
|
||||
public void performWhenValidBearerTokenThenScopedRequestsAlsoWork()
|
||||
throws Exception {
|
||||
|
||||
+6
-6
@@ -142,10 +142,10 @@ public class MockWebServerPropertySource extends PropertySource<MockWebServer> i
|
||||
private MockResponse doDispatch(RecordedRequest request) {
|
||||
if ("/introspect".equals(request.getPath())) {
|
||||
return Optional.ofNullable(request.getHeader(HttpHeaders.AUTHORIZATION))
|
||||
.filter(authorization -> isAuthorized(authorization, "client", "secret"))
|
||||
.map(authorization -> parseBody(request.getBody()))
|
||||
.map(parameters -> parameters.get("token"))
|
||||
.map(token -> {
|
||||
.filter((authorization) -> isAuthorized(authorization, "client", "secret"))
|
||||
.map((authorization) -> parseBody(request.getBody()))
|
||||
.map((parameters) -> parameters.get("token"))
|
||||
.map((token) -> {
|
||||
if ("00ed5855-1869-47a0-b0c9-0f3ce520aee7".equals(token)) {
|
||||
return NO_SCOPES_RESPONSE;
|
||||
} else if ("b43d1500-c405-4dc9-b9c9-6cfd966c34c9".equals(token)) {
|
||||
@@ -167,8 +167,8 @@ public class MockWebServerPropertySource extends PropertySource<MockWebServer> i
|
||||
|
||||
private Map<String, Object> parseBody(Buffer body) {
|
||||
return Stream.of(body.readUtf8().split("&"))
|
||||
.map(parameter -> parameter.split("="))
|
||||
.collect(Collectors.toMap(parts -> parts[0], parts -> parts[1]));
|
||||
.map((parameter) -> parameter.split("="))
|
||||
.collect(Collectors.toMap((parts) -> parts[0], (parts) -> parts[1]));
|
||||
}
|
||||
|
||||
private static MockResponse response(String body, int status) {
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
|
||||
+4
-3
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -35,15 +36,15 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
// @formatter:off
|
||||
http
|
||||
.authorizeRequests(authorizeRequests ->
|
||||
.authorizeRequests((authorizeRequests) ->
|
||||
authorizeRequests
|
||||
.antMatchers(HttpMethod.GET, "/message/**").hasAuthority("SCOPE_message:read")
|
||||
.antMatchers(HttpMethod.POST, "/message/**").hasAuthority("SCOPE_message:write")
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.oauth2ResourceServer(oauth2ResourceServer ->
|
||||
.oauth2ResourceServer((oauth2ResourceServer) ->
|
||||
oauth2ResourceServer
|
||||
.opaqueToken(opaqueToken ->
|
||||
.opaqueToken((opaqueToken) ->
|
||||
opaqueToken
|
||||
.introspectionUri(this.introspectionUri)
|
||||
.introspectionClientCredentials(this.clientId, this.clientSecret)
|
||||
|
||||
+3
-2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -45,13 +46,13 @@ public class OAuth2ResourceServerControllerTests {
|
||||
|
||||
@Test
|
||||
public void indexGreetsAuthenticatedUser() throws Exception {
|
||||
this.mvc.perform(get("/").with(opaqueToken().attributes(a -> a.put("sub", "ch4mpy"))))
|
||||
this.mvc.perform(get("/").with(opaqueToken().attributes((a) -> a.put("sub", "ch4mpy"))))
|
||||
.andExpect(content().string(is("Hello, ch4mpy!")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageCanBeReadWithScopeMessageReadAuthority() throws Exception {
|
||||
this.mvc.perform(get("/message").with(opaqueToken().attributes(a -> a.put("scope", "message:read"))))
|
||||
this.mvc.perform(get("/message").with(opaqueToken().attributes((a) -> a.put("scope", "message:read"))))
|
||||
.andExpect(content().string(is("secret message")));
|
||||
|
||||
this.mvc.perform(get("/message")
|
||||
|
||||
+1
-2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -60,8 +61,6 @@ public class OAuth2ResourceServerApplicationITests {
|
||||
.andExpect(content().string(containsString("Hello, subject!")));
|
||||
}
|
||||
|
||||
// -- tests with scopes
|
||||
|
||||
@Test
|
||||
public void performWhenValidBearerTokenThenScopedRequestsAlsoWork()
|
||||
throws Exception {
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
|
||||
+4
-3
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
@@ -38,14 +39,14 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
// @formatter:off
|
||||
http
|
||||
.authorizeRequests(authorizeRequests ->
|
||||
.authorizeRequests((authorizeRequests) ->
|
||||
authorizeRequests
|
||||
.antMatchers("/message/**").hasAuthority("SCOPE_message:read")
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.oauth2ResourceServer(oauth2ResourceServer ->
|
||||
.oauth2ResourceServer((oauth2ResourceServer) ->
|
||||
oauth2ResourceServer
|
||||
.jwt(jwt ->
|
||||
.jwt((jwt) ->
|
||||
jwt.decoder(jwtDecoder())
|
||||
)
|
||||
);
|
||||
|
||||
+2
-4
@@ -38,8 +38,8 @@ import static org.hamcrest.Matchers.containsString;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class ServerOAuth2ResourceServerApplicationITests {
|
||||
|
||||
Consumer<HttpHeaders> noScopesToken = http -> http.setBearerAuth("eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0IiwiZXhwIjo0NjgzODA1MTI4fQ.ULEPdHG-MK5GlrTQMhgqcyug2brTIZaJIrahUeq9zaiwUSdW83fJ7W1IDd2Z3n4a25JY2uhEcoV95lMfccHR6y_2DLrNvfta22SumY9PEDF2pido54LXG6edIGgarnUbJdR4rpRe_5oRGVa8gDx8FnuZsNv6StSZHAzw5OsuevSTJ1UbJm4UfX3wiahFOQ2OI6G-r5TB2rQNdiPHuNyzG5yznUqRIZ7-GCoMqHMaC-1epKxiX8gYXRROuUYTtcMNa86wh7OVDmvwVmFioRcR58UWBRoO1XQexTtOQq_t8KYsrPZhb9gkyW8x2bAQF-d0J0EJY8JslaH6n4RBaZISww");
|
||||
Consumer<HttpHeaders> messageReadToken = http -> http.setBearerAuth("eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0Iiwic2NvcGUiOiJtZXNzYWdlOnJlYWQiLCJleHAiOjQ2ODM4MDUxNDF9.h-j6FKRFdnTdmAueTZCdep45e6DPwqM68ZQ8doIJ1exi9YxAlbWzOwId6Bd0L5YmCmp63gGQgsBUBLzwnZQ8kLUgUOBEC3UzSWGRqMskCY9_k9pX0iomX6IfF3N0PaYs0WPC4hO1s8wfZQ-6hKQ4KigFi13G9LMLdH58PRMK0pKEvs3gCbHJuEPw-K5ORlpdnleUTQIwINafU57cmK3KocTeknPAM_L716sCuSYGvDl6xUTXO7oPdrXhS_EhxLP6KxrpI1uD4Ea_5OWTh7S0Wx5LLDfU6wBG1DowN20d374zepOIEkR-Jnmr_QlR44vmRqS5ncrF-1R0EGcPX49U6A");
|
||||
Consumer<HttpHeaders> noScopesToken = (http) -> http.setBearerAuth("eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0IiwiZXhwIjo0NjgzODA1MTI4fQ.ULEPdHG-MK5GlrTQMhgqcyug2brTIZaJIrahUeq9zaiwUSdW83fJ7W1IDd2Z3n4a25JY2uhEcoV95lMfccHR6y_2DLrNvfta22SumY9PEDF2pido54LXG6edIGgarnUbJdR4rpRe_5oRGVa8gDx8FnuZsNv6StSZHAzw5OsuevSTJ1UbJm4UfX3wiahFOQ2OI6G-r5TB2rQNdiPHuNyzG5yznUqRIZ7-GCoMqHMaC-1epKxiX8gYXRROuUYTtcMNa86wh7OVDmvwVmFioRcR58UWBRoO1XQexTtOQq_t8KYsrPZhb9gkyW8x2bAQF-d0J0EJY8JslaH6n4RBaZISww");
|
||||
Consumer<HttpHeaders> messageReadToken = (http) -> http.setBearerAuth("eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0Iiwic2NvcGUiOiJtZXNzYWdlOnJlYWQiLCJleHAiOjQ2ODM4MDUxNDF9.h-j6FKRFdnTdmAueTZCdep45e6DPwqM68ZQ8doIJ1exi9YxAlbWzOwId6Bd0L5YmCmp63gGQgsBUBLzwnZQ8kLUgUOBEC3UzSWGRqMskCY9_k9pX0iomX6IfF3N0PaYs0WPC4hO1s8wfZQ-6hKQ4KigFi13G9LMLdH58PRMK0pKEvs3gCbHJuEPw-K5ORlpdnleUTQIwINafU57cmK3KocTeknPAM_L716sCuSYGvDl6xUTXO7oPdrXhS_EhxLP6KxrpI1uD4Ea_5OWTh7S0Wx5LLDfU6wBG1DowN20d374zepOIEkR-Jnmr_QlR44vmRqS5ncrF-1R0EGcPX49U6A");
|
||||
|
||||
@Autowired
|
||||
private WebTestClient rest;
|
||||
@@ -55,8 +55,6 @@ public class ServerOAuth2ResourceServerApplicationITests {
|
||||
.expectBody(String.class).isEqualTo("Hello, subject!");
|
||||
}
|
||||
|
||||
// -- tests with scopes
|
||||
|
||||
@Test
|
||||
public void getWhenValidBearerTokenThenScopedRequestsAlsoWork() {
|
||||
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
|
||||
@@ -34,13 +34,13 @@ public class SecurityConfig {
|
||||
@Bean
|
||||
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
|
||||
http
|
||||
.authorizeExchange(exchanges ->
|
||||
.authorizeExchange((exchanges) ->
|
||||
exchanges
|
||||
.pathMatchers(HttpMethod.GET, "/message/**").hasAuthority("SCOPE_message:read")
|
||||
.pathMatchers(HttpMethod.POST, "/message/**").hasAuthority("SCOPE_message:write")
|
||||
.anyExchange().authenticated()
|
||||
)
|
||||
.oauth2ResourceServer(oauth2ResourceServer ->
|
||||
.oauth2ResourceServer((oauth2ResourceServer) ->
|
||||
oauth2ResourceServer
|
||||
.jwt(withDefaults())
|
||||
);
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+5
-5
@@ -50,14 +50,14 @@ public class OAuth2ResourceServerControllerTests {
|
||||
|
||||
@Test
|
||||
public void indexGreetsAuthenticatedUser() {
|
||||
this.rest.mutateWith(mockJwt().jwt(jwt -> jwt.subject("test-subject")))
|
||||
this.rest.mutateWith(mockJwt().jwt((jwt) -> jwt.subject("test-subject")))
|
||||
.get().uri("/").exchange()
|
||||
.expectBody(String.class).isEqualTo("Hello, test-subject!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageCanBeReadWithScopeMessageReadAuthority() {
|
||||
this.rest.mutateWith(mockJwt().jwt(jwt -> jwt.claim("scope", "message:read")))
|
||||
this.rest.mutateWith(mockJwt().jwt((jwt) -> jwt.claim("scope", "message:read")))
|
||||
.get().uri("/message").exchange()
|
||||
.expectBody(String.class).isEqualTo("secret message");
|
||||
|
||||
@@ -78,7 +78,7 @@ public class OAuth2ResourceServerControllerTests {
|
||||
Jwt jwt = jwt().claim("scope", "").build();
|
||||
when(this.jwtDecoder.decode(anyString())).thenReturn(Mono.just(jwt));
|
||||
this.rest.post().uri("/message")
|
||||
.headers(headers -> headers.setBearerAuth(jwt.getTokenValue()))
|
||||
.headers((headers) -> headers.setBearerAuth(jwt.getTokenValue()))
|
||||
.syncBody("Hello message").exchange()
|
||||
.expectStatus().isForbidden();
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class OAuth2ResourceServerControllerTests {
|
||||
Jwt jwt = jwt().claim("scope", "message:read").build();
|
||||
when(this.jwtDecoder.decode(anyString())).thenReturn(Mono.just(jwt));
|
||||
this.rest.post().uri("/message")
|
||||
.headers(headers -> headers.setBearerAuth(jwt.getTokenValue()))
|
||||
.headers((headers) -> headers.setBearerAuth(jwt.getTokenValue()))
|
||||
.syncBody("Hello message").exchange()
|
||||
.expectStatus().isForbidden();
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public class OAuth2ResourceServerControllerTests {
|
||||
Jwt jwt = jwt().claim("scope", "message:write").build();
|
||||
when(this.jwtDecoder.decode(anyString())).thenReturn(Mono.just(jwt));
|
||||
this.rest.post().uri("/message")
|
||||
.headers(headers -> headers.setBearerAuth(jwt.getTokenValue()))
|
||||
.headers((headers) -> headers.setBearerAuth(jwt.getTokenValue()))
|
||||
.syncBody("Hello message").exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody(String.class).isEqualTo("Message was created. Content: Hello message");
|
||||
|
||||
+1
-2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -62,8 +63,6 @@ public class OAuth2ResourceServerApplicationITests {
|
||||
.andExpect(content().string(containsString("Hello, subject!")));
|
||||
}
|
||||
|
||||
// -- tests with scopes
|
||||
|
||||
@Test
|
||||
public void performWhenValidBearerTokenThenScopedRequestsAlsoWork()
|
||||
throws Exception {
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -37,7 +38,7 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
// @formatter:off
|
||||
http
|
||||
.authorizeRequests(authorizeRequests ->
|
||||
.authorizeRequests((authorizeRequests) ->
|
||||
authorizeRequests
|
||||
.antMatchers(HttpMethod.GET, "/message/**").hasAuthority("SCOPE_message:read")
|
||||
.antMatchers(HttpMethod.POST, "/message/**").hasAuthority("SCOPE_message:write")
|
||||
|
||||
+5
-4
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -47,13 +48,13 @@ public class OAuth2ResourceServerControllerTests {
|
||||
|
||||
@Test
|
||||
public void indexGreetsAuthenticatedUser() throws Exception {
|
||||
mockMvc.perform(get("/").with(jwt().jwt(jwt -> jwt.subject("ch4mpy"))))
|
||||
mockMvc.perform(get("/").with(jwt().jwt((jwt) -> jwt.subject("ch4mpy"))))
|
||||
.andExpect(content().string(is("Hello, ch4mpy!")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageCanBeReadWithScopeMessageReadAuthority() throws Exception {
|
||||
mockMvc.perform(get("/message").with(jwt().jwt(jwt -> jwt.claim("scope", "message:read"))))
|
||||
mockMvc.perform(get("/message").with(jwt().jwt((jwt) -> jwt.claim("scope", "message:read"))))
|
||||
.andExpect(content().string(is("secret message")));
|
||||
|
||||
mockMvc.perform(get("/message")
|
||||
@@ -79,7 +80,7 @@ public class OAuth2ResourceServerControllerTests {
|
||||
public void messageCanNotBeCreatedWithScopeMessageReadAuthority() throws Exception {
|
||||
mockMvc.perform(post("/message")
|
||||
.content("Hello message")
|
||||
.with(jwt().jwt(jwt -> jwt.claim("scope", "message:read"))))
|
||||
.with(jwt().jwt((jwt) -> jwt.claim("scope", "message:read"))))
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
@@ -88,7 +89,7 @@ public class OAuth2ResourceServerControllerTests {
|
||||
throws Exception {
|
||||
mockMvc.perform(post("/message")
|
||||
.content("Hello message")
|
||||
.with(jwt().jwt(jwt -> jwt.claim("scope", "message:write"))))
|
||||
.with(jwt().jwt((jwt) -> jwt.claim("scope", "message:write"))))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(is("Message was created. Content: Hello message")));
|
||||
}
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -34,7 +35,7 @@ public class SecurityConfig {
|
||||
@Bean
|
||||
SecurityWebFilterChain configure(ServerHttpSecurity http) {
|
||||
http
|
||||
.authorizeExchange(exchanges ->
|
||||
.authorizeExchange((exchanges) ->
|
||||
exchanges
|
||||
.pathMatchers("/", "/public/**").permitAll()
|
||||
.anyExchange().authenticated()
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.web;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.web;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -35,7 +36,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeRequests(authorizeRequests ->
|
||||
.authorizeRequests((authorizeRequests) ->
|
||||
authorizeRequests
|
||||
.mvcMatchers("/", "/public/**").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.web;
|
||||
|
||||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
|
||||
|
||||
+1
-1
@@ -483,7 +483,7 @@ public class Saml2LoginIntegrationTests {
|
||||
String code,
|
||||
Matcher<String> message
|
||||
) {
|
||||
return result -> {
|
||||
return (result) -> {
|
||||
final HttpSession session = result.getRequest().getSession(false);
|
||||
AssertionErrors.assertNotNull("HttpSession", session);
|
||||
Object exception = session.getAttribute(AUTHENTICATION_EXCEPTION);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+1
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
@@ -46,13 +46,13 @@ public class WebfluxFormSecurityConfig {
|
||||
@Bean
|
||||
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
|
||||
http
|
||||
.authorizeExchange(exchanges ->
|
||||
.authorizeExchange((exchanges) ->
|
||||
exchanges
|
||||
.pathMatchers("/login").permitAll()
|
||||
.anyExchange().authenticated()
|
||||
)
|
||||
.httpBasic(withDefaults())
|
||||
.formLogin(formLogin ->
|
||||
.formLogin((formLogin) ->
|
||||
formLogin
|
||||
.loginPage("/login")
|
||||
);
|
||||
|
||||
@@ -35,6 +35,6 @@ public class MeController {
|
||||
public Mono<String> me() {
|
||||
return ReactiveSecurityContextHolder.getContext()
|
||||
.map(SecurityContext::getAuthentication)
|
||||
.map(authentication -> "Hello, " + authentication.getName());
|
||||
.map((authentication) -> "Hello, " + authentication.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class WebfluxX509Application {
|
||||
// @formatter:off
|
||||
http
|
||||
.x509(withDefaults())
|
||||
.authorizeExchange(exchanges ->
|
||||
.authorizeExchange((exchanges) ->
|
||||
exchanges
|
||||
.anyExchange().authenticated()
|
||||
);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class WebfluxX509ApplicationTest {
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody()
|
||||
.consumeWith(result -> {
|
||||
.consumeWith((result) -> {
|
||||
String responseBody = new String(result.getResponseBody());
|
||||
assertThat(responseBody).contains("Hello, client");
|
||||
});
|
||||
@@ -79,7 +79,7 @@ public class WebfluxX509ApplicationTest {
|
||||
.trustManager(devCA)
|
||||
.keyManager(clientKey, clientCrt);
|
||||
|
||||
HttpClient httpClient = HttpClient.create().secure(sslContextSpec -> sslContextSpec.sslContext(sslContextBuilder));
|
||||
HttpClient httpClient = HttpClient.create().secure((sslContextSpec) -> sslContextSpec.sslContext(sslContextBuilder));
|
||||
ClientHttpConnector httpConnector = new ReactorClientHttpConnector(httpClient);
|
||||
|
||||
return WebTestClient
|
||||
|
||||
Reference in New Issue
Block a user