Skip to content

Package: AccessTokenDAO

AccessTokenDAO

nameinstructionbranchcomplexitylinemethod
AccessTokenDAO()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
count(EntityManager, KapuaQuery)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
create(EntityManager, AccessTokenCreator)
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
delete(EntityManager, KapuaId, KapuaId)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
find(EntityManager, KapuaId, KapuaId)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
findByTokenId(EntityManager, String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
query(EntityManager, KapuaQuery)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
update(EntityManager, AccessToken)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.authentication.token.shiro;
14:
15: import org.eclipse.kapua.KapuaEntityNotFoundException;
16: import org.eclipse.kapua.KapuaException;
17: import org.eclipse.kapua.commons.jpa.EntityManager;
18: import org.eclipse.kapua.commons.service.internal.ServiceDAO;
19: import org.eclipse.kapua.model.id.KapuaId;
20: import org.eclipse.kapua.model.query.KapuaQuery;
21: import org.eclipse.kapua.service.authentication.token.AccessToken;
22: import org.eclipse.kapua.service.authentication.token.AccessTokenAttributes;
23: import org.eclipse.kapua.service.authentication.token.AccessTokenCreator;
24: import org.eclipse.kapua.service.authentication.token.AccessTokenListResult;
25:
26: /**
27: * {@link AccessToken} {@link ServiceDAO}.
28: *
29: * @since 1.0
30: */
31: public class AccessTokenDAO extends ServiceDAO {
32:
33: /**
34: * Creates and return new access token
35: *
36: * @param em
37: * @param accessTokenCreator
38: * @return
39: * @throws KapuaException
40: */
41: public static AccessToken create(EntityManager em, AccessTokenCreator accessTokenCreator)
42: throws KapuaException {
43: //
44: // Create User
45: AccessTokenImpl accessTokenImpl = new AccessTokenImpl(accessTokenCreator.getScopeId(),
46: accessTokenCreator.getUserId(),
47: accessTokenCreator.getTokenId(),
48: accessTokenCreator.getExpiresOn(),
49: accessTokenCreator.getRefreshToken(),
50: accessTokenCreator.getRefreshExpiresOn());
51:
52: return ServiceDAO.create(em, accessTokenImpl);
53: }
54:
55: /**
56: * Update the provided access token
57: *
58: * @param em
59: * @param accessToken
60: * @return
61: * @throws KapuaException
62: */
63: public static AccessToken update(EntityManager em, AccessToken accessToken)
64: throws KapuaException {
65: //
66: // Update user
67: AccessTokenImpl accessTokenImpl = (AccessTokenImpl) accessToken;
68:
69: return ServiceDAO.update(em, AccessTokenImpl.class, accessTokenImpl);
70: }
71:
72: /**
73: * Find the access token by access token identifier
74: *
75: * @param em
76: * @param scopeId
77: * @param accessTokenId
78: * @return
79: */
80: public static AccessToken find(EntityManager em, KapuaId scopeId, KapuaId accessTokenId) {
81: return ServiceDAO.find(em, AccessTokenImpl.class, scopeId, accessTokenId);
82: }
83:
84: /**
85: * Find the access token by the token string id
86: *
87: * @param em
88: * @param tokenId
89: * @return
90: */
91: public static AccessToken findByTokenId(EntityManager em, String tokenId) {
92: return ServiceDAO.findByField(em, AccessTokenImpl.class, AccessTokenAttributes.TOKEN_ID, tokenId);
93: }
94:
95: /**
96: * Return the access token list matching the provided query
97: *
98: * @param em
99: * @param accessTokenQuery
100: * @return
101: * @throws KapuaException
102: */
103: public static AccessTokenListResult query(EntityManager em, KapuaQuery accessTokenQuery)
104: throws KapuaException {
105: return ServiceDAO.query(em, AccessToken.class, AccessTokenImpl.class, new AccessTokenListResultImpl(), accessTokenQuery);
106: }
107:
108: /**
109: * Return the access token count matching the provided query
110: *
111: * @param em
112: * @param accessTokenQuery
113: * @return
114: * @throws KapuaException
115: */
116: public static long count(EntityManager em, KapuaQuery accessTokenQuery)
117: throws KapuaException {
118: return ServiceDAO.count(em, AccessToken.class, AccessTokenImpl.class, accessTokenQuery);
119: }
120:
121: /**
122: * Delete the accessToken by access token identifier
123: *
124: * @param em
125: * @param scopeId
126: * @param accessTokenId
127: * @return deleted entity
128: * @throws KapuaEntityNotFoundException If {@link AccessToken} is not found.
129: */
130: public static AccessToken delete(EntityManager em, KapuaId scopeId, KapuaId accessTokenId) throws KapuaEntityNotFoundException {
131: return ServiceDAO.delete(em, AccessTokenImpl.class, scopeId, accessTokenId);
132: }
133: }