|
18 | 18 | import org.springframework.http.HttpStatus;
|
19 | 19 | import org.springframework.http.MediaType;
|
20 | 20 | import org.springframework.http.ResponseEntity;
|
21 |
| -import org.springframework.util.Base64Utils; |
22 | 21 | import org.springframework.web.bind.annotation.CrossOrigin;
|
23 | 22 | import org.springframework.web.bind.annotation.RequestHeader;
|
24 | 23 | import org.springframework.web.bind.annotation.RequestMapping;
|
|
43 | 42 | import java.util.HashMap;
|
44 | 43 | import java.util.HashSet;
|
45 | 44 | import java.util.LinkedHashMap;
|
| 45 | +import java.util.List; |
46 | 46 | import java.util.Map;
|
47 | 47 | import java.util.Set;
|
48 | 48 | import java.util.UUID;
|
@@ -136,7 +136,7 @@ public ResponseEntity<?> userinfo(@RequestHeader("Authorization") String auth,
|
136 | 136 | HttpServletRequest req) {
|
137 | 137 | log.info("called " + USERINFO_ENDPOINT + " from {}", req.getRemoteHost());
|
138 | 138 | if (!auth.startsWith("Bearer ")) {
|
139 |
| - if(access_token == null) { |
| 139 | + if (access_token == null) { |
140 | 140 | return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("No token");
|
141 | 141 | }
|
142 | 142 | auth = access_token;
|
@@ -217,7 +217,7 @@ public ResponseEntity<?> token(@RequestParam String grant_type,
|
217 | 217 | }
|
218 | 218 | if (codeInfo.codeChallenge != null) {
|
219 | 219 | // check PKCE
|
220 |
| - if(code_verifier == null) { |
| 220 | + if (code_verifier == null) { |
221 | 221 | return jsonError("invalid_request", "code_verifier missing");
|
222 | 222 | }
|
223 | 223 | if ("S256".equals(codeInfo.codeChallengeMethod)) {
|
@@ -274,39 +274,40 @@ public ResponseEntity<?> authorize(@RequestParam String client_id,
|
274 | 274 | String[] creds = new String(Base64.getDecoder().decode(auth.split(" ")[1])).split(":", 2);
|
275 | 275 | String login = creds[0];
|
276 | 276 | String password = creds[1];
|
277 |
| - User user = serverProperties.getUser(); |
278 |
| - if (user.getLogname().equals(login) && user.getPassword().equals(password)) { |
279 |
| - log.info("password for user {} is correct", login); |
280 |
| - Set<String> responseType = setFromSpaceSeparatedString(response_type); |
281 |
| - String iss = uriBuilder.replacePath("/").build().encode().toUriString(); |
282 |
| - if (responseType.contains("token")) { |
283 |
| - // implicit flow |
284 |
| - log.info("using implicit flow"); |
285 |
| - String access_token = createAccessToken(iss, user, client_id, scope); |
286 |
| - String id_token = createIdToken(iss, user, client_id, nonce, access_token); |
287 |
| - String url = redirect_uri + "#" + |
288 |
| - "access_token=" + urlencode(access_token) + |
289 |
| - "&token_type=Bearer" + |
290 |
| - "&state=" + urlencode(state) + |
291 |
| - "&expires_in=" + serverProperties.getTokenExpirationSeconds() + |
292 |
| - "&id_token=" + urlencode(id_token); |
293 |
| - return ResponseEntity.status(HttpStatus.FOUND).header("Location", url).build(); |
294 |
| - } else if (responseType.contains("code")) { |
295 |
| - // authorization code flow |
296 |
| - log.info("using authorization code flow {}", code_challenge!=null ? "with PKCE" : ""); |
297 |
| - String code = createAuthorizationCode(code_challenge, code_challenge_method, client_id, redirect_uri, user, iss, scope, nonce); |
298 |
| - String url = redirect_uri + "?" + |
299 |
| - "code=" + code + |
300 |
| - "&state=" + urlencode(state); |
301 |
| - return ResponseEntity.status(HttpStatus.FOUND).header("Location", url).build(); |
302 |
| - } else { |
303 |
| - String url = redirect_uri + "#" + "error=unsupported_response_type"; |
304 |
| - return ResponseEntity.status(HttpStatus.FOUND).header("Location", url).build(); |
| 277 | + List<User> users = serverProperties.getUsers(); |
| 278 | + for (User user : users) { |
| 279 | + if (user.getLogname().equals(login) && user.getPassword().equals(password)) { |
| 280 | + log.info("password for user {} is correct", login); |
| 281 | + Set<String> responseType = setFromSpaceSeparatedString(response_type); |
| 282 | + String iss = uriBuilder.replacePath("/").build().encode().toUriString(); |
| 283 | + if (responseType.contains("token")) { |
| 284 | + // implicit flow |
| 285 | + log.info("using implicit flow"); |
| 286 | + String access_token = createAccessToken(iss, user, client_id, scope); |
| 287 | + String id_token = createIdToken(iss, user, client_id, nonce, access_token); |
| 288 | + String url = redirect_uri + "#" + |
| 289 | + "access_token=" + urlencode(access_token) + |
| 290 | + "&token_type=Bearer" + |
| 291 | + "&state=" + urlencode(state) + |
| 292 | + "&expires_in=" + serverProperties.getTokenExpirationSeconds() + |
| 293 | + "&id_token=" + urlencode(id_token); |
| 294 | + return ResponseEntity.status(HttpStatus.FOUND).header("Location", url).build(); |
| 295 | + } else if (responseType.contains("code")) { |
| 296 | + // authorization code flow |
| 297 | + log.info("using authorization code flow {}", code_challenge != null ? "with PKCE" : ""); |
| 298 | + String code = createAuthorizationCode(code_challenge, code_challenge_method, client_id, redirect_uri, user, iss, scope, nonce); |
| 299 | + String url = redirect_uri + "?" + |
| 300 | + "code=" + code + |
| 301 | + "&state=" + urlencode(state); |
| 302 | + return ResponseEntity.status(HttpStatus.FOUND).header("Location", url).build(); |
| 303 | + } else { |
| 304 | + String url = redirect_uri + "#" + "error=unsupported_response_type"; |
| 305 | + return ResponseEntity.status(HttpStatus.FOUND).header("Location", url).build(); |
| 306 | + } |
305 | 307 | }
|
306 |
| - } else { |
307 |
| - log.info("wrong user and password combination"); |
308 |
| - return response401(); |
309 | 308 | }
|
| 309 | + log.info("wrong user and password combination"); |
| 310 | + return response401(); |
310 | 311 | }
|
311 | 312 | }
|
312 | 313 |
|
|
0 commit comments