Skip to content

Commit a3f9145

Browse files
authored
feat(jans-config-api): endpoint to get UmaResource based on clientId and swagger changes (#1912)
* bug(jans-config-api): fixed swagger format issue * fix(jans-config-api): fixed due to couchbase clustter change * feat(jans-config-api): new endpoint to get UmaResource based on associatedClient * fix(jans-config-api): swagger spec fix for client attributes * fix(jans-config-api): reverted the local test properties * test(jans-config-api): commented test case
1 parent 8021ae3 commit a3f9145

File tree

7 files changed

+263
-18
lines changed

7 files changed

+263
-18
lines changed

jans-config-api/common/src/main/java/io/jans/configapi/util/ApiConstants.java

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ private ApiConstants() {}
7474
public static final String ORG = "/org";
7575
public static final String SERVER_STAT = "/server-stat";
7676
public static final String USERNAME_PATH = "/{username}";
77+
public static final String CLIENTID_PATH = "/{clientId}";
7778

7879
public static final String LIMIT = "limit";
7980
public static final String START_INDEX = "startIndex";
@@ -86,6 +87,7 @@ private ApiConstants() {}
8687
public static final String NAME = "name";
8788
public static final String DISPLAY_NAME = "displayName";
8889
public static final String KID = "kid";
90+
public static final String CLIENTID = "clientId";
8991

9092
public static final String ALL = "all";
9193
public static final String ACTIVE = "active";

jans-config-api/docs/jans-config-api-swagger.yaml

+38-6
Original file line numberDiff line numberDiff line change
@@ -2168,6 +2168,38 @@ paths:
21682168
description: Internal Server Error
21692169
security:
21702170
- oauth2: [https://jans.io/oauth/config/uma/resources.readonly]
2171+
/jans-config-api/api/v1/uma/resources/{clientId}:
2172+
parameters:
2173+
- name: clientId
2174+
in: path
2175+
required: true
2176+
description: Client ID.
2177+
schema:
2178+
type: string
2179+
get:
2180+
tags:
2181+
- OAuth - UMA Resources
2182+
summary: Fetch uma resources by client id.
2183+
description: Fetch uma resources by client id.
2184+
operationId: get-oauth-uma-resources-by-clientid
2185+
responses:
2186+
'200':
2187+
description: OK
2188+
content:
2189+
application/json:
2190+
schema:
2191+
title: UMA Resource list.
2192+
description: List of UMA Resource.
2193+
items:
2194+
$ref: '#/components/schemas/UmaResource'
2195+
'401':
2196+
$ref: '#/components/responses/Unauthorized'
2197+
'404':
2198+
$ref: '#/components/responses/NotFound'
2199+
'500':
2200+
description: Internal Server Error
2201+
security:
2202+
- oauth2: [https://jans.io/oauth/config/uma/resources.readonly]
21712203
delete:
21722204
tags:
21732205
- OAuth - UMA Resources
@@ -5122,27 +5154,27 @@ components:
51225154
requirePar:
51235155
description: boolean value to indicate of Pushed Authorisation Request(PAR)is required.
51245156
type: boolean
5125-
authorizationSignedResponseAlg:
5157+
jansAuthSignedRespAlg:
51265158
description: JWS alg algorithm JWA required for signing authorization responses.
51275159
type: string
5128-
authorizationEncryptedResponseAlg:
5160+
jansAuthEncRespAlg:
51295161
description: JWE alg algorithm JWA required for encrypting authorization responses.
51305162
type: string
5131-
authorizationEncryptedResponseEnc:
5163+
jansAuthEncRespEnc:
51325164
description: JWE enc algorithm JWA required for encrypting auhtorization responses.
51335165
type: string
5134-
publicSubjectIdentifierAttribute:
5166+
jansSubAttr:
51355167
description: custom subject identifier attribute.
51365168
type: string
51375169
redirectUrisRegex:
51385170
description: If set, redirectUri must match to this regexp
51395171
type: string
5140-
authorizedAcrValues:
5172+
jansAuthorizedAcr:
51415173
description: List of thentication Context Class Reference (ACR) that must exist.
51425174
type: array
51435175
items:
51445176
type: string
5145-
defaultPromptLogin:
5177+
jansDefaultPromptLogin:
51465178
description: sets prompt=login to the authorization request, which causes the authorization server to force the user to sign in again before it will show the authorization prompt.
51475179
type: boolean
51485180

jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/ClientsResource.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ public Response getOpenIdClientByInum(@PathParam(ApiConstants.INUM) @NotNull Str
109109
@ProtectedApi(scopes = { ApiAccessConstants.OPENID_CLIENTS_WRITE_ACCESS })
110110
public Response createOpenIdConnect(@Valid Client client) throws EncryptionException {
111111
if (logger.isDebugEnabled()) {
112-
logger.debug("Client details to be added - client:{}", escapeLog(client));
112+
logger.debug("Client to be added - client:{}, client.getAttributes():{}, client.getCustomAttributes():{}", escapeLog(client), escapeLog(client.getAttributes()), escapeLog(client.getCustomAttributes()));
113113
}
114+
114115
String inum = client.getClientId();
115116
if (inum == null || inum.isEmpty() || inum.isBlank()) {
116117
inum = inumService.generateClientInum();
@@ -132,7 +133,7 @@ public Response createOpenIdConnect(@Valid Client client) throws EncryptionExcep
132133
client.setDeletable(client.getClientSecretExpiresAt() != null);
133134
ignoreCustomObjectClassesForNonLDAP(client);
134135

135-
logger.debug("Final Client details to be added - client:{}", client);
136+
logger.trace("Final Client details to be added - client:{}, client.getAttributes():{}, client.getCustomAttributes():{}", client, client.getAttributes(), client.getCustomAttributes());
136137
clientService.addClient(client);
137138
Client result = clientService.getClientByInum(inum);
138139
result.setClientSecret(encryptionService.decrypt(result.getClientSecret()));

jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/UmaResourcesResource.java

+30-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.github.fge.jsonpatch.JsonPatchException;
1010
import io.jans.as.model.uma.persistence.UmaResource;
1111
import io.jans.configapi.core.rest.ProtectedApi;
12+
import io.jans.configapi.service.auth.ClientService;
1213
import io.jans.configapi.service.auth.UmaResourceService;
1314
import io.jans.configapi.util.ApiAccessConstants;
1415
import io.jans.configapi.util.ApiConstants;
@@ -40,17 +41,17 @@ public class UmaResourcesResource extends ConfigBaseResource {
4041
private static final String UMA_RESOURCE = "Uma resource";
4142

4243
@Inject
43-
Logger log;
44+
UmaResourceService umaResourceService;
4445

4546
@Inject
46-
UmaResourceService umaResourceService;
47+
ClientService clientService;
4748

4849
@GET
4950
@ProtectedApi(scopes = { ApiAccessConstants.UMA_RESOURCES_READ_ACCESS })
5051
public Response fetchUmaResources(
5152
@DefaultValue(DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit,
5253
@DefaultValue("") @QueryParam(value = ApiConstants.PATTERN) String pattern) {
53-
log.debug("UMA_RESOURCE to be fetched - limit = " + limit + " , pattern = " + pattern);
54+
logger.debug("UMA_RESOURCE to be fetched - limit:{}, pattern:{}", limit, pattern);
5455
final List<UmaResource> resources;
5556
if (!pattern.isEmpty() && pattern.length() >= 2) {
5657
resources = umaResourceService.findResources(pattern, 1000);
@@ -63,15 +64,25 @@ public Response fetchUmaResources(
6364
@GET
6465
@Path(ApiConstants.ID_PATH)
6566
@ProtectedApi(scopes = { ApiAccessConstants.UMA_RESOURCES_READ_ACCESS })
66-
public Response getUmaResourceByImun(@PathParam(value = ApiConstants.ID) @NotNull String id) {
67-
log.debug("UMA_RESOURCE to fetch by id = " + id);
67+
public Response getUmaResourceByInum(@PathParam(value = ApiConstants.ID) @NotNull String id) {
68+
logger.debug("UMA_RESOURCE to fetch by id:{}", id);
6869
return Response.ok(findOrThrow(id)).build();
6970
}
7071

72+
@GET
73+
@Path("/"+ApiConstants.CLIENTID + ApiConstants.CLIENTID_PATH)
74+
@ProtectedApi(scopes = { ApiAccessConstants.UMA_RESOURCES_READ_ACCESS })
75+
public Response getUmaResourceByAssociatedClient(
76+
@PathParam(value = ApiConstants.CLIENTID) @NotNull String associatedClientId) {
77+
logger.debug("UMA_RESOURCE to fetch by associatedClientId:{} ", associatedClientId);
78+
79+
return Response.ok(getUmaResourceByClient(associatedClientId)).build();
80+
}
81+
7182
@POST
7283
@ProtectedApi(scopes = { ApiAccessConstants.UMA_RESOURCES_WRITE_ACCESS })
7384
public Response createUmaResource(@Valid UmaResource umaResource) {
74-
log.debug("UMA_RESOURCE to be added umaResource = " + umaResource);
85+
logger.debug("UMA_RESOURCE to be added umaResource:{}", umaResource);
7586
checkNotNull(umaResource.getName(), AttributeNames.NAME);
7687
checkNotNull(umaResource.getDescription(), AttributeNames.DESCRIPTION);
7788
String id = UUID.randomUUID().toString();
@@ -96,7 +107,7 @@ private UmaResource findOrThrow(String id) {
96107
@PUT
97108
@ProtectedApi(scopes = { ApiAccessConstants.UMA_RESOURCES_WRITE_ACCESS })
98109
public Response updateUmaResource(@Valid UmaResource resource) {
99-
log.debug("UMA_RESOURCE to be upated - umaResource = " + resource);
110+
logger.debug("UMA_RESOURCE to be upated - umaResource:{}", resource);
100111
String id = resource.getId();
101112
checkNotNull(id, AttributeNames.ID);
102113
UmaResource existingResource = findOrThrow(id);
@@ -113,7 +124,7 @@ public Response updateUmaResource(@Valid UmaResource resource) {
113124
@Path(ApiConstants.ID_PATH)
114125
public Response patchResource(@PathParam(ApiConstants.ID) @NotNull String id, @NotNull String pathString)
115126
throws JsonPatchException, IOException {
116-
log.debug("UMA_RESOURCE to be patched - id = " + id + " , pathString = " + pathString);
127+
logger.debug("Patch for id:{} , pathString:{}", id, pathString);
117128
UmaResource existingResource = findOrThrow(id);
118129

119130
existingResource = Jackson.applyPatch(pathString, existingResource);
@@ -125,9 +136,19 @@ public Response patchResource(@PathParam(ApiConstants.ID) @NotNull String id, @N
125136
@Path(ApiConstants.ID_PATH)
126137
@ProtectedApi(scopes = { ApiAccessConstants.UMA_RESOURCES_DELETE_ACCESS })
127138
public Response deleteUmaResource(@PathParam(value = ApiConstants.ID) @NotNull String id) {
128-
log.debug("UMA_RESOURCE to delete - id = " + id);
139+
logger.debug("UMA_RESOURCE to delete - id:{}", id);
129140
UmaResource umaResource = findOrThrow(id);
130141
umaResourceService.remove(umaResource);
131142
return Response.status(Response.Status.NO_CONTENT).build();
132143
}
144+
145+
private List<UmaResource> getUmaResourceByClient(String associatedClientId) {
146+
logger.debug("UMA RESOURCE to be fetched based on associatedClientId:{}", associatedClientId);
147+
148+
// Get client DN
149+
String associatedClientDn = this.clientService.getDnForClient(associatedClientId);
150+
logger.debug("UMA RESOURCE to be fetched based on associatedClientId:{}", associatedClientId);
151+
152+
return umaResourceService.getResourcesByClient(associatedClientDn);
153+
}
133154
}

jans-config-api/server/src/main/java/io/jans/configapi/service/auth/UmaResourceService.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717

1818
import jakarta.enterprise.context.ApplicationScoped;
1919
import jakarta.inject.Inject;
20+
21+
import java.util.Collections;
2022
import java.util.List;
2123

24+
import org.slf4j.Logger;
25+
2226
/**
2327
* @author Yuriy Zabrovarnyy
2428
*/
@@ -31,6 +35,9 @@ public class UmaResourceService {
3135
@Inject
3236
private StaticConfiguration staticConfiguration;
3337

38+
@Inject
39+
private Logger logger;
40+
3441
public void addBranch() {
3542
SimpleBranch branch = new SimpleBranch();
3643
branch.setOrganizationalUnitName("resources");
@@ -49,12 +56,13 @@ public List<UmaResource> findResources(String pattern, int sizeLimit) {
4956
}
5057

5158
public List<UmaResource> findResourcesByName(String name, int sizeLimit) {
59+
5260
if (StringUtils.isNotBlank(name)) {
5361
Filter searchFilter = Filter.createEqualityFilter(AttributeConstants.DISPLAY_NAME, name);
5462
return persistenceEntryManager.findEntries(getDnForResource(null), UmaResource.class, searchFilter,
5563
sizeLimit);
5664
}
57-
return null;
65+
return Collections.emptyList();
5866
}
5967

6068
public List<UmaResource> getAllResources(int sizeLimit) {
@@ -83,6 +91,22 @@ public UmaResource getResourceById(String id) {
8391
return persistenceEntryManager.find(UmaResource.class, dn);
8492
}
8593

94+
public List<UmaResource> getResourcesByClient(String clientDn) {
95+
try {
96+
logger.debug(" Fetch UmaResource based on client - clientDn:{} ", clientDn);
97+
prepareBranch();
98+
99+
if (StringUtils.isNotBlank(clientDn)) {
100+
return persistenceEntryManager.findEntries(getBaseDnForResource(), UmaResource.class,
101+
Filter.createEqualityFilter("jansAssociatedClnt", clientDn));
102+
}
103+
104+
} catch (Exception e) {
105+
logger.error(e.getMessage(), e);
106+
}
107+
return Collections.emptyList();
108+
}
109+
86110
private void prepareBranch() {
87111
if (!persistenceEntryManager.hasBranchesSupport(getDnForResource(null))) {
88112
return;

jans-config-api/server/src/test/resources/feature/openid/clients/clients.feature

+11
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,14 @@ Then status 200
128128
And print response
129129
And assert response.length !=0
130130

131+
@ignore
132+
@CreateUpdateDelete
133+
Scenario: Create new OpenId Connect Client
134+
Given url mainUrl
135+
And header Authorization = 'Bearer ' + accessToken
136+
And request read('openid_clients_create.json')
137+
When method POST
138+
Then status 201
139+
And print response
140+
141+

0 commit comments

Comments
 (0)