Search in sources :

Example 1 with UserDetailsImpl

use of com.tistory.heowc.auth.UserDetailsImpl in project SpringBootSample by heowc.

the class RefreshController method refreshToken.

@GetMapping
public ResponseEntity<String> refreshToken(Authentication authentication) {
    UserDetails userDetails = new UserDetailsImpl(authentication.getPrincipal().toString(), new ArrayList<>(authentication.getAuthorities()));
    String token = JwtUtil.refreshToken(userDetails);
    HttpHeaders headers = new HttpHeaders();
    headers.add(JwtInfo.HEADER_NAME, token);
    return ResponseEntity.status(HttpStatus.OK).headers(headers).build();
}
Also used : UserDetailsImpl(com.tistory.heowc.auth.UserDetailsImpl) HttpHeaders(org.springframework.http.HttpHeaders) UserDetails(org.springframework.security.core.userdetails.UserDetails) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with UserDetailsImpl

use of com.tistory.heowc.auth.UserDetailsImpl in project SpringBootSample by heowc.

the class JwtUserDetailsService method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String token) {
    DecodedJWT decodedJWT = JwtUtil.tokenToJwt(token);
    if (decodedJWT == null) {
        throw new BadCredentialsException("Not used Token");
    }
    String id = decodedJWT.getClaim("id").asString();
    String role = decodedJWT.getClaim("role").asString();
    return new UserDetailsImpl(id, AuthorityUtils.createAuthorityList(role));
}
Also used : UserDetailsImpl(com.tistory.heowc.auth.UserDetailsImpl) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT)

Aggregations

UserDetailsImpl (com.tistory.heowc.auth.UserDetailsImpl)2 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)1 HttpHeaders (org.springframework.http.HttpHeaders)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1