From d51ae2421b77dd88f7a1751235200b19f4a0b305 Mon Sep 17 00:00:00 2001 From: pujavs <43700552+pujavs@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:49:20 +0530 Subject: [PATCH] fix(config-api): scope addiotion while client creation (#2714) * feat(config-api): swagger fixes * feat(config-api): swagger fixes * fix(config-api): scope addiotion while client creation --- .../docs/jans-config-api-swagger-auto.yaml | 34 ++++++------ .../plugins/docs/user-mgt-plugin-swagger.yaml | 4 +- .../configapi/service/auth/ClientService.java | 53 ++++++------------- 3 files changed, 35 insertions(+), 56 deletions(-) diff --git a/jans-config-api/docs/jans-config-api-swagger-auto.yaml b/jans-config-api/docs/jans-config-api-swagger-auto.yaml index 44b1e162884..45ed79d649b 100644 --- a/jans-config-api/docs/jans-config-api-swagger-auto.yaml +++ b/jans-config-api/docs/jans-config-api-swagger-auto.yaml @@ -2945,18 +2945,18 @@ components: $ref: '#/components/schemas/AttributeValidation' tooltip: type: string - adminCanEdit: + userCanAccess: type: boolean adminCanView: type: boolean + adminCanAccess: + type: boolean userCanView: type: boolean - userCanAccess: + adminCanEdit: type: boolean userCanEdit: type: boolean - adminCanAccess: - type: boolean whitePagesCanView: type: boolean baseDn: @@ -3389,10 +3389,10 @@ components: type: array items: type: object - displayValue: - type: string value: type: object + displayValue: + type: string LocalizedString: type: object properties: @@ -3400,13 +3400,13 @@ components: type: object additionalProperties: type: string + value: + type: string languageTags: uniqueItems: true type: array items: type: string - value: - type: string AppConfiguration: type: object properties: @@ -4093,6 +4093,15 @@ components: $ref: '#/components/schemas/EngineConfig' ssaConfiguration: $ref: '#/components/schemas/SsaConfiguration' + allResponseTypesSupported: + uniqueItems: true + type: array + items: + type: string + enum: + - code + - token + - id_token fapi: type: boolean enabledFeatureFlags: @@ -4122,15 +4131,6 @@ components: - STAT - PAR - SSA - allResponseTypesSupported: - uniqueItems: true - type: array - items: - type: string - enum: - - code - - token - - id_token AuthenticationFilter: required: - baseDn diff --git a/jans-config-api/plugins/docs/user-mgt-plugin-swagger.yaml b/jans-config-api/plugins/docs/user-mgt-plugin-swagger.yaml index 4b47382ece4..c5debdf81ec 100644 --- a/jans-config-api/plugins/docs/user-mgt-plugin-swagger.yaml +++ b/jans-config-api/plugins/docs/user-mgt-plugin-swagger.yaml @@ -225,10 +225,10 @@ components: type: array items: type: object - displayValue: - type: string value: type: object + displayValue: + type: string CustomUser: type: object properties: diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/ClientService.java b/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/ClientService.java index 78f66667865..58f6f5702de 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/ClientService.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/ClientService.java @@ -38,8 +38,6 @@ import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; -import com.google.common.collect.Lists; - /** * @author Mougang T.Gasmyr * @@ -199,7 +197,7 @@ public Client setClientDefaultAttributes(Client client, boolean update) { return client; } - logger.debug("client.getApplicationType:{}, client.getRedirectUris():{}, client.getClaimRedirectUris():{}", + logger.trace("client.getApplicationType:{}, client.getRedirectUris():{}, client.getClaimRedirectUris():{}", client.getApplicationType(), client.getRedirectUris(), client.getClaimRedirectUris()); List redirectUris = client.getRedirectUris() != null ? Arrays.asList(client.getRedirectUris()) : null; @@ -214,7 +212,9 @@ public Client setClientDefaultAttributes(Client client, boolean update) { claimsRedirectUris = new ArrayList<>(new HashSet<>(claimsRedirectUris)); // Remove repeated elements client.setClaimRedirectUris(claimsRedirectUris.toArray(new String[0])); } - + logger.trace("After setting client.getApplicationType:{}, client.getRedirectUris():{}, client.getClaimRedirectUris():{}", + client.getApplicationType(), client.getRedirectUris(), client.getClaimRedirectUris()); + client.setApplicationType( client.getApplicationType() != null ? client.getApplicationType() : ApplicationType.WEB); @@ -222,7 +222,7 @@ public Client setClientDefaultAttributes(Client client, boolean update) { client.setSectorIdentifierUri(client.getSectorIdentifierUri()); } - logger.debug("client.getResponseTypes():{}, client.getGrantTypes():{}", client.getResponseTypes(), + logger.trace("client.getApplicationType():{}, client.getResponseTypes():{}, client.getGrantTypes():{}",client.getApplicationType(), client.getResponseTypes(), client.getGrantTypes()); Set responseTypeSet = client.getResponseTypes() != null ? new HashSet<>(Arrays.asList(client.getResponseTypes())) @@ -255,7 +255,9 @@ public Client setClientDefaultAttributes(Client client, boolean update) { responseTypeSet.retainAll(appConfiguration.getAllResponseTypesSupported()); grantTypeSet.retainAll(appConfiguration.getGrantTypesSupported()); - + logger.trace("After setting - client.getResponseTypes():{}, client.getGrantTypes():{}", client.getResponseTypes(), + client.getGrantTypes()); + Set dynamicGrantTypeDefault = appConfiguration.getDynamicGrantTypeDefault(); grantTypeSet.retainAll(dynamicGrantTypeDefault); @@ -267,7 +269,7 @@ public Client setClientDefaultAttributes(Client client, boolean update) { client.setGrantTypes(grantTypeSet.toArray(new GrantType[0])); } - logger.debug("Set client.getResponseTypes():{}, client.getGrantTypes():{}", client.getResponseTypes(), + logger.trace("Set client.getResponseTypes():{}, client.getGrantTypes():{}", client.getResponseTypes(), client.getGrantTypes()); List contacts = client.getContacts() != null ? Arrays.asList(client.getContacts()) : null; if (contacts != null && !contacts.isEmpty()) { @@ -275,13 +277,13 @@ public Client setClientDefaultAttributes(Client client, boolean update) { client.setContacts(contacts.toArray(new String[0])); } - logger.debug("client.getTokenEndpointAuthMethod():{}", client.getTokenEndpointAuthMethod()); + logger.trace("client.getTokenEndpointAuthMethod():{}", client.getTokenEndpointAuthMethod()); if (StringUtils.isBlank(client.getTokenEndpointAuthMethod())) { // If omitted, the default is client_secret_basic client.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_BASIC.toString()); } - logger.debug("client.getDefaultAcrValues():{}", client.getDefaultAcrValues()); + logger.trace("client.getDefaultAcrValues():{}", client.getDefaultAcrValues()); List defaultAcrValues = client.getDefaultAcrValues() != null ? Arrays.asList(client.getDefaultAcrValues()) : null; @@ -318,39 +320,16 @@ public Client setClientDefaultAttributes(Client client, boolean update) { authorizedOrigins = new ArrayList<>(new HashSet<>(authorizedOrigins)); // Remove repeated elements client.setAuthorizedOrigins(authorizedOrigins.toArray(new String[authorizedOrigins.size()])); } - - List scopes = client.getScopes() != null ? Arrays.asList(client.getScopes()) : null; - if (grantTypeSet.contains(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS) - && !appConfiguration.getDynamicRegistrationAllowedPasswordGrantScopes().isEmpty()) { - scopes = Lists.newArrayList(scopes); - scopes.retainAll(appConfiguration.getDynamicRegistrationAllowedPasswordGrantScopes()); - } - List scopesDn; - if (scopes != null && !scopes.isEmpty() - && isTrue(appConfiguration.getDynamicRegistrationScopesParamEnabled())) { - List defaultScopes = scopeService.getDefaultScopesDn(); - List requestedScopes = scopeService.getScopesDn(scopes); - Set allowedScopes = new HashSet<>(); - - for (String requestedScope : requestedScopes) { - if (defaultScopes.contains(requestedScope)) { - allowedScopes.add(requestedScope); - } - } - - scopesDn = new ArrayList<>(allowedScopes); - client.setScopes(scopesDn.toArray(new String[scopesDn.size()])); - } else { - scopesDn = scopeService.getDefaultScopesDn(); - client.setScopes(scopesDn.toArray(new String[scopesDn.size()])); - } - + + logger.debug("client.getScopes():{}, appConfiguration.getDynamicRegistrationScopesParamEnabled():{}",client.getScopes(), appConfiguration.getDynamicRegistrationScopesParamEnabled()); + List claims = client.getClaims() != null ? Arrays.asList(client.getClaims()) : null; if (claims != null && !claims.isEmpty()) { List claimsDn = attributeService.getAttributesDn(claims); client.setClaims(claimsDn.toArray(new String[claimsDn.size()])); } - + logger.debug("client.getClaims():{}, client.getAttributes().getAuthorizedAcrValues():{}",client.getClaims(), client.getAttributes().getAuthorizedAcrValues()); + List authorizedAcrValues = client.getAttributes().getAuthorizedAcrValues(); if (authorizedAcrValues != null && !authorizedAcrValues.isEmpty()) { authorizedAcrValues = new ArrayList<>(new HashSet<>(authorizedAcrValues)); // Remove repeated elements