Search in sources :

Example 1 with JwtUser

use of no.arkivlab.hioa.nikita.webapp.security.JwtUser in project nikita-noark5-core by HiOA-ABI.

the class AuthenticationRestController method refreshAndGetAuthenticationToken.

@RequestMapping(value = "${jwt.route.authentication.refresh}", method = RequestMethod.GET)
public ResponseEntity<?> refreshAndGetAuthenticationToken(HttpServletRequest request) {
    String token = request.getHeader(tokenHeader);
    String username = jwtTokenUtil.getUsernameFromToken(token);
    JwtUser user = (JwtUser) userDetailsService.loadUserByUsername(username);
    if (jwtTokenUtil.canTokenBeRefreshed(token, user.getLastPasswordResetDate())) {
        String refreshedToken = jwtTokenUtil.refreshToken(token);
        return ResponseEntity.ok(new JwtAuthenticationResponse(refreshedToken));
    } else {
        return ResponseEntity.badRequest().body(null);
    }
}
Also used : JwtUser(no.arkivlab.hioa.nikita.webapp.security.JwtUser) JwtAuthenticationResponse(no.arkivlab.hioa.nikita.webapp.security.service.JwtAuthenticationResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JwtUser (no.arkivlab.hioa.nikita.webapp.security.JwtUser)1 JwtAuthenticationResponse (no.arkivlab.hioa.nikita.webapp.security.service.JwtAuthenticationResponse)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1