Polish spring-security-rsocket main code
Manually polish `spring-security-rsocket` following the formatting and checkstyle fixes. Issue gh-8945
This commit is contained in:
parent
16819be437
commit
e8094b8cf2
|
@ -39,11 +39,11 @@ import org.springframework.util.Assert;
|
|||
*/
|
||||
public class AnonymousPayloadInterceptor implements PayloadInterceptor, Ordered {
|
||||
|
||||
private String key;
|
||||
private final String key;
|
||||
|
||||
private Object principal;
|
||||
private final Object principal;
|
||||
|
||||
private List<GrantedAuthority> authorities;
|
||||
private final List<GrantedAuthority> authorities;
|
||||
|
||||
private int order;
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public class AuthenticationPayloadExchangeConverter implements PayloadExchangeAu
|
|||
private static final MimeType AUTHENTICATION_MIME_TYPE = MimeTypeUtils
|
||||
.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION.getString());
|
||||
|
||||
private MetadataExtractor metadataExtractor = createDefaultExtractor();
|
||||
private final MetadataExtractor metadataExtractor = createDefaultExtractor();
|
||||
|
||||
@Override
|
||||
public Mono<Authentication> convert(PayloadExchange exchange) {
|
||||
|
@ -79,7 +79,7 @@ public class AuthenticationPayloadExchangeConverter implements PayloadExchangeAu
|
|||
if (WellKnownAuthType.SIMPLE.equals(wellKnownAuthType)) {
|
||||
return simple(rawAuthentication);
|
||||
}
|
||||
else if (WellKnownAuthType.BEARER.equals(wellKnownAuthType)) {
|
||||
if (WellKnownAuthType.BEARER.equals(wellKnownAuthType)) {
|
||||
return bearer(rawAuthentication);
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown Mime Type " + wellKnownAuthType);
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.springframework.security.core.Authentication;
|
|||
import org.springframework.security.rsocket.api.PayloadExchange;
|
||||
import org.springframework.security.rsocket.util.matcher.PayloadExchangeAuthorizationContext;
|
||||
import org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcher;
|
||||
import org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcher.MatchResult;
|
||||
import org.springframework.security.rsocket.util.matcher.PayloadExchangeMatcherEntry;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
@ -53,7 +54,7 @@ public final class PayloadExchangeMatcherReactiveAuthorizationManager
|
|||
public Mono<AuthorizationDecision> check(Mono<Authentication> authentication, PayloadExchange exchange) {
|
||||
return Flux.fromIterable(this.mappings)
|
||||
.concatMap((mapping) -> mapping.getMatcher().matches(exchange)
|
||||
.filter(PayloadExchangeMatcher.MatchResult::isMatch).map((r) -> r.getVariables())
|
||||
.filter(PayloadExchangeMatcher.MatchResult::isMatch).map(MatchResult::getVariables)
|
||||
.flatMap((variables) -> mapping.getEntry().check(authentication,
|
||||
new PayloadExchangeAuthorizationContext(exchange, variables))))
|
||||
.next().switchIfEmpty(Mono.fromCallable(() -> new AuthorizationDecision(false)));
|
||||
|
|
|
@ -66,10 +66,8 @@ class PayloadSocketAcceptor implements SocketAcceptor {
|
|||
public Mono<RSocket> accept(ConnectionSetupPayload setup, RSocket sendingSocket) {
|
||||
MimeType dataMimeType = parseMimeType(setup.dataMimeType(), this.defaultDataMimeType);
|
||||
Assert.notNull(dataMimeType, "No `dataMimeType` in ConnectionSetupPayload and no default value");
|
||||
|
||||
MimeType metadataMimeType = parseMimeType(setup.metadataMimeType(), this.defaultMetadataMimeType);
|
||||
Assert.notNull(metadataMimeType, "No `metadataMimeType` in ConnectionSetupPayload and no default value");
|
||||
|
||||
// FIXME do we want to make the sendingSocket available in the PayloadExchange
|
||||
return intercept(setup, dataMimeType, metadataMimeType)
|
||||
.flatMap(
|
||||
|
|
|
@ -48,7 +48,6 @@ public class BasicAuthenticationDecoder extends AbstractDecoder<UsernamePassword
|
|||
return Flux.from(input).map(DataBuffer::asByteBuffer).map((byteBuffer) -> {
|
||||
byte[] sizeBytes = new byte[4];
|
||||
byteBuffer.get(sizeBytes);
|
||||
|
||||
int usernameSize = 4;
|
||||
byte[] usernameBytes = new byte[usernameSize];
|
||||
byteBuffer.get(usernameBytes);
|
||||
|
|
|
@ -24,37 +24,43 @@ import org.springframework.security.rsocket.api.PayloadExchangeType;
|
|||
/**
|
||||
* @author Rob Winch
|
||||
*/
|
||||
public abstract class PayloadExchangeMatchers {
|
||||
public final class PayloadExchangeMatchers {
|
||||
|
||||
private PayloadExchangeMatchers() {
|
||||
}
|
||||
|
||||
public static PayloadExchangeMatcher setup() {
|
||||
return new PayloadExchangeMatcher() {
|
||||
|
||||
@Override
|
||||
public Mono<MatchResult> matches(PayloadExchange exchange) {
|
||||
return PayloadExchangeType.SETUP.equals(exchange.getType()) ? MatchResult.match()
|
||||
: MatchResult.notMatch();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public static PayloadExchangeMatcher anyRequest() {
|
||||
return new PayloadExchangeMatcher() {
|
||||
|
||||
@Override
|
||||
public Mono<MatchResult> matches(PayloadExchange exchange) {
|
||||
return exchange.getType().isRequest() ? MatchResult.match() : MatchResult.notMatch();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public static PayloadExchangeMatcher anyExchange() {
|
||||
return new PayloadExchangeMatcher() {
|
||||
|
||||
@Override
|
||||
public Mono<MatchResult> matches(PayloadExchange exchange) {
|
||||
return MatchResult.match();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
private PayloadExchangeMatchers() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,10 +26,9 @@ import org.springframework.security.rsocket.api.PayloadExchange;
|
|||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.RouteMatcher;
|
||||
|
||||
// FIXME: Pay attention to the package this goes into. It requires spring-messaging for the MetadataExtractor.
|
||||
|
||||
/**
|
||||
* FIXME: Pay attention to the package this goes into. It requires spring-messaging for
|
||||
* the MetadataExtractor.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @since 5.2
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue