| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 1 | package de.ids_mannheim.korap.web.controller; |
| 2 | |
| margaretha | d484156 | 2022-06-01 12:24:47 +0200 | [diff] [blame] | 3 | import java.io.IOException; |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 4 | import java.net.URI; |
| margaretha | ca5472a | 2023-09-22 18:00:03 +0200 | [diff] [blame] | 5 | import java.time.ZoneId; |
| 6 | import java.time.ZonedDateTime; |
| 7 | import java.util.HashSet; |
| 8 | import java.util.Set; |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 9 | |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 10 | import org.apache.http.entity.ContentType; |
| margaretha | cc92959 | 2023-01-31 11:07:35 +0100 | [diff] [blame] | 11 | import org.glassfish.jersey.client.ClientConfig; |
| 12 | import org.glassfish.jersey.client.ClientProperties; |
| margaretha | b22a585 | 2023-01-27 14:43:36 +0100 | [diff] [blame] | 13 | import org.glassfish.jersey.uri.UriComponent; |
| margaretha | 93e602e | 2019-08-07 15:19:56 +0200 | [diff] [blame] | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 15 | import org.springframework.util.MultiValueMap; |
| 16 | import org.springframework.web.util.UriComponentsBuilder; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.google.common.net.HttpHeaders; |
| margaretha | b38e630 | 2023-10-26 12:33:26 +0200 | [diff] [blame^] | 20 | import com.nimbusds.oauth2.sdk.GrantType; |
| margaretha | 5f5d3ed | 2023-08-30 23:48:52 +0200 | [diff] [blame] | 21 | import com.nimbusds.oauth2.sdk.OAuth2Error; |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 22 | |
| 23 | import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler; |
| 24 | import de.ids_mannheim.korap.config.Attributes; |
| 25 | import de.ids_mannheim.korap.config.SpringJerseyTest; |
| margaretha | ca5472a | 2023-09-22 18:00:03 +0200 | [diff] [blame] | 26 | import de.ids_mannheim.korap.constant.OAuth2Scope; |
| 27 | import de.ids_mannheim.korap.encryption.RandomCodeGenerator; |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 28 | import de.ids_mannheim.korap.exceptions.KustvaktException; |
| margaretha | d484156 | 2022-06-01 12:24:47 +0200 | [diff] [blame] | 29 | import de.ids_mannheim.korap.exceptions.StatusCodes; |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 30 | import de.ids_mannheim.korap.oauth2.constant.OAuth2ClientType; |
| margaretha | ca5472a | 2023-09-22 18:00:03 +0200 | [diff] [blame] | 31 | import de.ids_mannheim.korap.oauth2.dao.AccessTokenDao; |
| 32 | import de.ids_mannheim.korap.oauth2.dao.OAuth2ClientDao; |
| margaretha | 93e602e | 2019-08-07 15:19:56 +0200 | [diff] [blame] | 33 | import de.ids_mannheim.korap.oauth2.dao.RefreshTokenDao; |
| margaretha | ca5472a | 2023-09-22 18:00:03 +0200 | [diff] [blame] | 34 | import de.ids_mannheim.korap.oauth2.entity.AccessScope; |
| 35 | import de.ids_mannheim.korap.oauth2.entity.AccessToken; |
| 36 | import de.ids_mannheim.korap.oauth2.entity.OAuth2Client; |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 37 | import de.ids_mannheim.korap.utils.JsonUtils; |
| margaretha | 977fabe | 2022-04-28 09:23:47 +0200 | [diff] [blame] | 38 | import de.ids_mannheim.korap.utils.TimeUtils; |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 39 | import de.ids_mannheim.korap.web.input.OAuth2ClientJson; |
| margaretha | 96c309d | 2023-08-16 12:24:12 +0200 | [diff] [blame] | 40 | import jakarta.ws.rs.ProcessingException; |
| 41 | import jakarta.ws.rs.client.Client; |
| 42 | import jakarta.ws.rs.client.ClientBuilder; |
| 43 | import jakarta.ws.rs.client.Entity; |
| margaretha | 5f5d3ed | 2023-08-30 23:48:52 +0200 | [diff] [blame] | 44 | import jakarta.ws.rs.client.Invocation.Builder; |
| margaretha | 96c309d | 2023-08-16 12:24:12 +0200 | [diff] [blame] | 45 | import jakarta.ws.rs.client.WebTarget; |
| 46 | import jakarta.ws.rs.core.Form; |
| 47 | import jakarta.ws.rs.core.MultivaluedMap; |
| 48 | import jakarta.ws.rs.core.Response; |
| 49 | import jakarta.ws.rs.core.Response.Status; |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 50 | |
| Marc Kupietz | d43a98d | 2023-09-22 17:11:46 +0200 | [diff] [blame] | 51 | import static org.junit.jupiter.api.Assertions.*; |
| 52 | |
| margaretha | 230effb | 2018-11-29 17:28:18 +0100 | [diff] [blame] | 53 | /** |
| 54 | * Provides common methods and variables for OAuth2 tests, |
| 55 | * and does not run any test. |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 56 | * |
| 57 | * @author margaretha |
| 58 | * |
| 59 | */ |
| margaretha | f370f54 | 2018-08-23 18:51:49 +0200 | [diff] [blame] | 60 | public abstract class OAuth2TestBase extends SpringJerseyTest { |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 61 | |
| margaretha | 93e602e | 2019-08-07 15:19:56 +0200 | [diff] [blame] | 62 | @Autowired |
| margaretha | ca5472a | 2023-09-22 18:00:03 +0200 | [diff] [blame] | 63 | private AccessTokenDao tokenDao; |
| 64 | @Autowired |
| 65 | private OAuth2ClientDao clientDao; |
| 66 | @Autowired |
| 67 | private RandomCodeGenerator codeGenerator; |
| 68 | @Autowired |
| margaretha | 93e602e | 2019-08-07 15:19:56 +0200 | [diff] [blame] | 69 | protected RefreshTokenDao refreshTokenDao; |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 70 | |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 71 | protected String publicClientId = "8bIDtZnH6NvRkW2Fq"; |
| margaretha | ffb8950 | 2022-04-20 12:03:16 +0200 | [diff] [blame] | 72 | // without registered redirect URI |
| 73 | protected String publicClientId2 = "nW5qM63Rb2a7KdT9L"; |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 74 | protected String confidentialClientId = "9aHsGW6QflV13ixNpez"; |
| margaretha | 3507469 | 2021-03-26 18:11:59 +0100 | [diff] [blame] | 75 | protected String confidentialClientId2 = "52atrL0ajex_3_5imd9Mgw"; |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 76 | protected String superClientId = "fCBbQkAyYzI4NzUxMg"; |
| 77 | protected String clientSecret = "secret"; |
| margaretha | d67b427 | 2022-04-11 17:34:19 +0200 | [diff] [blame] | 78 | protected String state = "thisIsMyState"; |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 79 | |
| margaretha | 74110b7 | 2022-03-28 12:16:51 +0200 | [diff] [blame] | 80 | public static String ACCESS_TOKEN_TYPE = "access_token"; |
| 81 | public static String REFRESH_TOKEN_TYPE = "refresh_token"; |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 82 | |
| margaretha | 977fabe | 2022-04-28 09:23:47 +0200 | [diff] [blame] | 83 | protected int defaultRefreshTokenExpiry = TimeUtils.convertTimeToSeconds("365D"); |
| 84 | |
| margaretha | d67b427 | 2022-04-11 17:34:19 +0200 | [diff] [blame] | 85 | protected String clientURL = "http://example.client.com"; |
| 86 | protected String clientRedirectUri = "https://example.client.com/redirect"; |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 87 | |
| margaretha | ffb8950 | 2022-04-20 12:03:16 +0200 | [diff] [blame] | 88 | protected MultivaluedMap<String, String> getQueryParamsFromURI (URI uri) { |
| 89 | return UriComponent.decodeQuery(uri, true); |
| 90 | }; |
| margaretha | 74110b7 | 2022-03-28 12:16:51 +0200 | [diff] [blame] | 91 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 92 | protected Form getSuperClientForm () { |
| 93 | Form form = new Form(); |
| 94 | form.param("super_client_id", superClientId); |
| 95 | form.param("super_client_secret", clientSecret); |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 96 | return form; |
| 97 | } |
| 98 | |
| margaretha | 3cd2d5f | 2023-05-02 14:51:11 +0200 | [diff] [blame] | 99 | protected String parseAuthorizationCode (Response response) { |
| 100 | |
| 101 | assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(), |
| 102 | response.getStatus()); |
| 103 | |
| 104 | URI redirectUri = response.getLocation(); |
| 105 | MultiValueMap<String, String> params = UriComponentsBuilder |
| 106 | .fromUri(redirectUri).build().getQueryParams(); |
| 107 | return params.getFirst("code"); |
| 108 | } |
| 109 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 110 | protected Response requestAuthorizationCode (String responseType, |
| margaretha | d67b427 | 2022-04-11 17:34:19 +0200 | [diff] [blame] | 111 | String clientId, String redirectUri, String scope, String state, |
| 112 | String authHeader) throws KustvaktException { |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 113 | |
| margaretha | cc92959 | 2023-01-31 11:07:35 +0100 | [diff] [blame] | 114 | ClientConfig clientConfig = new ClientConfig(); |
| 115 | clientConfig.property(ClientProperties.FOLLOW_REDIRECTS, false); |
| 116 | Client client = ClientBuilder.newClient(clientConfig); |
| margaretha | 0034a0c | 2022-05-17 10:37:41 +0200 | [diff] [blame] | 117 | |
| margaretha | cc92959 | 2023-01-31 11:07:35 +0100 | [diff] [blame] | 118 | WebTarget request = client.target(getBaseUri()).path(API_VERSION) |
| 119 | .path("oauth2").path("authorize"); |
| 120 | |
| margaretha | 0034a0c | 2022-05-17 10:37:41 +0200 | [diff] [blame] | 121 | if (!responseType.isEmpty()) { |
| 122 | request = request.queryParam("response_type", responseType); |
| 123 | } |
| 124 | if (!clientId.isEmpty()) { |
| 125 | request = request.queryParam("client_id", clientId); |
| 126 | } |
| 127 | if (!redirectUri.isEmpty()) { |
| 128 | request = request.queryParam("redirect_uri", redirectUri); |
| 129 | } |
| 130 | if (!scope.isEmpty()) { |
| 131 | request = request.queryParam("scope", scope); |
| 132 | } |
| 133 | if (!state.isEmpty()) { |
| 134 | request = request.queryParam("state", state); |
| 135 | } |
| 136 | |
| margaretha | 5f5d3ed | 2023-08-30 23:48:52 +0200 | [diff] [blame] | 137 | Builder builder = request.request().header(Attributes.AUTHORIZATION, authHeader); |
| 138 | |
| 139 | return builder.get(); |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 140 | } |
| 141 | |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 142 | protected String requestAuthorizationCode (String clientId, |
| margaretha | d67b427 | 2022-04-11 17:34:19 +0200 | [diff] [blame] | 143 | String authHeader) throws KustvaktException { |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 144 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 145 | Response response = requestAuthorizationCode("code", clientId, "", |
| margaretha | 64ea645 | 2023-01-30 12:39:19 +0100 | [diff] [blame] | 146 | "search match_info", "", authHeader); |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 147 | assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(), |
| 148 | response.getStatus()); |
| 149 | URI redirectUri = response.getLocation(); |
| 150 | |
| 151 | MultiValueMap<String, String> params = UriComponentsBuilder |
| 152 | .fromUri(redirectUri).build().getQueryParams(); |
| 153 | return params.getFirst("code"); |
| 154 | } |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 155 | |
| 156 | protected String requestAuthorizationCode (String clientId, |
| 157 | String redirect_uri, String authHeader) throws KustvaktException { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 158 | Response response = requestAuthorizationCode("code", clientId, |
| margaretha | 64ea645 | 2023-01-30 12:39:19 +0100 | [diff] [blame] | 159 | redirect_uri, "search", "", authHeader); |
| Akron | dc6d73d | 2020-04-15 16:40:04 +0200 | [diff] [blame] | 160 | assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(), |
| 161 | response.getStatus()); |
| 162 | URI redirectUri = response.getLocation(); |
| 163 | |
| 164 | MultiValueMap<String, String> params = UriComponentsBuilder |
| 165 | .fromUri(redirectUri).build().getQueryParams(); |
| 166 | return params.getFirst("code"); |
| 167 | } |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 168 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 169 | protected Response requestToken (Form form) |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 170 | throws KustvaktException { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 171 | return target().path(API_VERSION).path("oauth2").path("token") |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 172 | .request() |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 173 | .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32") |
| 174 | .header(HttpHeaders.CONTENT_TYPE, |
| 175 | ContentType.APPLICATION_FORM_URLENCODED) |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 176 | .post(Entity.form(form)); |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | // client credentials as form params |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 180 | protected Response requestTokenWithAuthorizationCodeAndForm ( |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 181 | String clientId, String clientSecret, String code) |
| 182 | throws KustvaktException { |
| 183 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 184 | Form form = new Form(); |
| 185 | form.param("grant_type", "authorization_code"); |
| 186 | form.param("client_id", clientId); |
| 187 | form.param("client_secret", clientSecret); |
| 188 | form.param("code", code); |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 189 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 190 | return target().path(API_VERSION).path("oauth2").path("token") |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 191 | .request() |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 192 | .header(HttpHeaders.CONTENT_TYPE, |
| 193 | ContentType.APPLICATION_FORM_URLENCODED) |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 194 | .post(Entity.form(form)); |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 195 | } |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 196 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 197 | protected Response requestTokenWithAuthorizationCodeAndForm ( |
| Akron | dc6d73d | 2020-04-15 16:40:04 +0200 | [diff] [blame] | 198 | String clientId, String clientSecret, String code, |
| 199 | String redirectUri) throws KustvaktException { |
| 200 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 201 | Form form = new Form(); |
| 202 | form.param("grant_type", "authorization_code"); |
| 203 | form.param("client_id", clientId); |
| 204 | form.param("client_secret", clientSecret); |
| 205 | form.param("code", code); |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 206 | if (redirectUri != null) { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 207 | form.param("redirect_uri", redirectUri); |
| Akron | dc6d73d | 2020-04-15 16:40:04 +0200 | [diff] [blame] | 208 | } |
| 209 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 210 | return target().path(API_VERSION).path("oauth2").path("token") |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 211 | .request() |
| Akron | dc6d73d | 2020-04-15 16:40:04 +0200 | [diff] [blame] | 212 | .header(HttpHeaders.CONTENT_TYPE, |
| 213 | ContentType.APPLICATION_FORM_URLENCODED) |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 214 | .post(Entity.form(form)); |
| Akron | dc6d73d | 2020-04-15 16:40:04 +0200 | [diff] [blame] | 215 | } |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 216 | |
| 217 | // client credentials in authorization header |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 218 | protected JsonNode requestTokenWithAuthorizationCodeAndHeader ( |
| 219 | String clientId, String code, String authHeader) |
| 220 | throws KustvaktException { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 221 | Form form = new Form(); |
| 222 | form.param("grant_type", "authorization_code"); |
| 223 | form.param("client_id", clientId); |
| 224 | form.param("code", code); |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 225 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 226 | Response response = target().path(API_VERSION).path("oauth2") |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 227 | .path("token") |
| 228 | .request() |
| 229 | .header(Attributes.AUTHORIZATION, authHeader) |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 230 | .header(HttpHeaders.CONTENT_TYPE, |
| 231 | ContentType.APPLICATION_FORM_URLENCODED) |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 232 | .post(Entity.form(form)); |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 233 | |
| margaretha | 3cd2d5f | 2023-05-02 14:51:11 +0200 | [diff] [blame] | 234 | assertEquals(Status.OK.getStatusCode(), response.getStatus()); |
| 235 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 236 | String entity = response.readEntity(String.class); |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 237 | return JsonUtils.readTree(entity); |
| 238 | } |
| 239 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 240 | protected Response requestTokenWithDoryPassword (String clientId, |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 241 | String clientSecret) throws KustvaktException { |
| margaretha | 230effb | 2018-11-29 17:28:18 +0100 | [diff] [blame] | 242 | return requestTokenWithPassword(clientId, clientSecret, "dory", |
| 243 | "password"); |
| 244 | } |
| 245 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 246 | protected Response requestTokenWithPassword (String clientId, |
| margaretha | 230effb | 2018-11-29 17:28:18 +0100 | [diff] [blame] | 247 | String clientSecret, String username, String password) |
| 248 | throws KustvaktException { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 249 | Form form = new Form(); |
| 250 | form.param("grant_type", "password"); |
| 251 | form.param("client_id", clientId); |
| margaretha | 7ac20b1 | 2023-09-27 09:40:16 +0200 | [diff] [blame] | 252 | if (clientSecret !=null && !clientSecret.isEmpty()) { |
| 253 | form.param("client_secret", clientSecret); |
| 254 | } |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 255 | form.param("username", username); |
| 256 | form.param("password", password); |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 257 | |
| 258 | return requestToken(form); |
| 259 | } |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 260 | |
| margaretha | c750cbb | 2018-12-11 12:47:02 +0100 | [diff] [blame] | 261 | protected void testRequestTokenWithRevokedRefreshToken (String clientId, |
| 262 | String clientSecret, String refreshToken) throws KustvaktException { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 263 | Form form = new Form(); |
| 264 | form.param("grant_type", GrantType.REFRESH_TOKEN.toString()); |
| 265 | form.param("client_id", clientId); |
| 266 | form.param("client_secret", clientSecret); |
| 267 | form.param("refresh_token", refreshToken); |
| margaretha | c750cbb | 2018-12-11 12:47:02 +0100 | [diff] [blame] | 268 | if (clientSecret != null) { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 269 | form.param("client_secret", clientSecret); |
| margaretha | c750cbb | 2018-12-11 12:47:02 +0100 | [diff] [blame] | 270 | } |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 271 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 272 | Response response = |
| 273 | target().path(API_VERSION).path("oauth2").path("token") |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 274 | .request() |
| margaretha | c750cbb | 2018-12-11 12:47:02 +0100 | [diff] [blame] | 275 | .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32") |
| 276 | .header(HttpHeaders.CONTENT_TYPE, |
| 277 | ContentType.APPLICATION_FORM_URLENCODED) |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 278 | .post(Entity.form(form)); |
| margaretha | c750cbb | 2018-12-11 12:47:02 +0100 | [diff] [blame] | 279 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 280 | String entity = response.readEntity(String.class); |
| margaretha | c750cbb | 2018-12-11 12:47:02 +0100 | [diff] [blame] | 281 | JsonNode node = JsonUtils.readTree(entity); |
| margaretha | 7ac20b1 | 2023-09-27 09:40:16 +0200 | [diff] [blame] | 282 | assertEquals(OAuth2Error.INVALID_GRANT.getCode(), node.at("/error").asText()); |
| margaretha | c750cbb | 2018-12-11 12:47:02 +0100 | [diff] [blame] | 283 | assertEquals("Refresh token has been revoked", |
| 284 | node.at("/error_description").asText()); |
| 285 | } |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 286 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 287 | protected Response registerClient (String username, |
| abcpro1 | 63418f4 | 2022-11-09 20:35:09 +0000 | [diff] [blame] | 288 | OAuth2ClientJson json) throws |
| 289 | ProcessingException, KustvaktException { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 290 | return target().path(API_VERSION).path("oauth2").path("client") |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 291 | .path("register") |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 292 | .request() |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 293 | .header(Attributes.AUTHORIZATION, |
| 294 | HttpAuthorizationHandler |
| 295 | .createBasicAuthorizationHeaderValue(username, |
| 296 | "password")) |
| 297 | .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32") |
| 298 | .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON) |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 299 | .post(Entity.json(json)); |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 300 | } |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 301 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 302 | protected Response registerConfidentialClient (String username) |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 303 | throws KustvaktException { |
| margaretha | c750cbb | 2018-12-11 12:47:02 +0100 | [diff] [blame] | 304 | |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 305 | OAuth2ClientJson json = new OAuth2ClientJson(); |
| 306 | json.setName("OAuth2ClientTest"); |
| 307 | json.setType(OAuth2ClientType.CONFIDENTIAL); |
| margaretha | 3ef1b81 | 2022-04-06 11:32:54 +0200 | [diff] [blame] | 308 | json.setUrl(clientURL); |
| 309 | json.setRedirectURI(clientRedirectUri); |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 310 | json.setDescription("This is a confidential test client."); |
| 311 | |
| 312 | return registerClient(username, json); |
| 313 | } |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 314 | |
| margaretha | 3ef1b81 | 2022-04-06 11:32:54 +0200 | [diff] [blame] | 315 | protected void testConfidentialClientInfo (String clientId, String username) |
| abcpro1 | 63418f4 | 2022-11-09 20:35:09 +0000 | [diff] [blame] | 316 | throws ProcessingException, |
| margaretha | 3ef1b81 | 2022-04-06 11:32:54 +0200 | [diff] [blame] | 317 | KustvaktException { |
| 318 | JsonNode clientInfo = retrieveClientInfo(clientId, username); |
| margaretha | 79f0144 | 2022-05-04 12:03:47 +0200 | [diff] [blame] | 319 | assertEquals(clientId, clientInfo.at("/client_id").asText()); |
| 320 | assertEquals("OAuth2ClientTest", clientInfo.at("/client_name").asText()); |
| margaretha | 3ef1b81 | 2022-04-06 11:32:54 +0200 | [diff] [blame] | 321 | assertEquals(OAuth2ClientType.CONFIDENTIAL.name(), |
| margaretha | 79f0144 | 2022-05-04 12:03:47 +0200 | [diff] [blame] | 322 | clientInfo.at("/client_type").asText()); |
| margaretha | 3ef1b81 | 2022-04-06 11:32:54 +0200 | [diff] [blame] | 323 | assertEquals(username, clientInfo.at("/registered_by").asText()); |
| margaretha | 79f0144 | 2022-05-04 12:03:47 +0200 | [diff] [blame] | 324 | assertEquals(clientURL, clientInfo.at("/client_url").asText()); |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 325 | assertEquals(clientRedirectUri, |
| margaretha | 79f0144 | 2022-05-04 12:03:47 +0200 | [diff] [blame] | 326 | clientInfo.at("/client_redirect_uri").asText()); |
| margaretha | 977fabe | 2022-04-28 09:23:47 +0200 | [diff] [blame] | 327 | // 31536000 seconds |
| margaretha | 79f0144 | 2022-05-04 12:03:47 +0200 | [diff] [blame] | 328 | assertEquals(defaultRefreshTokenExpiry, |
| margaretha | 977fabe | 2022-04-28 09:23:47 +0200 | [diff] [blame] | 329 | clientInfo.at("/refresh_token_expiry").asInt()); |
| margaretha | 3ef1b81 | 2022-04-06 11:32:54 +0200 | [diff] [blame] | 330 | assertNotNull(clientInfo.at("/description")); |
| margaretha | d716312 | 2022-04-11 09:42:41 +0200 | [diff] [blame] | 331 | assertNotNull(clientInfo.at("/registration_date")); |
| 332 | assertTrue(clientInfo.at("/permitted").asBoolean()); |
| 333 | assertTrue(clientInfo.at("/source").isMissingNode()); |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 334 | |
| margaretha | 3ef1b81 | 2022-04-06 11:32:54 +0200 | [diff] [blame] | 335 | } |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 336 | |
| margaretha | d484156 | 2022-06-01 12:24:47 +0200 | [diff] [blame] | 337 | protected void deregisterClient (String username, |
| abcpro1 | 63418f4 | 2022-11-09 20:35:09 +0000 | [diff] [blame] | 338 | String clientId) throws |
| 339 | ProcessingException, KustvaktException { |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 340 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 341 | Response response = target().path(API_VERSION).path("oauth2") |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 342 | .path("client").path("deregister").path(clientId) |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 343 | .request() |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 344 | .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler |
| 345 | .createBasicAuthorizationHeaderValue(username, "pass")) |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 346 | .delete(); |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 347 | |
| 348 | assertEquals(Status.OK.getStatusCode(), response.getStatus()); |
| 349 | } |
| 350 | |
| 351 | protected JsonNode retrieveClientInfo (String clientId, String username) |
| abcpro1 | 63418f4 | 2022-11-09 20:35:09 +0000 | [diff] [blame] | 352 | throws ProcessingException, |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 353 | KustvaktException { |
| margaretha | b22a585 | 2023-01-27 14:43:36 +0100 | [diff] [blame] | 354 | Form form = new Form(); |
| 355 | form.param("super_client_id", superClientId); |
| 356 | form.param("super_client_secret", clientSecret); |
| 357 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 358 | Response response = target().path(API_VERSION).path("oauth2") |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 359 | .path("client").path(clientId) |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 360 | .request() |
| margaretha | b22a585 | 2023-01-27 14:43:36 +0100 | [diff] [blame] | 361 | // .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler |
| 362 | // .createBasicAuthorizationHeaderValue(username, "pass")) |
| 363 | .header(HttpHeaders.CONTENT_TYPE, |
| 364 | ContentType.APPLICATION_FORM_URLENCODED) |
| 365 | .post(Entity.form(form)); |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 366 | |
| 367 | assertEquals(Status.OK.getStatusCode(), response.getStatus()); |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 368 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 369 | String entity = response.readEntity(String.class); |
| margaretha | e28cdd9 | 2022-03-29 09:42:08 +0200 | [diff] [blame] | 370 | return JsonUtils.readTree(entity); |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 371 | } |
| margaretha | 230effb | 2018-11-29 17:28:18 +0100 | [diff] [blame] | 372 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 373 | protected Response searchWithAccessToken (String accessToken) { |
| 374 | return target().path(API_VERSION).path("search") |
| margaretha | 230effb | 2018-11-29 17:28:18 +0100 | [diff] [blame] | 375 | .queryParam("q", "Wasser").queryParam("ql", "poliqarp") |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 376 | .request() |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 377 | .header(Attributes.AUTHORIZATION, "Bearer " + accessToken) |
| 378 | .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32") |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 379 | .get(); |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 380 | } |
| margaretha | d484156 | 2022-06-01 12:24:47 +0200 | [diff] [blame] | 381 | |
| 382 | protected void testSearchWithOAuth2Token (String accessToken) |
| 383 | throws KustvaktException, IOException { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 384 | Response response = searchWithAccessToken(accessToken); |
| 385 | String entity = response.readEntity(String.class); |
| 386 | assertEquals(Status.OK.getStatusCode(), |
| margaretha | d484156 | 2022-06-01 12:24:47 +0200 | [diff] [blame] | 387 | response.getStatus()); |
| 388 | JsonNode node = JsonUtils.readTree(entity); |
| 389 | assertNotNull(node); |
| 390 | assertEquals(25, node.at("/matches").size()); |
| 391 | } |
| 392 | |
| 393 | protected void testSearchWithRevokedAccessToken (String accessToken) |
| 394 | throws KustvaktException { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 395 | Response response = searchWithAccessToken(accessToken); |
| 396 | String entity = response.readEntity(String.class); |
| 397 | assertEquals(Status.UNAUTHORIZED.getStatusCode(), |
| margaretha | d484156 | 2022-06-01 12:24:47 +0200 | [diff] [blame] | 398 | response.getStatus()); |
| 399 | |
| 400 | JsonNode node = JsonUtils.readTree(entity); |
| 401 | assertEquals(StatusCodes.INVALID_ACCESS_TOKEN, |
| 402 | node.at("/errors/0/0").asInt()); |
| 403 | assertEquals("Access token is invalid", |
| 404 | node.at("/errors/0/1").asText()); |
| 405 | } |
| 406 | |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 407 | |
| 408 | protected void testRevokeTokenViaSuperClient (String token, |
| 409 | String userAuthHeader) { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 410 | Form form = new Form(); |
| 411 | form.param("token", token); |
| 412 | form.param("super_client_id", superClientId); |
| 413 | form.param("super_client_secret", clientSecret); |
| margaretha | 0afd44a | 2020-02-05 10:49:21 +0100 | [diff] [blame] | 414 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 415 | Response response = target().path(API_VERSION).path("oauth2") |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 416 | .path("revoke").path("super") |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 417 | .request() |
| margaretha | 0afd44a | 2020-02-05 10:49:21 +0100 | [diff] [blame] | 418 | .header(HttpHeaders.CONTENT_TYPE, |
| 419 | ContentType.APPLICATION_FORM_URLENCODED) |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 420 | .header(Attributes.AUTHORIZATION, userAuthHeader) |
| 421 | .post(Entity.form(form)); |
| margaretha | 0afd44a | 2020-02-05 10:49:21 +0100 | [diff] [blame] | 422 | |
| 423 | assertEquals(Status.OK.getStatusCode(), response.getStatus()); |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 424 | assertEquals("SUCCESS", response.readEntity(String.class)); |
| margaretha | 0afd44a | 2020-02-05 10:49:21 +0100 | [diff] [blame] | 425 | } |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 426 | |
| margaretha | 74110b7 | 2022-03-28 12:16:51 +0200 | [diff] [blame] | 427 | protected void testRevokeToken (String token, String clientId, |
| 428 | String clientSecret, String tokenType) { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 429 | Form form = new Form(); |
| 430 | form.param("token_type", tokenType); |
| 431 | form.param("token", token); |
| 432 | form.param("client_id", clientId); |
| margaretha | 74110b7 | 2022-03-28 12:16:51 +0200 | [diff] [blame] | 433 | if (clientSecret != null) { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 434 | form.param("client_secret", clientSecret); |
| margaretha | 74110b7 | 2022-03-28 12:16:51 +0200 | [diff] [blame] | 435 | } |
| 436 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 437 | Response response = |
| 438 | target().path(API_VERSION).path("oauth2").path("revoke") |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 439 | .request() |
| margaretha | 74110b7 | 2022-03-28 12:16:51 +0200 | [diff] [blame] | 440 | .header(HttpHeaders.CONTENT_TYPE, |
| 441 | ContentType.APPLICATION_FORM_URLENCODED) |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 442 | .post(Entity.form(form)); |
| margaretha | 74110b7 | 2022-03-28 12:16:51 +0200 | [diff] [blame] | 443 | |
| 444 | assertEquals(Status.OK.getStatusCode(), response.getStatus()); |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 445 | assertEquals("SUCCESS", response.readEntity(String.class)); |
| margaretha | 74110b7 | 2022-03-28 12:16:51 +0200 | [diff] [blame] | 446 | } |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 447 | |
| 448 | protected JsonNode listUserRegisteredClients (String username) |
| abcpro1 | 63418f4 | 2022-11-09 20:35:09 +0000 | [diff] [blame] | 449 | throws ProcessingException, |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 450 | KustvaktException { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 451 | Form form = getSuperClientForm(); |
| 452 | Response response = target().path(API_VERSION).path("oauth2") |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 453 | .path("client").path("list") |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 454 | .request() |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 455 | .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler |
| 456 | .createBasicAuthorizationHeaderValue(username, "pwd")) |
| 457 | .header(HttpHeaders.CONTENT_TYPE, |
| 458 | ContentType.APPLICATION_FORM_URLENCODED) |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 459 | .post(Entity.form(form)); |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 460 | |
| 461 | assertEquals(Status.OK.getStatusCode(), response.getStatus()); |
| 462 | |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 463 | String entity = response.readEntity(String.class); |
| margaretha | e20a280 | 2022-04-21 12:37:38 +0200 | [diff] [blame] | 464 | return JsonUtils.readTree(entity); |
| 465 | } |
| margaretha | 9436ebe | 2022-04-22 11:48:37 +0200 | [diff] [blame] | 466 | |
| margaretha | 45ba733 | 2023-01-31 11:39:52 +0100 | [diff] [blame] | 467 | protected void testInvalidRedirectUri (String entity, String contentType, |
| 468 | boolean includeState, int status) throws KustvaktException { |
| margaretha | 9436ebe | 2022-04-22 11:48:37 +0200 | [diff] [blame] | 469 | JsonNode node = JsonUtils.readTree(entity); |
| margaretha | b38e630 | 2023-10-26 12:33:26 +0200 | [diff] [blame^] | 470 | System.out.println(node); |
| margaretha | 5f5d3ed | 2023-08-30 23:48:52 +0200 | [diff] [blame] | 471 | assertEquals(OAuth2Error.INVALID_REQUEST.getCode(), |
| margaretha | 9436ebe | 2022-04-22 11:48:37 +0200 | [diff] [blame] | 472 | node.at("/error").asText()); |
| 473 | assertEquals("Invalid redirect URI", |
| 474 | node.at("/error_description").asText()); |
| 475 | if (includeState) { |
| 476 | assertEquals(state, node.at("/state").asText()); |
| 477 | } |
| 478 | |
| margaretha | 45ba733 | 2023-01-31 11:39:52 +0100 | [diff] [blame] | 479 | assertEquals("application/json;charset=utf-8", contentType); |
| margaretha | 9436ebe | 2022-04-22 11:48:37 +0200 | [diff] [blame] | 480 | assertEquals(Status.BAD_REQUEST.getStatusCode(), status); |
| 481 | } |
| margaretha | ca5472a | 2023-09-22 18:00:03 +0200 | [diff] [blame] | 482 | |
| 483 | protected String createExpiredAccessToken () throws KustvaktException { |
| 484 | String authToken = codeGenerator.createRandomCode(); |
| 485 | |
| 486 | // create new access token |
| 487 | OAuth2Client client = clientDao.retrieveClientById(publicClientId); |
| 488 | |
| 489 | ZonedDateTime now = |
| 490 | ZonedDateTime.now(ZoneId.of(Attributes.DEFAULT_TIME_ZONE)); |
| 491 | Set<AccessScope> scopes = new HashSet<>(); |
| 492 | scopes.add(new AccessScope(OAuth2Scope.EDIT_VC)); |
| 493 | |
| 494 | AccessToken accessToken = new AccessToken(); |
| 495 | accessToken.setCreatedDate(now.minusSeconds(5)); |
| 496 | accessToken.setExpiryDate(now.minusSeconds(3)); |
| 497 | accessToken.setToken(authToken); |
| 498 | accessToken.setScopes(scopes); |
| 499 | accessToken.setUserId("marlin"); |
| 500 | accessToken.setClient(client); |
| 501 | accessToken.setUserAuthenticationTime(now.minusSeconds(5)); |
| 502 | tokenDao.storeAccessToken(accessToken); |
| 503 | return authToken; |
| 504 | } |
| margaretha | f008512 | 2018-08-16 16:19:53 +0200 | [diff] [blame] | 505 | } |