Use parenthesis with single-arg lambdas

Use regular expression search/replace to ensure all single-arg
lambdas have parenthesis. This aligns with the style used in Spring
Boot and ensure that single-arg and multi-arg lambdas are consistent.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-29 18:18:05 -07:00
committed by Rob Winch
parent 01d90c9881
commit 52f20b5281
426 changed files with 1668 additions and 1617 deletions

View File

@@ -53,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();

View File

@@ -70,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");
}
}

View File

@@ -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())

View File

@@ -123,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");
}
}

View File

@@ -69,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");
}
}

View File

@@ -105,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");
}
}

View File

@@ -75,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");
}
}

View File

@@ -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 + "!"))

View File

@@ -106,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");
}
}

View File

@@ -35,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")
);

View File

@@ -167,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

View File

@@ -46,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()

View File

@@ -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();
}

View File

@@ -308,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));
}
@@ -335,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())
)

View File

@@ -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")));

View File

@@ -69,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())
);

View File

@@ -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) {

View File

@@ -37,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

View File

@@ -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) {

View File

@@ -36,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)

View File

@@ -46,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")

View File

@@ -39,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())
)
);

View File

@@ -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;

View File

@@ -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())
);

View File

@@ -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");

View File

@@ -38,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")

View File

@@ -48,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")
@@ -80,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());
}
@@ -89,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")));
}

View File

@@ -35,7 +35,7 @@ public class SecurityConfig {
@Bean
SecurityWebFilterChain configure(ServerHttpSecurity http) {
http
.authorizeExchange(exchanges ->
.authorizeExchange((exchanges) ->
exchanges
.pathMatchers("/", "/public/**").permitAll()
.anyExchange().authenticated()

View File

@@ -36,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()

View File

@@ -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);

View File

@@ -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")
);

View File

@@ -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());
}
}

View File

