001/*******************************************************************************
002 * Copyright 2018 The MIT Internet Trust Consortium
003 *
004 * Portions copyright 2011-2013 The MITRE Corporation
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 *******************************************************************************/
018package org.mitre.oauth2.repository;
019
020import java.util.List;
021import java.util.Set;
022
023import org.mitre.data.PageCriteria;
024import org.mitre.oauth2.model.ClientDetailsEntity;
025import org.mitre.oauth2.model.OAuth2AccessTokenEntity;
026import org.mitre.oauth2.model.OAuth2RefreshTokenEntity;
027import org.mitre.openid.connect.model.ApprovedSite;
028import org.mitre.uma.model.ResourceSet;
029
030public interface OAuth2TokenRepository {
031
032        public OAuth2AccessTokenEntity saveAccessToken(OAuth2AccessTokenEntity token);
033
034        public OAuth2RefreshTokenEntity getRefreshTokenByValue(String refreshTokenValue);
035
036        public OAuth2RefreshTokenEntity getRefreshTokenById(Long Id);
037
038        public void clearAccessTokensForRefreshToken(OAuth2RefreshTokenEntity refreshToken);
039
040        public void removeRefreshToken(OAuth2RefreshTokenEntity refreshToken);
041
042        public OAuth2RefreshTokenEntity saveRefreshToken(OAuth2RefreshTokenEntity refreshToken);
043
044        public OAuth2AccessTokenEntity getAccessTokenByValue(String accessTokenValue);
045
046        public OAuth2AccessTokenEntity getAccessTokenById(Long id);
047
048        public void removeAccessToken(OAuth2AccessTokenEntity accessToken);
049
050        public void clearTokensForClient(ClientDetailsEntity client);
051
052        public List<OAuth2AccessTokenEntity> getAccessTokensForClient(ClientDetailsEntity client);
053
054        public List<OAuth2RefreshTokenEntity> getRefreshTokensForClient(ClientDetailsEntity client);
055        
056        public Set<OAuth2AccessTokenEntity> getAccessTokensByUserName(String name);
057        
058        public Set<OAuth2RefreshTokenEntity> getRefreshTokensByUserName(String name);
059
060        public Set<OAuth2AccessTokenEntity> getAllAccessTokens();
061
062        public Set<OAuth2RefreshTokenEntity> getAllRefreshTokens();
063
064        public Set<OAuth2AccessTokenEntity> getAllExpiredAccessTokens();
065
066        public Set<OAuth2AccessTokenEntity> getAllExpiredAccessTokens(PageCriteria pageCriteria);
067
068        public Set<OAuth2RefreshTokenEntity> getAllExpiredRefreshTokens();
069
070        public Set<OAuth2RefreshTokenEntity> getAllExpiredRefreshTokens(PageCriteria pageCriteria);
071
072        public Set<OAuth2AccessTokenEntity> getAccessTokensForResourceSet(ResourceSet rs);
073
074        /**
075         * removes duplicate access tokens.
076         *
077         * @deprecated this method was added to return the remove duplicate access tokens values
078         * so that {code removeAccessToken(OAuth2AccessTokenEntity o)} would not to fail. the
079         * removeAccessToken method has been updated so as it will not fail in the event that an
080         * accessToken has been duplicated, so this method is unnecessary.
081         *
082         */
083        @Deprecated
084        public void clearDuplicateAccessTokens();
085
086        /**
087         * removes duplicate refresh tokens.
088         *
089         * @deprecated this method was added to return the remove duplicate refresh token value
090         * so that {code removeRefreshToken(OAuth2RefreshTokenEntity o)} would not to fail. the
091         * removeRefreshToken method has been updated so as it will not fail in the event that
092         * refreshToken has been duplicated, so this method is unnecessary.
093         *
094         */
095        @Deprecated
096        public void clearDuplicateRefreshTokens();
097
098        public List<OAuth2AccessTokenEntity> getAccessTokensForApprovedSite(ApprovedSite approvedSite);
099
100}