-
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.
- Spring Security application tok중n filter 작업
- Loading branch information
Showing
5 changed files
with
108 additions
and
2 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
27 changes: 27 additions & 0 deletions
27
...er/src/main/java/com/cjw/chatting/config/security/SimpleChattingAuthenticationFilter.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,27 @@ | ||
package com.cjw.chatting.config.security; | ||
|
||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* 발급한 JwtToken 검증 | ||
*/ | ||
public class SimpleChattingAuthenticationFilter extends AbstractAuthenticationProcessingFilter { | ||
protected SimpleChattingAuthenticationFilter(String defaultFilterProcessesUrl) { | ||
super(defaultFilterProcessesUrl); | ||
} | ||
|
||
@Override | ||
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { | ||
//헤더에서 Token 받아오겄지 | ||
String authorization = request.getHeader("Authorization"); | ||
//토큰으로 provider 결정 | ||
return this.getAuthenticationManager().authenticate(new SimpleChattingAuthenticationToken(authorization)); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../src/main/java/com/cjw/chatting/config/security/SimpleChattingAuthenticationProvider.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,23 @@ | ||
package com.cjw.chatting.config.security; | ||
|
||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.authentication.AuthenticationProvider; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class SimpleChattingAuthenticationProvider implements AuthenticationProvider { | ||
@Override | ||
public Authentication authenticate(Authentication authentication) throws AuthenticationException { | ||
//받은 토큰 Expire 검증 후 인증 여부 결정 | ||
return new SimpleChattingAuthenticationToken(null, null, null); | ||
} | ||
|
||
@Override | ||
public boolean supports(Class<?> authentication) { | ||
return (SimpleChattingAuthenticationToken.class.isAssignableFrom(authentication)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ver/src/main/java/com/cjw/chatting/config/security/SimpleChattingAuthenticationToken.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,33 @@ | ||
package com.cjw.chatting.config.security; | ||
|
||
import org.springframework.security.authentication.AbstractAuthenticationToken; | ||
import org.springframework.security.core.GrantedAuthority; | ||
|
||
import java.util.Collection; | ||
|
||
public class SimpleChattingAuthenticationToken extends AbstractAuthenticationToken { | ||
private final Object credential; | ||
private Object principal; | ||
|
||
public SimpleChattingAuthenticationToken(String accessToken) { | ||
super(null); | ||
this.credential = accessToken; | ||
this.setAuthenticated(false); | ||
} | ||
public SimpleChattingAuthenticationToken(Collection<? extends GrantedAuthority> authorities, Object principal, String accessToken) { | ||
super(authorities); | ||
this.principal = principal; | ||
this.credential = accessToken; | ||
this.setAuthenticated(true); | ||
} | ||
|
||
@Override | ||
public Object getCredentials() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object getPrincipal() { | ||
return null; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
chatting-stream-server/src/main/java/com/cjw/chatting/controller/api/TestController.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,13 @@ | ||
package com.cjw.chatting.controller.api; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class TestController { | ||
|
||
@GetMapping("/test") | ||
public String test() { | ||
return "test"; | ||
} | ||
} |