Skip to content

Commit 034f7da

Browse files
Merge pull request #67 from authlete/native-sso
Native SSO Support
2 parents bc79c02 + 3095d0a commit 034f7da

File tree

12 files changed

+1054
-26
lines changed

12 files changed

+1054
-26
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414

15-
<authlete.java.common.version>4.12</authlete.java.common.version>
16-
<authlete.java.jaxrs.version>2.80</authlete.java.jaxrs.version>
15+
<authlete.java.common.version>4.19</authlete.java.common.version>
16+
<authlete.java.jaxrs.version>2.86</authlete.java.jaxrs.version>
1717
<authlete.cbor.version>1.18</authlete.cbor.version>
1818
<javax.servlet-api.version>3.0.1</javax.servlet-api.version>
1919
<jersey.version>2.30.1</jersey.version>

src/main/java/com/authlete/jaxrs/server/api/AuthorizationDecisionEndpoint.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2016-2019 Authlete, Inc.
2+
* Copyright (C) 2016-2025 Authlete, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
2020
import java.util.ArrayList;
2121
import java.util.Arrays;
2222
import java.util.Date;
23-
import java.util.List;
2423
import javax.servlet.http.HttpServletRequest;
2524
import javax.servlet.http.HttpSession;
2625
import javax.ws.rs.Consumes;
@@ -110,7 +109,8 @@ public Response post(
110109
// Implementation of AuthorizationDecisionHandlerSpi.
111110
AuthorizationDecisionHandlerSpi spi =
112111
new AuthorizationDecisionHandlerSpiImpl(
113-
parameters, user, authTime, idTokenClaims, acrs, client);
112+
parameters, user, authTime, idTokenClaims, acrs, client,
113+
session.getId());
114114

115115
// Handle the end-user's decision.
116116
return handle(AuthleteApiFactory.getDefaultApi(), spi, params);

src/main/java/com/authlete/jaxrs/server/api/AuthorizationDecisionHandlerSpiImpl.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2016-2022 Authlete, Inc.
2+
* Copyright (C) 2016-2025 Authlete, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -104,6 +104,12 @@ class AuthorizationDecisionHandlerSpiImpl extends AuthorizationDecisionHandlerSp
104104
private Client mClient;
105105

106106

107+
/**
108+
* The session ID of the user's authentication session.
109+
*/
110+
private String mSessionId;
111+
112+
107113
/**
108114
* Constructor with a request from the form in the authorization page.
109115
*
@@ -114,7 +120,8 @@ class AuthorizationDecisionHandlerSpiImpl extends AuthorizationDecisionHandlerSp
114120
*/
115121
public AuthorizationDecisionHandlerSpiImpl(
116122
MultivaluedMap<String, String> parameters, User user,
117-
Date userAuthenticatedAt, String idTokenClaims, String[] acrs, Client client)
123+
Date userAuthenticatedAt, String idTokenClaims, String[] acrs,
124+
Client client, String sessionId)
118125
{
119126
// If the end-user clicked the "Authorize" button, "authorized"
120127
// is contained in the request.
@@ -159,6 +166,9 @@ public AuthorizationDecisionHandlerSpiImpl(
159166

160167
// The client associated with the request.
161168
mClient = client;
169+
170+
// The session ID of the user's authentication session.
171+
mSessionId = sessionId;
162172
}
163173

164174

@@ -255,7 +265,7 @@ private static Map<String, Object> parseJson(String json)
255265

256266
try
257267
{
258-
return (Map<String, Object>)Utils.fromJson(json, Map.class);
268+
return Utils.fromJson(json, Map.class);
259269
}
260270
catch (Exception e)
261271
{
@@ -483,4 +493,11 @@ public Object getVerifiedClaims(String subject, Object verifiedClaimsRequest)
483493
// of the request from the available datasets.
484494
return new VerifiedClaimsBuilder(verifiedClaimsRequest, datasets).build();
485495
}
496+
497+
498+
@Override
499+
public String getSessionId()
500+
{
501+
return mSessionId;
502+
}
486503
}

src/main/java/com/authlete/jaxrs/server/api/JwtAuthzGrantProcessor.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022 Authlete, Inc.
2+
* Copyright (C) 2022-2025 Authlete, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,10 +17,13 @@
1717
package com.authlete.jaxrs.server.api;
1818

1919

20+
import java.util.Map;
21+
import javax.servlet.http.HttpServletRequest;
2022
import javax.ws.rs.WebApplicationException;
2123
import javax.ws.rs.core.CacheControl;
2224
import javax.ws.rs.core.MediaType;
2325
import javax.ws.rs.core.Response;
26+
import javax.ws.rs.core.Response.ResponseBuilder;
2427
import javax.ws.rs.core.Response.Status;
2528
import com.authlete.common.api.AuthleteApi;
2629
import com.authlete.common.dto.TokenCreateRequest;
@@ -66,13 +69,19 @@
6669
class JwtAuthzGrantProcessor
6770
{
6871
private final AuthleteApi mAuthleteApi;
72+
private final HttpServletRequest mRequest;
6973
private final TokenResponse mTokenResponse;
74+
private final Map<String, Object> mHeaders;
7075

7176

72-
public JwtAuthzGrantProcessor(AuthleteApi authleteApi, TokenResponse tokenResponse)
77+
public JwtAuthzGrantProcessor(
78+
AuthleteApi authleteApi, HttpServletRequest request,
79+
TokenResponse tokenResponse, Map<String, Object> headers)
7380
{
7481
mAuthleteApi = authleteApi;
82+
mRequest = request;
7583
mTokenResponse = tokenResponse;
84+
mHeaders = headers;
7685
}
7786

7887

@@ -326,12 +335,29 @@ private Response toJsonResponse(Status status, String content)
326335
cacheControl.setNoCache(true);
327336
cacheControl.setNoStore(true);
328337

329-
return Response
330-
.status(status)
338+
ResponseBuilder builder = Response.status(status)
331339
.type(MediaType.APPLICATION_JSON_TYPE)
332340
.cacheControl(cacheControl)
333341
.entity(content)
334-
.build();
342+
;
343+
344+
addResponseHeaders(builder, mHeaders);
345+
346+
return builder.build();
347+
}
348+
349+
350+
private static void addResponseHeaders(ResponseBuilder builder, Map<String, Object> headers)
351+
{
352+
if (headers == null)
353+
{
354+
return;
355+
}
356+
357+
for (Map.Entry<String, Object> header : headers.entrySet())
358+
{
359+
builder.header(header.getKey(), header.getValue());
360+
}
335361
}
336362

337363

0 commit comments

Comments
 (0)