Skip to content

Commit 892b87a

Browse files
authored
feat(jans-auth-server): java docs for ssa (#2995)
1 parent d19b13a commit 892b87a

10 files changed

+370
-3
lines changed

jans-auth-server/server/src/main/java/io/jans/as/server/ssa/ws/rs/SsaContextBuilder.java

+18
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,28 @@
1414
import jakarta.inject.Named;
1515
import jakarta.servlet.http.HttpServletRequest;
1616

17+
/**
18+
* Provides builder methods for SSA
19+
*/
1720
@Stateless
1821
@Named
1922
public class SsaContextBuilder {
2023

24+
/**
25+
* ModifySsaResponseContext instance for use in the SSA custom script call.
26+
* <p>
27+
* Method was created with the purpose of passing unit tests, since when instantiating ModifySsaResponseContext
28+
* it internally call {@link io.jans.service.cdi.util.CdiUtil} and cannot be mocked
29+
* </p>
30+
*
31+
* @param httpRequest Http request
32+
* @param grant Grant type
33+
* @param client Client
34+
* @param appConfiguration App configuration
35+
* @param attributeService Attribute service
36+
* @return New instance of {@link ModifySsaResponseContext}
37+
*/
38+
@Deprecated
2139
public ModifySsaResponseContext buildModifySsaResponseContext(HttpServletRequest httpRequest, AuthorizationGrant grant,
2240
Client client, AppConfiguration appConfiguration, AttributeService attributeService) {
2341
return new ModifySsaResponseContext(httpRequest, grant, client, appConfiguration, attributeService);

jans-auth-server/server/src/main/java/io/jans/as/server/ssa/ws/rs/SsaJsonService.java

+35
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,49 @@
2222

2323
import static io.jans.as.model.ssa.SsaRequestParam.*;
2424

25+
/**
26+
* Provides json utilities for SSA
27+
*/
2528
@Stateless
2629
@Named
2730
public class SsaJsonService {
2831

2932
@Inject
3033
private AppConfiguration appConfiguration;
3134

35+
/**
36+
* Convert to json string from jsonObject.
37+
*
38+
* @param jsonObject Json object to convert
39+
* @return Json string
40+
* @throws JSONException If an error is found when converting.
41+
*/
3242
public String jsonObjectToString(JSONObject jsonObject) throws JSONException {
3343
return jsonObject.toString(4).replace("\\/", "/");
3444
}
3545

46+
/**
47+
* Convert to json string from jsonArray.
48+
*
49+
* @param jsonArray Json array to convert
50+
* @return Json string
51+
* @throws JSONException If an error is found when converting.
52+
*/
3653
public String jsonArrayToString(JSONArray jsonArray) throws JSONException {
3754
return jsonArray.toString(4).replace("\\/", "/");
3855
}
3956

57+
/**
58+
* Convert to JSONArray from ssaList with structure SSA.
59+
*
60+
* <p>
61+
* Method generates the SSA structure to add them to a json array.
62+
* </p>
63+
*
64+
* @param ssaList List of SSA
65+
* @return Json array
66+
* @throws JSONException If an error is found when converting.
67+
*/
4068
public JSONArray getJSONArray(List<Ssa> ssaList) throws JSONException {
4169
JSONArray jsonArray = new JSONArray();
4270
if (ssaList == null) {
@@ -67,6 +95,13 @@ public JSONArray getJSONArray(List<Ssa> ssaList) throws JSONException {
6795
return jsonArray;
6896
}
6997

98+
/**
99+
* Convert to JSON using jwt.
100+
*
101+
* @param jwt json web token of SSA
102+
* @return Json object.
103+
* @throws JSONException If an error is found when converting.
104+
*/
70105
public JSONObject getJSONObject(String jwt) throws JSONException {
71106
JSONObject responseJsonObject = new JSONObject();
72107
Util.addToJSONObjectIfNotNull(responseJsonObject, SSA.getName(), jwt);

jans-auth-server/server/src/main/java/io/jans/as/server/ssa/ws/rs/SsaRestWebService.java

+40
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@
1212
import jakarta.ws.rs.core.MediaType;
1313
import jakarta.ws.rs.core.Response;
1414

15+
/**
16+
* Interface to handle all SSA REST web services.
17+
*/
1518
public interface SsaRestWebService {
1619

20+
/**
21+
* Create SSA for the organization with "expiration" (optional).
22+
*
23+
* @param requestParams Valid json
24+
* @param httpRequest Http request object
25+
* @return {@link Response} with status {@code 201 (Created)} and with body the ssa token,
26+
* or with status {@code 401 (Unauthorized)} if unauthorized access request,
27+
* or with status {@code 500 (Internal Server Error)} if internal error occurred.
28+
*/
1729
@POST
1830
@Path("/ssa")
1931
@Produces({MediaType.APPLICATION_JSON})
@@ -22,6 +34,16 @@ Response create(
2234
@Context HttpServletRequest httpRequest
2335
);
2436

37+
/**
38+
* Get list of SSA based on "jti" or "org_id" filter.
39+
*
40+
* @param jti Unique identifier
41+
* @param orgId Organization ID
42+
* @param httpRequest Http request
43+
* @return the {@link Response} with status {@code 200 (Ok)} and with body the ssa list,
44+
* or with status {@code 401 (Unauthorized)} if unauthorized access request,
45+
* or with status {@code 500 (Internal Server Error)} if internal error occurred.
46+
*/
2547
@GET
2648
@Path("/ssa")
2749
@Produces({MediaType.APPLICATION_JSON})
@@ -32,11 +54,29 @@ Response get(
3254
@Context HttpServletRequest httpRequest
3355
);
3456

57+
/**
58+
* Validate existing active SSA based on "jti".
59+
*
60+
* @param jti Unique identifier
61+
* @return {@link Response} with status {@code 200 (Ok)} if is was validated successfully,
62+
* or with status {@code 401 (Unauthorized)} if unauthorized access request,
63+
* or with status {@code 500 (Internal Server Error)} if internal error occurred.
64+
*/
3565
@HEAD
3666
@Path("/ssa")
3767
@Produces({MediaType.APPLICATION_JSON})
3868
Response validate(@HeaderParam("jti") String jti);
3969

70+
/**
71+
* Revokes existing active SSA based on "jti" or "org_id".
72+
*
73+
* @param jti Unique identifier
74+
* @param orgId Organization ID
75+
* @param httpRequest Http request
76+
* @return the {@link Response} with status {@code 200 (Ok)} if it was revoked successfully,
77+
* or with status {@code 401 (Unauthorized)} if unauthorized access request,
78+
* or with status {@code 500 (Internal Server Error)} if internal error occurred.
79+
*/
4080
@DELETE
4181
@Path("/ssa")
4282
@Produces({MediaType.APPLICATION_JSON})

jans-auth-server/server/src/main/java/io/jans/as/server/ssa/ws/rs/SsaRestWebServiceImpl.java

+44
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import jakarta.ws.rs.Path;
1616
import jakarta.ws.rs.core.Response;
1717

18+
/**
19+
* Implements all methods of the {@link SsaRestWebService} interface.
20+
*/
1821
@Path("/")
1922
public class SsaRestWebServiceImpl implements SsaRestWebService {
2023

@@ -30,21 +33,62 @@ public class SsaRestWebServiceImpl implements SsaRestWebService {
3033
@Inject
3134
private SsaRevokeAction ssaRevokeAction;
3235

36+
/**
37+
* Creates an SSA from the requested parameters.
38+
* <p>
39+
* Method calls the action where the SSA creation logic is implemented.
40+
* <p/>
41+
*
42+
* @param requestParams Valid json
43+
* @param httpRequest Http request object
44+
* @return {@link Response} with status {@code 201} (Created) and with body the ssa token (jwt).
45+
*/
3346
@Override
3447
public Response create(String requestParams, HttpServletRequest httpRequest) {
3548
return ssaCreateAction.create(requestParams, httpRequest);
3649
}
3750

51+
/**
52+
* Get existing active SSA based on "jti" or "org_id".
53+
* <p>
54+
* Method calls the action where the SSA get logic is implemented.
55+
* <p/>
56+
*
57+
* @param jti Unique identifier
58+
* @param orgId Organization ID
59+
* @param httpRequest Http request
60+
* @return {@link Response} with status {@code 200 (Ok)} and with body List of SSA.
61+
*/
3862
@Override
3963
public Response get(Boolean softwareRoles, String jti, Long orgId, HttpServletRequest httpRequest) {
4064
return ssaGetAction.get(softwareRoles, jti, orgId, httpRequest);
4165
}
4266

67+
/**
68+
* Validate existing active SSA based on "jti".
69+
* <p>
70+
* Method calls the action where the SSA validate logic is implemented.
71+
* <p/>
72+
*
73+
* @param jti Unique identifier
74+
* @return {@link Response} with status {@code 200} (Ok) if SSA has been validated.
75+
*/
4376
@Override
4477
public Response validate(String jti) {
4578
return ssaValidateAction.validate(jti);
4679
}
4780

81+
/**
82+
* Revoked existing active SSA based on "jti" or "org_id".
83+
* <p>
84+
* Method calls the action where the SSA revoke logic is implemented.
85+
* </p>
86+
*
87+
* @param jti Unique identifier
88+
* @param orgId Organization ID
89+
* @param httpRequest Http request
90+
* @return {@link Response} with status {@code 200 (Ok)} if SSA has been revoked.
91+
*/
4892
@Override
4993
public Response revoke(String jti, Long orgId, HttpServletRequest httpRequest) {
5094
return ssaRevokeAction.revoke(jti, orgId, httpRequest);

jans-auth-server/server/src/main/java/io/jans/as/server/ssa/ws/rs/SsaRestWebServiceValidator.java

+28-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
import jakarta.ejb.Stateless;
1616
import jakarta.inject.Inject;
1717
import jakarta.inject.Named;
18+
import jakarta.ws.rs.WebApplicationException;
1819
import jakarta.ws.rs.core.Response;
1920
import org.slf4j.Logger;
2021

2122
import java.util.Arrays;
2223
import java.util.List;
2324
import java.util.stream.Collectors;
2425

26+
/**
27+
* Provides methods to validate different params about SSA.
28+
*/
2529
@Named
2630
@Stateless
2731
public class SsaRestWebServiceValidator {
@@ -38,7 +42,14 @@ public class SsaRestWebServiceValidator {
3842
@Inject
3943
private ScopeService scopeService;
4044

41-
public Client getClientFromSession() {
45+
/**
46+
* Get client from session
47+
*
48+
* @return {@link Client} if obtained.
49+
* @throws WebApplicationException with status {@code 401} and key <b>INVALID_CLIENT</b> if the client cannot
50+
* be obtained.
51+
*/
52+
public Client getClientFromSession() throws WebApplicationException {
4253
SessionClient sessionClient = identity.getSessionClient();
4354
if (sessionClient != null) {
4455
log.debug("Client: {}, obtained from session", sessionClient.getClient().getClientId());
@@ -47,13 +58,27 @@ public Client getClientFromSession() {
4758
throw errorResponseFactory.createBadRequestException(SsaErrorResponseType.INVALID_CLIENT, "Invalid client");
4859
}
4960

50-
public void checkScopesPolicy(Client client, String scope) {
61+
/**
62+
* Check if the client has the given scope.
63+
*
64+
* @param client Client to check scope
65+
* @param scope Scope to validate
66+
* @throws WebApplicationException with status {@code 401} and key <b>UNAUTHORIZED_CLIENT</b> if you don't have the scope.
67+
*/
68+
public void checkScopesPolicy(Client client, String scope) throws WebApplicationException {
5169
List<String> scopes = scopeService.getScopeIdsByDns(Arrays.stream(client.getScopes()).collect(Collectors.toList()));
5270
if (!scopes.contains(scope))
5371
throw errorResponseFactory.createWebApplicationException(Response.Status.UNAUTHORIZED, SsaErrorResponseType.UNAUTHORIZED_CLIENT, "Unauthorized client");
5472
}
5573

56-
public void checkScopesPolicy(Client client, List<String> scopeList) {
74+
/**
75+
* Check if the client has at least one scope from the list of scopes.
76+
*
77+
* @param client Client to check scope
78+
* @param scopeList List of scope to validated
79+
* @throws WebApplicationException with status {@code 401} and key <b>UNAUTHORIZED_CLIENT</b> if you don't have the scope.
80+
*/
81+
public void checkScopesPolicy(Client client, List<String> scopeList) throws WebApplicationException {
5782
if (client == null || scopeList == null || scopeList.isEmpty()) {
5883
throw errorResponseFactory.createWebApplicationException(Response.Status.UNAUTHORIZED, SsaErrorResponseType.UNAUTHORIZED_CLIENT, "Unauthorized client");
5984
}

0 commit comments

Comments
 (0)