Search in sources :

Example 1 with JwtResponseDTO

use of com.ncedu.fooddelivery.api.v1.dto.jwt.JwtResponseDTO in project 2021-msk-food-delivery by netcracker-edu.

the class AuthServiceImpl method signIn.

@Override
public JwtResponseDTO signIn(JwtRequestDTO authInfo, String userAgent) {
    Authentication auth = authenticate(authInfo.getLogin(), authInfo.getPassword());
    // User implements UserDetails
    User user = (User) auth.getPrincipal();
    userService.setLastSigninFromNow(user);
    log.debug("USER: " + user.getUsername() + user.getLastSigninDate());
    final String accessToken = jwtUtil.createToken(user);
    final String refreshToken = userRefreshTokenService.createRefreshToken(user, userAgent);
    return new JwtResponseDTO(accessToken, refreshToken, createUserDTO(user));
}
Also used : Authentication(org.springframework.security.core.Authentication) JwtResponseDTO(com.ncedu.fooddelivery.api.v1.dto.jwt.JwtResponseDTO)

Example 2 with JwtResponseDTO

use of com.ncedu.fooddelivery.api.v1.dto.jwt.JwtResponseDTO in project 2021-msk-food-delivery by netcracker-edu.

the class AuthServiceImpl method refresh.

@Override
public JwtResponseDTO refresh(RefreshTokenDTO refreshTokenDTO, String authHeader) {
    UUID refreshToken = UUID.fromString(refreshTokenDTO.getRefreshToken());
    UserRefreshToken urt = userRefreshTokenService.getTokenById(refreshToken);
    // change lastSignin on owner of token
    userService.setLastSigninFromNow(urt.getOwner());
    final String accessToken = jwtUtil.createToken(urt.getOwner());
    return new JwtResponseDTO(accessToken, refreshToken.toString(), createUserDTO(urt.getOwner()));
}
Also used : UUID(java.util.UUID) JwtResponseDTO(com.ncedu.fooddelivery.api.v1.dto.jwt.JwtResponseDTO)

Aggregations

JwtResponseDTO (com.ncedu.fooddelivery.api.v1.dto.jwt.JwtResponseDTO)2 UUID (java.util.UUID)1 Authentication (org.springframework.security.core.Authentication)1