@@ -46,7 +46,7 @@ public class WebfluxX509Application {
// @formatter:off
http
.x509(withDefaults())
.authorizeExchange(exchanges ->
.authorizeExchange((exchanges) ->
exchanges
.anyExchange().authenticated()
);

View File

@@ -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

View File

@@ -43,14 +43,14 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(
HttpSecurity http) throws Exception {
http
.authorizeRequests(authorizeRequests ->
.authorizeRequests((authorizeRequests) ->
authorizeRequests
.anyRequest().authenticated()
)
.formLogin(withDefaults())
.sessionManagement(sessionManagement ->
.sessionManagement((sessionManagement) ->
sessionManagement
.sessionConcurrency(sessionConcurrency ->
.sessionConcurrency((sessionConcurrency) ->
sessionConcurrency
.maximumSessions(1)
.expiredUrl("/login?expired")

View File

@@ -30,17 +30,17 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests(authorizeRequests ->
.authorizeRequests((authorizeRequests) ->
authorizeRequests
.antMatchers("/resources/**").permitAll()
.anyRequest().authenticated()
)
.formLogin(formLogin ->
.formLogin((formLogin) ->
formLogin
.loginPage("/login")
.permitAll()
)
.logout(logout ->
.logout((logout) ->
logout
.permitAll()
);

View File

@@ -32,64 +32,64 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests(authorizeRequests ->
.authorizeRequests((authorizeRequests) ->
authorizeRequests
.antMatchers("/resources/**").permitAll()
.anyRequest().authenticated()
)
.openidLogin(openidLogin ->
.openidLogin((openidLogin) ->
openidLogin
.loginPage("/login")
.permitAll()
.authenticationUserDetailsService(new CustomUserDetailsService())
.attributeExchange(googleExchange ->
.attributeExchange((googleExchange) ->
googleExchange
.identifierPattern("https://www.google.com/.*")
.attribute(emailAttribute ->
.attribute((emailAttribute) ->
emailAttribute
.name("email")
.type("https://axschema.org/contact/email")
.required(true)
)
.attribute(firstnameAttribute ->
.attribute((firstnameAttribute) ->
firstnameAttribute
.name("firstname")
.type("https://axschema.org/namePerson/first")
.required(true)
)
.attribute(lastnameAttribute ->
.attribute((lastnameAttribute) ->
lastnameAttribute
.name("lastname")
.type("https://axschema.org/namePerson/last")
.required(true)
)
)
.attributeExchange(yahooExchange ->
.attributeExchange((yahooExchange) ->
yahooExchange
.identifierPattern(".*yahoo.com.*")
.attribute(emailAttribute ->
.attribute((emailAttribute) ->
emailAttribute
.name("email")
.type("https://axschema.org/contact/email")
.required(true)
)
.attribute(fullnameAttribute ->
.attribute((fullnameAttribute) ->
fullnameAttribute
.name("fullname")
.type("https://axschema.org/namePerson")
.required(true)
)
)
.attributeExchange(myopenidExchange ->
.attributeExchange((myopenidExchange) ->
myopenidExchange
.identifierPattern(".*myopenid.com.*")
.attribute(emailAttribute ->
.attribute((emailAttribute) ->
emailAttribute
.name("email")
.type("https://schema.openid.net/contact/email")
.required(true)
)
.attribute(fullnameAttribute ->
.attribute((fullnameAttribute) ->
fullnameAttribute
.name("fullname")
.type("https://schema.openid.net/namePerson")

View File

@@ -27,12 +27,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests(authorizeRequests ->
.authorizeRequests((authorizeRequests) ->
authorizeRequests
.antMatchers("/login", "/resources/**").permitAll()
.anyRequest().authenticated()
)
.jee(jee ->
.jee((jee) ->
jee
.mappableRoles("USER", "ADMIN")
);

View File

@@ -42,12 +42,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests(authorizeRequests ->
.authorizeRequests((authorizeRequests) ->
authorizeRequests
.antMatchers("/resources/**").permitAll()
.anyRequest().authenticated()
)
.formLogin(formLogin ->
.formLogin((formLogin) ->
formLogin
.loginPage("/login")
.permitAll()

View File

@@ -57,11 +57,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
return RelyingPartyRegistration.withRegistrationId(registrationId)
.entityId(localEntityIdTemplate)
.assertionConsumerServiceLocation(acsUrlTemplate)
.signingX509Credentials(c -> c.add(signingCredential))
.assertingPartyDetails(config -> config
.signingX509Credentials((c) -> c.add(signingCredential))
.assertingPartyDetails((config) -> config
.entityId(idpEntityId)
.singleSignOnServiceLocation(webSsoEndpoint)
.verificationX509Credentials(c -> c.add(idpVerificationCertificate)))
.verificationX509Credentials((c) -> c.add(idpVerificationCertificate)))
.build();
}

View File

@@ -52,7 +52,7 @@ public class SecurityConfigTests {
Saml2WebSsoAuthenticationFilter filter = (Saml2WebSsoAuthenticationFilter) filters
.stream()
.filter(
f -> f instanceof Saml2WebSsoAuthenticationFilter
(f) -> f instanceof Saml2WebSsoAuthenticationFilter
)
.findFirst()
.get();

View File

@@ -43,7 +43,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests(authorizeRequests ->
.authorizeRequests((authorizeRequests) ->
authorizeRequests
.anyRequest().authenticated()
)

View File

@@ -117,14 +117,14 @@ public class CasSampleProxyTests {
public void extremelySecurePageWhenReusingTicketThenDisplays() {
this.login.to(this::serviceParam).assertAt().login("rod");
Map<String, String> ptCache = new HashMap<>();
this.extremelySecure.to(url -> url + "?ticket=" + ptCache.computeIfAbsent(url, this::getPt)).assertAt();
this.extremelySecure.to(url -> url + "?ticket=" + ptCache.get(url)).assertAt();
this.extremelySecure.to((url) -> url + "?ticket=" + ptCache.computeIfAbsent(url, this::getPt)).assertAt();
this.extremelySecure.to((url) -> url + "?ticket=" + ptCache.get(url)).assertAt();
}
@Test
public void securePageWhenInvalidTicketThenFails() {
this.login.to(this::serviceParam).assertAt().login("scott");
this.secure.to(url -> url + "?ticket=invalid");
this.secure.to((url) -> url + "?ticket=invalid");
this.unauthorized.assertAt();
}

View File

@@ -66,19 +66,19 @@ public class ContactsPage {
}
Predicate<WebElement> byEmail(final String val) {
return e -> e.findElements(By.xpath("td[position()=3 and normalize-space()='" + val + "']")).size() == 1;
return (e) -> e.findElements(By.xpath("td[position()=3 and normalize-space()='" + val + "']")).size() == 1;
}
Predicate<WebElement> byName(final String val) {
return e -> e.findElements(By.xpath("td[position()=2 and normalize-space()='" + val + "']")).size() == 1;
return (e) -> e.findElements(By.xpath("td[position()=2 and normalize-space()='" + val + "']")).size() == 1;
}
public DeleteContactLink andHasContact(final String name, final String email) {
return this.contacts.stream()
.filter(byEmail(email).and(byName(name)))
.map(e -> e.findElement(By.cssSelector("td:nth-child(4) > a")))
.map((e) -> e.findElement(By.cssSelector("td:nth-child(4) > a")))
.findFirst()
.map(e -> new DeleteContactLink(webDriver, e))
.map((e) -> new DeleteContactLink(webDriver, e))
.get();
}

View File

@@ -33,7 +33,7 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
public void create(final Contact contact) {
getJdbcTemplate().update("insert into contacts values (?, ?, ?)",
ps -> {
(ps) -> {
ps.setLong(1, contact.getId());
ps.setString(2, contact.getName());
ps.setString(3, contact.getEmail());
@@ -42,13 +42,13 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
public void delete(final Long contactId) {
getJdbcTemplate().update("delete from contacts where id = ?",
ps -> ps.setLong(1, contactId));
(ps) -> ps.setLong(1, contactId));
}
public void update(final Contact contact) {
getJdbcTemplate().update(
"update contacts set contact_name = ?, address = ? where id = ?",
ps -> {
(ps) -> {
ps.setString(1, contact.getName());
ps.setString(2, contact.getEmail());
ps.setLong(3, contact.getId());

View File

@@ -162,7 +162,7 @@ public class DataSourcePopulator implements InitializingBean {
for (int i = 1; i < createEntities; i++) {
final ObjectIdentity objectIdentity = new ObjectIdentityImpl(Contact.class,
(long) i);
tt.execute(arg0 -> {
tt.execute((arg0) -> {
mutableAclService.createAcl(objectIdentity);
return null;
@@ -267,7 +267,7 @@ public class DataSourcePopulator implements InitializingBean {
}
private void updateAclInTransaction(final MutableAcl acl) {
tt.execute(arg0 -> {
tt.execute((arg0) -> {
mutableAclService.updateAcl(acl);
return null;