Skip to content

Commit

Permalink
feat(jans-config-api): new functionality and swagger fix (#1802)
Browse files Browse the repository at this point in the history
* fix(jans-config-api): fixed swagger link

* fix(jans-config-api): swagger spec change to add missing attributes for Client

* fix(jans-config-api): swagger spec change to add missing attributes for Client

* feat9jans-config-api): fixed GluuAtrribute usageType enum in spec

* feat9jans-config-api): jansStatus attribute enum value rectification in spec for User management

* feat(jans-config-api): implemented fetch custom script based on script name issue#1754
  • Loading branch information
pujavs authored Jul 14, 2022
1 parent e389363 commit fc81d1d
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 31 deletions.
39 changes: 34 additions & 5 deletions jans-config-api/docs/jans-config-api-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,35 @@ paths:
$ref: '#/components/responses/InternalServerError'
security:
- oauth2: [https://jans.io/oauth/config/scripts.write]
/jans-config-api/api/v1/config/scripts/name/{name}:
parameters:
- name: name
in: path
required: true
description: Script name.
schema:
type: string
get:
summary: Fetch custom script by name.
description: Fetch custom script by name.
operationId: get-custom-script-by-name
tags:
- Custom Scripts
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/CustomScript'
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
security:
- oauth2: [https://jans.io/oauth/config/scripts.readonly]

/jans-config-api/api/v1/config/scripts/type/{type}:
parameters:
- schema:
Expand Down Expand Up @@ -4855,7 +4884,7 @@ components:
items:
type: string
enum:
- openid
- OPENID
claimName:
type: string
seeAlso:
Expand Down Expand Up @@ -6892,10 +6921,10 @@ components:
type: string
description: User status
enum:
- ACTIVE
- INACTIVE
- EXPIRED
- REGISTER
- active
- inactive
- expired
- register
userId:
description: A domain issued and managed identifier for the user.
type: string
Expand Down
4 changes: 2 additions & 2 deletions jans-config-api/profiles/local/test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ test.scopes=https://jans.io/oauth/config/acrs.readonly https://jans.io/oauth/con
# jans.server
token.endpoint=https://jans.server1/jans-auth/restv1/token
token.grant.type=client_credentials
test.client.id=1800.fbeaf31b-16dc-405f-97f6-001eeb622f18
test.client.secret=6OB4BxtxVd6I
test.client.id=1800.d2d3ab98-e018-4a75-bc1d-15b5ac8cb455
test.client.secret=oGjYGFjhBr97
test.issuer=https://jans.server1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.jans.model.custom.script.model.CustomScript;
import io.jans.service.custom.CustomScriptService;
import io.jans.util.StringHelper;
import org.slf4j.Logger;

import com.github.fge.jsonpatch.JsonPatchException;

Expand All @@ -39,9 +38,6 @@ public class CustomScriptResource extends ConfigBaseResource {
private static final String CUSTOM_SCRIPT = "custom script";
private static final String PATH_SEPARATOR = "/";

@Inject
Logger log;

@Inject
CustomScriptService customScriptService;

Expand All @@ -55,9 +51,31 @@ public class CustomScriptResource extends ConfigBaseResource {
@ProtectedApi(scopes = { ApiAccessConstants.SCRIPTS_READ_ACCESS })
public Response getAllCustomScripts() {
List<CustomScript> customScripts = customScriptService.findAllCustomScripts(null);
log.debug("Custom Scripts:{}", customScripts);
logger.debug("Custom Scripts:{}", customScripts);
return Response.ok(customScripts).build();
}

/***
* Method to fetch a custom script based on name
*
* @param name - name of custom script
* @throws NotAuthorizedException
*/
@GET
@Path(PATH_SEPARATOR + ApiConstants.NAME + ApiConstants.NAME_PARAM_PATH)
@ProtectedApi(scopes = { ApiAccessConstants.SCRIPTS_READ_ACCESS })
public Response getCustomScriptByName(@PathParam(ApiConstants.NAME) @NotNull String name) {

if (logger.isDebugEnabled()) {
logger.debug("Custom Script to be fetched based on type - name:{} ", escapeLog(name));
}

CustomScript customScript = customScriptService.getScriptByDisplayName(name);
checkResourceNotNull(customScript, CUSTOM_SCRIPT);

logger.debug("Custom Script Fetched based on name:{}, customScript:{}", name, customScript);
return Response.ok(customScript).build();
}

/***
* Method to fetch a custom script by type
Expand All @@ -72,9 +90,14 @@ public Response getAllCustomScripts() {
public Response getCustomScriptsByTypePattern(@PathParam(ApiConstants.TYPE) @NotNull String type,
@DefaultValue("") @QueryParam(value = ApiConstants.PATTERN) String pattern,
@DefaultValue(DEFAULT_LIST_SIZE) @QueryParam(value = ApiConstants.LIMIT) int limit) {

if (logger.isDebugEnabled()) {
logger.debug("Custom Script to be fetched based on type - type:{} , pattern:{}, limit:{} ", escapeLog(type), escapeLog(pattern), escapeLog(limit));
}

List<CustomScript> customScripts = this.customScriptService.findScriptByPatternAndType(pattern,
CustomScriptType.getByValue(type.toLowerCase()), limit);
log.debug("Custom Scripts fetched :{}", customScripts);
logger.debug("Custom Scripts fetched :{}", customScripts);
if (customScripts != null && !customScripts.isEmpty())
return Response.ok(customScripts).build();
else
Expand All @@ -92,8 +115,8 @@ public Response getCustomScriptsByTypePattern(@PathParam(ApiConstants.TYPE) @Not
@Path(PATH_SEPARATOR + ApiConstants.INUM + PATH_SEPARATOR + ApiConstants.INUM_PATH)
@ProtectedApi(scopes = { ApiAccessConstants.SCRIPTS_READ_ACCESS })
public Response getCustomScriptByInum(@PathParam(ApiConstants.INUM) @NotNull String inum) {
if (log.isDebugEnabled()) {
log.debug("Custom Script to be fetched - inum:{} ", escapeLog(inum));
if (logger.isDebugEnabled()) {
logger.debug("Custom Script to be fetched - inum:{} ", escapeLog(inum));
}
CustomScript script = null;
try {
Expand All @@ -104,7 +127,7 @@ public Response getCustomScriptByInum(@PathParam(ApiConstants.INUM) @NotNull Str
return Response.status(Response.Status.NOT_FOUND).build();
}
}
log.debug("Custom Script fetched by inum :{}", script);
logger.debug("Custom Script fetched by inum :{}", script);
return Response.ok(script).build();
}

Expand All @@ -118,7 +141,7 @@ public Response getCustomScriptByInum(@PathParam(ApiConstants.INUM) @NotNull Str
@POST
@ProtectedApi(scopes = { ApiAccessConstants.SCRIPTS_WRITE_ACCESS })
public Response createScript(@Valid CustomScript customScript) {
log.debug("Custom Script to create - customScript:{}", customScript);
logger.debug("Custom Script to create - customScript:{}", customScript);
Objects.requireNonNull(customScript, "Attempt to create null custom script");
String inum = customScript.getInum();
if (StringHelper.isEmpty(inum)) {
Expand All @@ -127,7 +150,7 @@ public Response createScript(@Valid CustomScript customScript) {
customScript.setDn(customScriptService.buildDn(inum));
customScript.setInum(inum);
customScriptService.add(customScript);
log.debug("Custom Script added {}", customScript);
logger.debug("Custom Script added {}", customScript);
return Response.status(Response.Status.CREATED).entity(customScript).build();
}

Expand All @@ -142,11 +165,11 @@ public Response createScript(@Valid CustomScript customScript) {
@PUT
@ProtectedApi(scopes = { ApiAccessConstants.SCRIPTS_WRITE_ACCESS })
public Response updateScript(@Valid @NotNull CustomScript customScript) {
log.debug("Custom Script to update - customScript:{}", customScript);
logger.debug("Custom Script to update - customScript:{}", customScript);
CustomScript existingScript = customScriptService.getScriptByInum(customScript.getInum());
checkResourceNotNull(existingScript, CUSTOM_SCRIPT);
customScript.setInum(existingScript.getInum());
log.debug("Custom Script updated {}", customScript);
logger.debug("Custom Script updated {}", customScript);
customScriptService.update(customScript);
return Response.ok(customScript).build();
}
Expand All @@ -163,14 +186,14 @@ public Response updateScript(@Valid @NotNull CustomScript customScript) {
@ProtectedApi(scopes = { ApiAccessConstants.SCRIPTS_DELETE_ACCESS })
public Response deleteScript(@PathParam(ApiConstants.INUM) @NotNull String inum) {
try {
if (log.isDebugEnabled()) {
log.debug("Custom Script Resource to delete - inum:{}", escapeLog(inum));
if (logger.isDebugEnabled()) {
logger.debug("Custom Script Resource to delete - inum:{}", escapeLog(inum));
}
CustomScript existingScript = customScriptService.getScriptByInum(inum);
customScriptService.remove(existingScript);
return Response.noContent().build();
} catch (Exception ex) {
log.info("Error deleting script by inum " + inum, ex);
logger.info("Error deleting script by inum " + inum, ex);
throw new NotFoundException(getNotFoundError(CUSTOM_SCRIPT));
}
}
Expand All @@ -193,8 +216,8 @@ public Response deleteScript(@PathParam(ApiConstants.INUM) @NotNull String inum)
@Path(ApiConstants.INUM_PATH)
public Response patchAtribute(@PathParam(ApiConstants.INUM) @NotNull String inum, @NotNull String pathString)
throws JsonPatchException, IOException {
if (log.isDebugEnabled()) {
log.debug("Custom Script Resource to patch - inum:{} , pathString:{}", escapeLog(inum),
if (logger.isDebugEnabled()) {
logger.debug("Custom Script Resource to patch - inum:{} , pathString:{}", escapeLog(inum),
escapeLog(pathString));
}

Expand All @@ -204,7 +227,7 @@ public Response patchAtribute(@PathParam(ApiConstants.INUM) @NotNull String inum
customScriptService.update(existingScript);
existingScript = customScriptService.getScriptByInum(inum);

log.debug(" Custom Script Resource after patch - existingScript:{}", existingScript);
logger.debug(" Custom Script Resource after patch - existingScript:{}", existingScript);
return Response.ok(existingScript).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,28 @@ Feature: Verify Custom Script configuration endpoint
And print response
And assert response.length != null


@scripts-get-custom-script-by-name
Scenario: Fetch all custom scripts by name
Given url mainUrl
And header Authorization = 'Bearer ' + accessToken
When method GET
Then status 200
And print response
And assert response.length != null
And print response[0]
And print 'Script inum = '+response[0].name
And assert response[0].name != null
And print 'Script Name = '+response[0].name
And print 'Fetching script by name' + '-' +response[0].name
Given url mainUrl + '/name' + '/'+response[0].name
And header Authorization = 'Bearer ' + accessToken
When method GET
Then status 200
And print response
And assert response.length != null

@scripts-get-person-custom-scripts
Scenario: Fetch all person custom scripts without bearer token
Scenario: Fetch all person custom script
Given url mainUrl + '/type'
And path 'person_authentication'
And header Authorization = 'Bearer ' + accessToken
Expand All @@ -34,7 +53,7 @@ Feature: Verify Custom Script configuration endpoint


@scripts-get-introspection-custom-scripts
Scenario: Fetch all introspection scripts without bearer token
Scenario: Fetch all introspection scripts
Given url mainUrl + '/type'
And path 'introspection'
And header Authorization = 'Bearer ' + accessToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"postLogoutRedirectUris": [
],
"redirectUris": [
"http://localhost:8080"
],
"scopes": [
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ When method GET
Then status 200
And print response


@ignore
@CreateUpdateDelete
Scenario: Create new OpenId Connect Client
Given url mainUrl
Expand Down Expand Up @@ -105,7 +105,7 @@ When method GET
Then status 404
And print response


@ignore
Scenario: Patch openid connect client
Given url mainUrl
And header Authorization = 'Bearer ' + accessToken
Expand Down

0 comments on commit fc81d1d

Please sign in to comment.