All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.foodtechlab.lib.auth.service.domain.token.usecases.ExpireRefreshTokenByTimeUseCase Maven / Gradle / Ivy

There is a newer version: 4.1.0
Show newest version
package ru.foodtechlab.lib.auth.service.domain.token.usecases;

import com.rcore.domain.commons.usecase.UseCase;
import com.rcore.domain.commons.usecase.model.IdInputValues;
import com.rcore.domain.commons.usecase.model.SingletonEntityOutputValues;
import lombok.RequiredArgsConstructor;
import ru.foodtechlab.lib.auth.service.domain.token.entity.RefreshTokenEntity;
import ru.foodtechlab.lib.auth.service.domain.token.exception.RefreshTokenNotFoundException;
import ru.foodtechlab.lib.auth.service.domain.token.port.RefreshTokenRepository;

import java.time.Instant;

@RequiredArgsConstructor
public class ExpireRefreshTokenByTimeUseCase extends UseCase, SingletonEntityOutputValues> {

    private final RefreshTokenRepository refreshTokenRepository;
    private final DeactivateAccessTokensByRefreshToken deactivateAccessTokensByRefreshToken;

    @Override
    public SingletonEntityOutputValues execute(IdInputValues inputValues) {

        RefreshTokenEntity refreshTokenEntity = refreshTokenRepository.findById(inputValues.getId())
                .orElseThrow(() -> new RefreshTokenNotFoundException(inputValues.getId()));

        refreshTokenEntity.setExpireAt(Instant.now());
        deactivateAccessTokensByRefreshToken.execute(DeactivateAccessTokensByRefreshToken.InputValues.of(refreshTokenEntity));

        return SingletonEntityOutputValues.of(refreshTokenRepository.save(refreshTokenEntity));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy