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

Move PolicyEnforcerTest to keycloak-client repository #22

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:

- name: Run client tests
run: |
mvn -B -f testsuite/providers/pom.xml package -DskipTests=true
mvn -B -f testsuite/admin-client-tests/pom.xml test -Dkeycloak.version.docker.image=${{ matrix.keycloak_server_version }}
mvn -B -f testsuite/admin-client-jee-tests/pom.xml test -Dkeycloak.version.docker.image=${{ matrix.keycloak_server_version }}
mvn -B -f testsuite/authz-tests/pom.xml test -Dkeycloak.version.docker.image=${{ matrix.keycloak_server_version }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,7 @@ public static String replaceProperties(final String string, final Properties pro
if (props == null) {
return replaceProperties(string, (PropertyResolver) null);
}
return replaceProperties(string, new PropertyResolver() {
@Override
public String resolve(String property) {
return props.getProperty(property);
}
});
return replaceProperties(string, props::getProperty);
}

public static String replaceProperties(final String string, PropertyResolver resolver)
Expand Down Expand Up @@ -249,29 +244,6 @@ else if (PATH_SEPARATOR_ALIAS.equals(key))
return buffer.toString();
}

/**
* Try to resolve a "key" from the provided properties by
* checking if it is actually a "key1,key2", in which case
* try first "key1", then "key2". If all fails, return null.
*
* It also accepts "key1," and ",key2".
*
* @param key the key to resolve
* @param props the properties to use
* @return the resolved key or null
*/
private static String resolveCompositeKey(String key, final Properties props) {
if (props == null) {
return resolveCompositeKey(key, (PropertyResolver) null);
}
return resolveCompositeKey(key, new PropertyResolver() {
@Override
public String resolve(String property) {
return props.getProperty(property);
}
});
}

private static String resolveCompositeKey(String key, PropertyResolver resolver)
{
String value = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class RolePolicyRepresentation extends AbstractPolicyRepresentation {

private Set<RoleDefinition> roles;
private boolean fetchRoles;
private Boolean fetchRoles;

@Override
public String getType() {
Expand All @@ -40,7 +40,7 @@ public void setRoles(Set<RoleDefinition> roles) {
this.roles = roles;
}

public void addRole(String name, boolean required) {
public void addRole(String name, Boolean required) {
if (roles == null) {
roles = new HashSet<>();
}
Expand All @@ -59,24 +59,24 @@ public void addClientRole(String clientId, String name, boolean required) {
addRole(clientId + "/" + name, required);
}

public boolean isFetchRoles() {
public Boolean isFetchRoles() {
return fetchRoles;
}

public void setFetchRoles(boolean fetchRoles) {
public void setFetchRoles(Boolean fetchRoles) {
this.fetchRoles = fetchRoles;
}

public static class RoleDefinition implements Comparable<RoleDefinition> {

private String id;
private boolean required;
private Boolean required;

public RoleDefinition() {
this(null, false);
}

public RoleDefinition(String id, boolean required) {
public RoleDefinition(String id, Boolean required) {
this.id = id;
this.required = required;
}
Expand All @@ -89,11 +89,11 @@ public void setId(String id) {
this.id = id;
}

public boolean isRequired() {
public Boolean isRequired() {
return required;
}

public void setRequired(boolean required) {
public void setRequired(Boolean required) {
this.required = required;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,7 @@ public static String replaceProperties(final String string, final Properties pro
if (props == null) {
return replaceProperties(string, (PropertyResolver) null);
}
return replaceProperties(string, new PropertyResolver() {
@Override
public String resolve(String property) {
return props.getProperty(property);
}
});
return replaceProperties(string, props::getProperty);
}

public static String replaceProperties(final String string, PropertyResolver resolver)
Expand Down Expand Up @@ -249,29 +244,6 @@ else if (PATH_SEPARATOR_ALIAS.equals(key))
return buffer.toString();
}

/**
* Try to resolve a "key" from the provided properties by
* checking if it is actually a "key1,key2", in which case
* try first "key1", then "key2". If all fails, return null.
*
* It also accepts "key1," and ",key2".
*
* @param key the key to resolve
* @param props the properties to use
* @return the resolved key or null
*/
private static String resolveCompositeKey(String key, final Properties props) {
if (props == null) {
return resolveCompositeKey(key, (PropertyResolver) null);
}
return resolveCompositeKey(key, new PropertyResolver() {
@Override
public String resolve(String property) {
return props.getProperty(property);
}
});
}

private static String resolveCompositeKey(String key, PropertyResolver resolver)
{
String value = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class RolePolicyRepresentation extends AbstractPolicyRepresentation {

private Set<RoleDefinition> roles;
private boolean fetchRoles;
private Boolean fetchRoles;

@Override
public String getType() {
Expand All @@ -40,7 +40,7 @@ public void setRoles(Set<RoleDefinition> roles) {
this.roles = roles;
}

public void addRole(String name, boolean required) {
public void addRole(String name, Boolean required) {
if (roles == null) {
roles = new HashSet<>();
}
Expand All @@ -59,24 +59,24 @@ public void addClientRole(String clientId, String name, boolean required) {
addRole(clientId + "/" + name, required);
}

public boolean isFetchRoles() {
public Boolean isFetchRoles() {
return fetchRoles;
}

public void setFetchRoles(boolean fetchRoles) {
public void setFetchRoles(Boolean fetchRoles) {
this.fetchRoles = fetchRoles;
}

public static class RoleDefinition implements Comparable<RoleDefinition> {

private String id;
private boolean required;
private Boolean required;

public RoleDefinition() {
this(null, false);
}

public RoleDefinition(String id, boolean required) {
public RoleDefinition(String id, Boolean required) {
this.id = id;
this.required = required;
}
Expand All @@ -89,11 +89,11 @@ public void setId(String id) {
this.id = id;
}

public boolean isRequired() {
public Boolean isRequired() {
return required;
}

public void setRequired(boolean required) {
public void setRequired(Boolean required) {
this.required = required;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,7 @@ public static String replaceProperties(final String string, final Properties pro
if (props == null) {
return replaceProperties(string, (PropertyResolver) null);
}
return replaceProperties(string, new PropertyResolver() {
@Override
public String resolve(String property) {
return props.getProperty(property);
}
});
return replaceProperties(string, props::getProperty);
}

public static String replaceProperties(final String string, PropertyResolver resolver)
Expand Down Expand Up @@ -249,29 +244,6 @@ else if (PATH_SEPARATOR_ALIAS.equals(key))
return buffer.toString();
}

/**
* Try to resolve a "key" from the provided properties by
* checking if it is actually a "key1,key2", in which case
* try first "key1", then "key2". If all fails, return null.
*
* It also accepts "key1," and ",key2".
*
* @param key the key to resolve
* @param props the properties to use
* @return the resolved key or null
*/
private static String resolveCompositeKey(String key, final Properties props) {
if (props == null) {
return resolveCompositeKey(key, (PropertyResolver) null);
}
return resolveCompositeKey(key, new PropertyResolver() {
@Override
public String resolve(String property) {
return props.getProperty(property);
}
});
}

private static String resolveCompositeKey(String key, PropertyResolver resolver)
{
String value = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class RolePolicyRepresentation extends AbstractPolicyRepresentation {

private Set<RoleDefinition> roles;
private boolean fetchRoles;
private Boolean fetchRoles;

@Override
public String getType() {
Expand All @@ -40,7 +40,7 @@ public void setRoles(Set<RoleDefinition> roles) {
this.roles = roles;
}

public void addRole(String name, boolean required) {
public void addRole(String name, Boolean required) {
if (roles == null) {
roles = new HashSet<>();
}
Expand All @@ -59,24 +59,24 @@ public void addClientRole(String clientId, String name, boolean required) {
addRole(clientId + "/" + name, required);
}

public boolean isFetchRoles() {
public Boolean isFetchRoles() {
return fetchRoles;
}

public void setFetchRoles(boolean fetchRoles) {
public void setFetchRoles(Boolean fetchRoles) {
this.fetchRoles = fetchRoles;
}

public static class RoleDefinition implements Comparable<RoleDefinition> {

private String id;
private boolean required;
private Boolean required;

public RoleDefinition() {
this(null, false);
}

public RoleDefinition(String id, boolean required) {
public RoleDefinition(String id, Boolean required) {
this.id = id;
this.required = required;
}
Expand All @@ -89,11 +89,11 @@ public void setId(String id) {
this.id = id;
}

public boolean isRequired() {
public Boolean isRequired() {
return required;
}

public void setRequired(boolean required) {
public void setRequired(Boolean required) {
this.required = required;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.junit.jupiter.api.BeforeEach;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.resource.RealmsResource;
import org.keycloak.client.testsuite.common.OAuthClient;
import org.keycloak.client.testsuite.framework.Inject;
import org.keycloak.client.testsuite.common.RealmImporter;
import org.keycloak.client.testsuite.common.RealmRepsSupplier;
Expand All @@ -23,6 +25,9 @@ public abstract class AbstractAuthzTest implements RealmRepsSupplier {
@Inject
protected RealmImporter realmImporter;

@Inject
protected OAuthClient oauth;

@BeforeEach
public void importRealms() {
realmImporter.importRealmsIfNotImported(this);
Expand All @@ -35,4 +40,14 @@ protected RealmRepresentation loadRealm(InputStream is) {
throw new UncheckedIOException(ioe);
}
}

@Override
public boolean removeVerifyProfileAtImport() {
// remove verify profile by default because most tests are not prepared
return true;
}

public RealmsResource realmsResource() {
return adminClient.realms();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.keycloak.client.testsuite.authz;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.keycloak.adapters.authorization.cip.spi.ClaimInformationPointProvider;
import org.keycloak.adapters.authorization.cip.spi.ClaimInformationPointProviderFactory;
import org.keycloak.adapters.authorization.spi.HttpRequest;

public class MyCustomCIPFactory implements ClaimInformationPointProviderFactory<MyCustomCIP> {

@Override
public String getName() {
return "my-custom-cip";
}

@Override
public MyCustomCIP create(Map<String, Object> config) {
return new MyCustomCIP(config);
}
}

class MyCustomCIP implements ClaimInformationPointProvider {

private final Map<String, Object> config;

MyCustomCIP(Map<String, Object> config) {
this.config = config;
}

@Override
public Map<String, List<String>> resolve(HttpRequest request) {
Map<String, List<String>> claims = new HashMap<>();

claims.put("resolved-claim", Arrays.asList(config.get("claim-value").toString()));

return claims;
}
}

Loading