Java 8: Statement lambda can be replaced with expression lambda

This commit is contained in:
Lars Grefer 2019-08-09 00:53:15 +02:00 committed by Rob Winch
parent 7b2a7847e5
commit 38de737663
7 changed files with 18 additions and 32 deletions

View File

@ -1184,9 +1184,7 @@ public class ServerHttpSecurity {
return Collections.emptyMap();
}
Map<String, String> result = new HashMap<>();
registrations.iterator().forEachRemaining(r -> {
result.put("/oauth2/authorization/" + r.getRegistrationId(), r.getClientName());
});
registrations.iterator().forEachRemaining(r -> result.put("/oauth2/authorization/" + r.getRegistrationId(), r.getClientName()));
return result;
}

View File

@ -117,16 +117,14 @@ public class DefaultReactiveOAuth2UserService implements ReactiveOAuth2UserServi
}
Mono<Map<String, Object>> userAttributes = requestHeadersSpec
.retrieve()
.onStatus(s -> s != HttpStatus.OK, response -> {
return parse(response).map(userInfoErrorResponse -> {
String description = userInfoErrorResponse.getErrorObject().getDescription();
OAuth2Error oauth2Error = new OAuth2Error(
INVALID_USER_INFO_RESPONSE_ERROR_CODE, description,
null);
throw new OAuth2AuthenticationException(oauth2Error,
oauth2Error.toString());
});
})
.onStatus(s -> s != HttpStatus.OK, response -> parse(response).map(userInfoErrorResponse -> {
String description = userInfoErrorResponse.getErrorObject().getDescription();
OAuth2Error oauth2Error = new OAuth2Error(
INVALID_USER_INFO_RESPONSE_ERROR_CODE, description,
null);
throw new OAuth2AuthenticationException(oauth2Error,
oauth2Error.toString());
}))
.bodyToMono(typeReference);
return userAttributes.map(attrs -> {

View File

@ -255,12 +255,10 @@ public final class ServletOAuth2AuthorizedClientExchangeFilterFunction
* @return the {@link Consumer} to populate the attributes
*/
public Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest() {
return spec -> {
spec.attributes(attrs -> {
populateDefaultRequestResponse(attrs);
populateDefaultAuthentication(attrs);
});
};
return spec -> spec.attributes(attrs -> {
populateDefaultRequestResponse(attrs);
populateDefaultAuthentication(attrs);
});
}
/**

View File

@ -114,10 +114,8 @@ public class OAuth2AuthorizationRequestRedirectWebFilter implements WebFilter {
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
return this.authorizationRequestResolver.resolve(exchange)
.switchIfEmpty(chain.filter(exchange).then(Mono.empty()))
.onErrorResume(ClientAuthorizationRequiredException.class, e -> {
return this.requestCache.saveRequest(exchange)
.then(this.authorizationRequestResolver.resolve(exchange, e.getClientRegistrationId()));
})
.onErrorResume(ClientAuthorizationRequiredException.class, e -> this.requestCache.saveRequest(exchange)
.then(this.authorizationRequestResolver.resolve(exchange, e.getClientRegistrationId())))
.flatMap(clientRegistration -> sendRedirectForAuthorization(exchange, clientRegistration));
}

View File

@ -69,9 +69,7 @@ public class UnAuthenticatedServerOAuth2AuthorizedClientRepository implements Se
Assert.notNull(clientRegistrationId, "clientRegistrationId cannot be null");
Assert.isNull(serverWebExchange, "serverWebExchange " + serverWebExchange + "must be null");
Assert.isTrue(isUnauthenticated(authentication), "The user " + authentication + " should not be authenticated");
return Mono.fromRunnable(() -> {
this.clientRegistrationIdToAuthorizedClient.remove(clientRegistrationId);
});
return Mono.fromRunnable(() -> this.clientRegistrationIdToAuthorizedClient.remove(clientRegistrationId));
}
private boolean isUnauthenticated(Authentication authentication) {

View File

@ -67,9 +67,7 @@ public class SecurityMockServerConfigurers {
public static MockServerConfigurer springSecurity() {
return new MockServerConfigurer() {
public void beforeServerCreated(WebHttpHandlerBuilder builder) {
builder.filters( filters -> {
filters.add(0, new MutatorFilter());
});
builder.filters( filters -> filters.add(0, new MutatorFilter()));
}
};
}

View File

@ -62,9 +62,7 @@ public final class CookieClearingLogoutHandler implements LogoutHandler {
List<Function<HttpServletRequest, Cookie>> cookieList = new ArrayList<>();
for (Cookie cookie : cookiesToClear) {
Assert.isTrue(cookie.getMaxAge() == 0, "Cookie maxAge must be 0");
Function<HttpServletRequest, Cookie> f = (request) -> {
return cookie;
};
Function<HttpServletRequest, Cookie> f = (request) -> cookie;
cookieList.add(f);
}
this.cookiesToClear = cookieList;