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

pl.edu.icm.unity.oauth.as.token.access.OAuthClientTokensCleaner Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2021 Bixbit - Krzysztof Benedyczak. All rights reserved.
 * See LICENCE.txt file for licensing information.
 */

package pl.edu.icm.unity.oauth.as.token.access;

import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;

import pl.edu.icm.unity.base.exceptions.EngineException;
import pl.edu.icm.unity.base.utils.Log;

@Component
public class OAuthClientTokensCleaner
{
	private static final Logger log = Log.getLogger(Log.U_SERVER_OAUTH, OAuthRefreshTokenExpirationListener.class);

	private final OAuthAccessTokenRepository accessTokenRepository;
	private final OAuthRefreshTokenRepository refreshTokenRepository;

	public OAuthClientTokensCleaner(OAuthAccessTokenRepository accessTokenRepository,
			OAuthRefreshTokenRepository refreshTokenRepository)
	{
		this.accessTokenRepository = accessTokenRepository;
		this.refreshTokenRepository = refreshTokenRepository;
	}

	public void removeTokensForClient(long clientId, long userId, String rollingTokenId)
	{

		try
		{
			accessTokenRepository.removeOwnedByClient(clientId, userId);
		} catch (EngineException e)
		{
			log.error("Can not remove access tokens for client {}", clientId);
		}

		try
		{
			refreshTokenRepository.clearHistoryForClient(rollingTokenId, clientId, userId);
		} catch (EngineException e)
		{
			log.error("Can not remove refresh token history for client {}", clientId);

		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy