Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use find by name for resources|scopes|policies #1096

Merged
merged 17 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
a901720
Use find by name for resources|scopes|policies instead of filtering t…
bohmber Jul 9, 2024
fbb6ce6
Use find by name for resources|scopes|policies instead of filtering t…
bohmber Jul 9, 2024
ff4680d
Use find by name for resources|policies instead of filtering the list…
bohmber Jul 9, 2024
2c982d2
Use find by name for resources|scopes|policies instead of filtering t…
bohmber Jul 9, 2024
740b1e3
Use find by name for resources|policies instead of filtering the list…
bohmber Jul 9, 2024
65980d3
Use find by name for resources|policies instead of filtering the list…
bohmber Jul 9, 2024
a22d5e2
Use find by name for resources|policies instead of filtering the list…
bohmber Jul 11, 2024
7f0f3e5
Use find by name for resources|policies instead of filtering the list…
bohmber Jul 11, 2024
93e2400
Use find by name for resources|policies instead of filtering the list…
bohmber Jul 11, 2024
02f6ea1
Use find by name for resources|policies instead of filtering the list…
bohmber Jul 11, 2024
df42b38
Use find by name for resources|policies instead of filtering the list…
bohmber Jul 12, 2024
c8b6a3a
Use find by name for resources|policies instead of filtering the list…
bohmber Jul 12, 2024
ec08665
Use find by name for resources|policies instead of filtering the list…
bohmber Jul 12, 2024
c930808
Use find by name for resources|policies instead of filtering the list…
bohmber Jul 12, 2024
fba08a9
Use find by name for resources|policies instead of filtering the list…
bohmber Jul 12, 2024
e95fff2
NPE with added Resouce in AuthorizationSettings
bohmber Jul 23, 2024
ec12561
Merge branch 'main' into issue-1095
bohmber Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed
- Crash after inserting more than 100 roles in realm-management authorization
[#1090](/adorsys/keycloak-config-cli/issues/1090):

- NPE when using custom policy in AuthorizationPolicy [#1095](/adorsys/keycloak-config-cli/issues/1095):


## [6.1.6] - 2024-07-26

## [6.1.5] - 2024-06-27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,19 @@ public void removeAuthorizationResource(String realmName, String id, String reso
}

private String getResourceId(ClientResource clientResource, String resourceName) {
return clientResource.authorization().resources().resources().stream()
.filter(resource -> resourceName.equals(resource.getName()))
.findFirst()
.map(ResourceRepresentation::getId)
.orElse(null);
String clientId = clientResource.toRepresentation().getClientId();
// find it with name and owner(clientId)
// Note: findByName is not exact filter the resource with the exact name
return clientResource.authorization().resources().findByName(resourceName, clientId).stream()
.filter(r -> resourceName.equals(r.getName()))
.findFirst().map(ResourceRepresentation::getId)
.orElseGet(
() -> clientResource.authorization().resources()
.findByName(resourceName).stream()
.filter(r -> resourceName.equals(r.getName())
&& !clientId.equals(r.getOwner().getName()))
.findFirst().map(ResourceRepresentation::getId)
.orElse(null));
}

public void addAuthorizationScope(String realmName, String id, String name) {
Expand All @@ -225,11 +233,11 @@ public void removeAuthorizationScope(String realmName, String id, String scopeNa
}

private String getScopeId(ClientResource clientResource, String scopeName) {
return clientResource.authorization().scopes().scopes().stream()
.filter(scope -> scopeName.equals(scope.getName()))
.findFirst()
.map(ScopeRepresentation::getId)
.orElse(null);
ScopeRepresentation scopeRepresentation = clientResource.authorization().scopes().findByName(scopeName);
if (scopeRepresentation != null) {
return scopeRepresentation.getId();
}
return null;
}

public void createAuthorizationPolicy(String realmName, String id, PolicyRepresentation policy) {
Expand All @@ -255,11 +263,11 @@ public void removeAuthorizationPolicy(String realmName, String id, String policy
}

private String getPolicyId(ClientResource clientResource, String policyName) {
return clientResource.authorization().policies().policies().stream()
.filter(policy -> policyName.equals(policy.getName()))
.findFirst()
.map(PolicyRepresentation::getId)
.orElse(null);
PolicyRepresentation policyRepresentation = clientResource.authorization().policies().findByName(policyName);
if (policyRepresentation != null) {
return policyRepresentation.getId();
}
return null;
}

public void addScopeMapping(String realmName, String clientId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ private void updateAuthorizationResource(
existingClientAuthorizationResource.getOwner().setName(null);
}

if (existingClientAuthorizationResource.getAttributes().isEmpty() && authorizationResourceToImport.getAttributes() == null) {
if (existingClientAuthorizationResource.getAttributes() != null
&& existingClientAuthorizationResource.getAttributes().isEmpty()
&& authorizationResourceToImport.getAttributes() == null) {
existingClientAuthorizationResource.setAttributes(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2339,6 +2339,12 @@ void shouldNotTriggerErrorWhenReferencingInvalidUuidInFineGrainedAuthz() throws
assertDoesNotThrow(() -> realmImportService.doImport(foundImport4));
}

@Test
@Order(51)
void updateRealmWithClientWithMoreThan100RolesInRealmManagementAuthorization() throws IOException {
doImport("51_update_realm_with_client_with_more_than_100_roles_in_realm_management_authorization.json");
}

@Test
@Order(71)
void shouldAddClientWithAuthenticationFlowBindingOverrides() throws IOException {
Expand Down
Loading
Loading