Skip to content

Commit

Permalink
fix(config-api): fix for returning associated-clients for scope (#2567)
Browse files Browse the repository at this point in the history
* fix(config-api): fix for returning associated-clients for scope

* fix(config-api): fix for returning associated-clients for scope
  • Loading branch information
pujavs committed Oct 7, 2022
1 parent f6faa71 commit e623f64
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ public void setClients(List<Client> clients) {

private List<Client> clients;

@Override
public String toString() {
return "CustomScope [clients=" + clients + "]";
}



}
22 changes: 11 additions & 11 deletions jans-config-api/docs/jans-config-api-swagger-auto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2947,17 +2947,17 @@ components:
type: string
whitePagesCanView:
type: boolean
adminCanAccess:
type: boolean
userCanEdit:
type: boolean
adminCanEdit:
type: boolean
adminCanView:
type: boolean
userCanAccess:
type: boolean
userCanView:
type: boolean
userCanAccess:
adminCanAccess:
type: boolean
userCanEdit:
type: boolean
baseDn:
type: string
Expand Down Expand Up @@ -3284,6 +3284,8 @@ components:
format: int32
displayName:
type: string
tokenBindingSupported:
type: boolean
authenticationMethod:
type: string
enum:
Expand All @@ -3295,8 +3297,6 @@ components:
- tls_client_auth
- self_signed_tls_client_auth
- none
tokenBindingSupported:
type: boolean
baseDn:
type: string
inum:
Expand Down Expand Up @@ -4090,6 +4090,8 @@ components:
$ref: '#/components/schemas/EngineConfig'
ssaConfiguration:
$ref: '#/components/schemas/SsaConfiguration'
fapi:
type: boolean
enabledFeatureFlags:
uniqueItems: true
type: array
Expand Down Expand Up @@ -4117,8 +4119,6 @@ components:
- STAT
- PAR
- SSA
fapi:
type: boolean
allResponseTypesSupported:
uniqueItems: true
type: array
Expand Down Expand Up @@ -4384,13 +4384,13 @@ components:
type: boolean
internal:
type: boolean
locationPath:
type: string
locationType:
type: string
enum:
- ldap
- file
locationPath:
type: string
baseDn:
type: string
ScriptError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

package io.jans.configapi.service.auth;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.api.client.util.Lists;
import io.jans.as.common.model.registration.Client;
import io.jans.as.common.service.OrganizationService;
Expand Down Expand Up @@ -97,9 +96,8 @@ public CustomScope getScopeByInum(String inum, boolean withAssociatedClients) {
try {
CustomScope scope = persistenceEntryManager.find(CustomScope.class, getDnForScope(inum));
if (withAssociatedClients) {
List<Client> clients = clientService.getAllClients();
List<UmaResource> umaResources = umaResourceService.getAllResources();
return setClients(scope, clients, umaResources);

return setClients(scope);
}
return scope;
} catch (Exception e) {
Expand Down Expand Up @@ -206,43 +204,78 @@ public List<CustomScope> searchScope(SearchRequest searchRequest) {
return Collections.emptyList();
}

private CustomScope setClients(Scope scope, List<Client> clients, List<UmaResource> umaResources) {
logger.debug("Search Scope with associated clients - scope:{}, clients:{}, umaResources:{}", scope, clients,
umaResources);
public List<Scope> getAllScopesList() {
String scopesBaseDN = staticConfiguration.getBaseDn().getScopes();

return persistenceEntryManager.findEntries(scopesBaseDN, Scope.class, Filter.createPresenceFilter("inum"));
}

public List<String> getDefaultScopesDn() {
List<String> defaultScopes = new ArrayList<>();

for (Scope scope : getAllScopesList()) {
if (Boolean.TRUE.equals(scope.isDefaultScope())) {
defaultScopes.add(scope.getDn());
}
}

return defaultScopes;
}

public List<String> getScopesDn(List<String> scopeDnList) {
List<String> scopes = new ArrayList<>();

for (String scopeDn : scopeDnList) {
Scope scope = getScopeByDn(scopeDn);
if (scope != null) {
scopes.add(scope.getDn());
}
}

return scopes;
}

private CustomScope setClients(CustomScope customScope) {
logger.debug("Getting associated-clients for scope - customScope:{}", customScope);

ObjectMapper mapper = new ObjectMapper();
CustomScope customScope = mapper.convertValue(scope, CustomScope.class);
List<Client> clients = clientService.getAllClients();
List<UmaResource> umaResources = umaResourceService.getAllResources();
logger.debug("Verifying associated-clients using clients:{}, umaResources:{}", clients, umaResources);
customScope.setClients(Lists.newArrayList());

for (Client client : clients) {
logger.debug(
"Associated clients serach - scope.getScopeType():{}, scope.getInum():{}, scope.getCreatorId():{}, client.getClientId():{}, clientService.getDnForClient(client.getClientId()):{}, client.getScopes():{}, client.getClientId().equals(scope.getCreatorId()):{}",
scope.getScopeType(), scope.getInum(), scope.getCreatorId(), client.getClientId(),
"Associated clients search - customScope.getScopeType():{}, customScope.getInum():{}, customScope.getCreatorId():{}, client.getClientId():{}, clientService.getDnForClient(client.getClientId()):{}, client.getScopes():{}, client.getClientId().equals(customScope.getCreatorId()):{}",
customScope.getScopeType(), customScope.getInum(), customScope.getCreatorId(), client.getClientId(),
clientService.getDnForClient(client.getClientId()), client.getScopes(),
client.getClientId().equals(scope.getCreatorId()));
client.getClientId().equals(customScope.getCreatorId()));

if (scope.getScopeType() == ScopeType.OPENID || scope.getScopeType() == ScopeType.OAUTH
|| scope.getScopeType() == ScopeType.DYNAMIC) {
if (customScope.getScopeType() == ScopeType.OPENID || customScope.getScopeType() == ScopeType.OAUTH
|| customScope.getScopeType() == ScopeType.DYNAMIC) {
if (client.getScopes() != null
&& Arrays.asList(client.getScopes()).contains(getDnForScope(scope.getInum()))) {
&& Arrays.asList(client.getScopes()).contains(getDnForScope(customScope.getInum()))) {
logger.debug(
"Associated clients match for OOD - customScope.getScopeType():{}, customScope.getInum():{},client.getClientId():{}",
customScope.getScopeType(), customScope.getInum(), client.getClientId());
customScope.getClients().add(client);
}
} else if (scope.getScopeType() == ScopeType.UMA) {
} else if (customScope.getScopeType() == ScopeType.UMA) {
List<UmaResource> umaRes = umaResources.stream()
.filter(umaResource -> (umaResource.getScopes() != null
&& umaResource.getScopes().contains(getDnForScope(scope.getInum()))))
&& umaResource.getScopes().contains(getDnForScope(customScope.getInum()))))
.collect(Collectors.toList());
logger.trace("Associated clients serach - umaRes():{}", umaRes);
for (UmaResource res : umaRes) {
logger.trace(
" client.getDn():{}, res.getInum():{}, res.getClients():{}, res.getClients().contains(clientService.getDnForClient(client.getClientId()):{}",
client.getDn(), res.getInum(), res.getClients(),
res.getClients().contains(clientService.getDnForClient(client.getClientId())));
logger.trace("Associated clients search - umaRes():{}", umaRes);
if (umaRes.stream().anyMatch(
ele -> ele.getClients().contains(clientService.getDnForClient(client.getClientId())))) {
customScope.getClients().add(client);

}
} else if ((scope.getScopeType() == ScopeType.SPONTANEOUS)
&& (client.getClientId().equals(scope.getCreatorId()))) {
} else if ((customScope.getScopeType() == ScopeType.SPONTANEOUS)
&& (client.getClientId().equals(customScope.getCreatorId()))) {
logger.debug(
"Associated clients match for SPONTANEOUS - customScope.getScopeType():{}, customScope.getInum():{},customScope.getCreatorId():{}, client.getClientId():{}",
customScope.getScopeType(), customScope.getInum(), customScope.getCreatorId(),
client.getClientId());
customScope.getClients().add(client);
}
}
Expand All @@ -254,9 +287,14 @@ public List<CustomScope> getAssociatedClients(List<CustomScope> scopes) {
if (scopes == null) {
return scopes;
}
List<Client> clients = clientService.getAllClients();
List<UmaResource> umaResources = umaResourceService.getAllResources();
return (scopes.stream().map(scope -> setClients(scope, clients, umaResources)).collect(Collectors.toList()));

List<CustomScope> scopeList = Lists.newArrayList();
for (CustomScope scope : scopes) {
scopeList.add(setClients(scope));
}

logger.debug("Getting associatedClients for scopeList:{}", scopeList);
return scopeList;

}

Expand Down

0 comments on commit e623f64

Please sign in to comment.