-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
118 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/mafia/mafiatogether/common/resolver/WebsocketPlayerArgumentResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package mafia.mafiatogether.chat.ui; | ||
|
||
import mafia.mafiatogether.common.annotation.PlayerInfo; | ||
import mafia.mafiatogether.common.exception.AuthException; | ||
import mafia.mafiatogether.common.exception.ExceptionCode; | ||
import mafia.mafiatogether.common.resolver.PlayerInfoDto; | ||
import mafia.mafiatogether.common.util.AuthExtractor; | ||
import org.springframework.core.MethodParameter; | ||
import org.springframework.messaging.Message; | ||
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; | ||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; | ||
|
||
public class WebsocketPlayerArgumentResolver implements HandlerMethodArgumentResolver { | ||
@Override | ||
public boolean supportsParameter(final MethodParameter parameter) { | ||
return parameter.hasParameterAnnotation(PlayerInfo.class); | ||
} | ||
|
||
@Override | ||
public Object resolveArgument(final MethodParameter parameter, final Message<?> message) throws Exception { | ||
SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.wrap(message); | ||
String authorization = headerAccessor.getFirstNativeHeader("Authorization"); | ||
if (authorization == null) { | ||
throw new AuthException(ExceptionCode.MISSING_AUTHENTICATION_HEADER); | ||
} | ||
if (!authorization.startsWith("Basic")) { | ||
throw new AuthException(ExceptionCode.MISSING_AUTHENTICATION_HEADER); | ||
} | ||
|
||
String[] information = AuthExtractor.extractByAuthorization(authorization); | ||
|
||
return new PlayerInfoDto(information[0], information[1]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters