1 /*
2 * Copyright (C) 2026 Alberto Irurueta Carro (alberto@irurueta.com)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.irurueta.authserver.authorization.api.web.implicit;
17
18 import java.util.List;
19 import java.util.Set;
20 import org.springframework.security.authentication.AbstractAuthenticationToken;
21 import org.springframework.security.core.Authentication;
22
23 /**
24 * An authorization request of the legacy implicit flow ({@code response_type=token}), not yet authenticated: the
25 * request as the client sent it and the user the request arrived with.
26 */
27 public class LegacyImplicitAuthorizationRequestToken extends AbstractAuthenticationToken {
28
29 /** Serial version. */
30 private static final long serialVersionUID = 1L;
31
32 /** Identifier of the client. */
33 private final String clientId;
34
35 /** Redirect URI of the request, {@code null} when it names none. */
36 private final String redirectUri;
37
38 /** Scopes requested. */
39 private final Set<String> scopes;
40
41 /** State of the request, {@code null} when it has none. */
42 private final String state;
43
44 /** The user the request arrived with, possibly anonymous. */
45 private final transient Authentication user;
46
47 /**
48 * Creates the request.
49 *
50 * @param clientId identifier of the client.
51 * @param redirectUri redirect URI of the request, may be {@code null}.
52 * @param scopes scopes requested.
53 * @param state state of the request, may be {@code null}.
54 * @param user the user the request arrived with.
55 */
56 public LegacyImplicitAuthorizationRequestToken(final String clientId, final String redirectUri,
57 final Set<String> scopes, final String state, final Authentication user) {
58 super(List.of());
59 this.clientId = clientId;
60 this.redirectUri = redirectUri;
61 this.scopes = Set.copyOf(scopes);
62 this.state = state;
63 this.user = user;
64 }
65
66 /**
67 * Returns the identifier of the client.
68 *
69 * @return the client id.
70 */
71 public String getClientId() {
72 return clientId;
73 }
74
75 /**
76 * Returns the redirect URI of the request.
77 *
78 * @return the redirect URI, {@code null} when the request names none.
79 */
80 public String getRedirectUri() {
81 return redirectUri;
82 }
83
84 /**
85 * Returns the scopes requested.
86 *
87 * @return the scopes, possibly empty.
88 */
89 public Set<String> getScopes() {
90 return scopes;
91 }
92
93 /**
94 * Returns the state of the request.
95 *
96 * @return the state, {@code null} when the request has none.
97 */
98 public String getState() {
99 return state;
100 }
101
102 /**
103 * Returns the credentials, which a request has none of.
104 *
105 * @return an empty string.
106 */
107 @Override
108 public Object getCredentials() {
109 return "";
110 }
111
112 /**
113 * Returns the principal of the request: the user it arrived with.
114 *
115 * @return the user.
116 */
117 @Override
118 public Object getPrincipal() {
119 return user;
120 }
121 }