Browse Source

Polishing

pull/23931/head
Rossen Stoyanchev 5 years ago
parent
commit
739d2881fa
  1. 10
      spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/PrincipalMethodArgumentResolver.java

10
spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/PrincipalMethodArgumentResolver.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,7 +25,7 @@ import org.springframework.messaging.handler.invocation.HandlerMethodArgumentRes
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
/** /**
* {@link HandlerMethodArgumentResolver} to a {@link Principal} or {@link Optional} of {@link Principal}. * Resolver for arguments of type {@link Principal}, including {@code Optional<Principal>}.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.0 * @since 4.0
@ -42,11 +42,7 @@ public class PrincipalMethodArgumentResolver implements HandlerMethodArgumentRes
@Override @Override
public Object resolveArgument(MethodParameter parameter, Message<?> message){ public Object resolveArgument(MethodParameter parameter, Message<?> message){
Principal user = SimpMessageHeaderAccessor.getUser(message.getHeaders()); Principal user = SimpMessageHeaderAccessor.getUser(message.getHeaders());
if (parameter.isOptional()) { return parameter.isOptional() ? Optional.ofNullable(user) : user;
return Optional.ofNullable(user);
} else {
return user;
}
} }
} }

Loading…
Cancel
Save