Skip to content

Commit

Permalink
KEYCLOAK-16805 Client Policy : Support New Admin REST API (Implementa…
Browse files Browse the repository at this point in the history
…tion) (#7780)

* KEYCLOAK-16805 Client Policy : Support New Admin REST API (Implementation)

* support tests using auth-server-quarkus

* Configuration changes for ClientPolicyExecutorProvider

* Change VALUE of table REALM_ATTRIBUTES to NCLOB

* add author tag

* incorporate all review comments

Co-authored-by: mposolda <mposolda@gmail.com>
  • Loading branch information
tnorimat and mposolda committed Apr 6, 2021
1 parent d1ad905 commit 42dec08
Show file tree
Hide file tree
Showing 102 changed files with 5,354 additions and 1,857 deletions.
@@ -0,0 +1,41 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.keycloak.representations.idm;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
* Client Policies' (the set of all Client Policy) external representation class
*
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class ClientPoliciesRepresentation {
protected List<ClientPolicyRepresentation> policies;

public List<ClientPolicyRepresentation> getPolicies() {
return policies;
}

public void setPolicies(List<ClientPolicyRepresentation> policies) {
this.policies = policies;
}

}
@@ -0,0 +1,87 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.keycloak.representations.idm;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
* Client Policy's external representation class
*
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class ClientPolicyRepresentation {

protected String name;
protected String description;
protected Boolean builtin;
protected Boolean enable;
protected List<Object> conditions;
protected List<String> profiles;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Boolean isBuiltin() {
return builtin;
}

public void setBuiltin(Boolean builtin) {
this.builtin = builtin;
}

public Boolean isEnable() {
return enable;
}

public void setEnable(Boolean enable) {
this.enable = enable;
}

public List<Object> getConditions() {
return conditions;
}

public void setConditions(List<Object> conditions) {
this.conditions = conditions;
}

public List<String> getProfiles() {
return profiles;
}

public void setProfiles(List<String> profiles) {
this.profiles = profiles;
}

}
@@ -0,0 +1,68 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.keycloak.representations.idm;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
* Client Profile's external representation class
*
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class ClientProfileRepresentation {

protected String name;
protected String description;
protected Boolean builtin;
protected List<Object> executors;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Boolean isBuiltin() {
return builtin;
}

public void setBuiltin(Boolean builtin) {
this.builtin = builtin;
}

public List<Object> getExecutors() {
return executors;
}

public void setExecutors(List<Object> executors) {
this.executors = executors;
}
}
@@ -0,0 +1,41 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.keycloak.representations.idm;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
* Client Profiles' (the set of all Client Profile) external representation class
*
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class ClientProfilesRepresentation {
protected List<ClientProfileRepresentation> profiles;

public List<ClientProfileRepresentation> getProfiles() {
return profiles;
}

public void setProfiles(List<ClientProfileRepresentation> profiles) {
this.profiles = profiles;
}

}
Expand Up @@ -141,6 +141,11 @@ public class RealmRepresentation {
protected Boolean webAuthnPolicyPasswordlessAvoidSameAuthenticatorRegister;
protected List<String> webAuthnPolicyPasswordlessAcceptableAaguids;

// Client Policies/Profiles

protected ClientProfilesRepresentation clientProfiles;
protected ClientPoliciesRepresentation clientPolicies;

protected List<UserRepresentation> users;
protected List<UserRepresentation> federatedUsers;
protected List<ScopeMappingRepresentation> scopeMappings;
Expand Down Expand Up @@ -1173,6 +1178,24 @@ public void setWebAuthnPolicyPasswordlessAcceptableAaguids(List<String> webAuthn
this.webAuthnPolicyPasswordlessAcceptableAaguids = webAuthnPolicyPasswordlessAcceptableAaguids;
}

// Client Policies/Profiles

public ClientProfilesRepresentation getClientProfiles() {
return clientProfiles;
}

public void setClientProfiles(ClientProfilesRepresentation clientProfiles) {
this.clientProfiles = clientProfiles;
}

public ClientPoliciesRepresentation getClientPolicies() {
return clientPolicies;
}

public void setClientPolicies(ClientPoliciesRepresentation clientPolicies) {
this.clientPolicies = clientPolicies;
}

public String getBrowserFlow() {
return browserFlow;
}
Expand Down
@@ -0,0 +1,26 @@
package org.keycloak.admin.client.resource;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.jboss.resteasy.annotations.cache.NoCache;

/**
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/
public interface ClientPoliciesPoliciesResource {

@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
String getPolicies();

@PUT
@Consumes(MediaType.APPLICATION_JSON)
Response updatePolicies(final String json);
}

@@ -0,0 +1,25 @@
package org.keycloak.admin.client.resource;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.jboss.resteasy.annotations.cache.NoCache;

/**
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/
public interface ClientPoliciesProfilesResource {

@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
String getProfiles();

@PUT
@Consumes(MediaType.APPLICATION_JSON)
Response updateProfiles(final String json);
}
Expand Up @@ -18,6 +18,7 @@
package org.keycloak.admin.client.resource;

import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.representations.adapters.action.GlobalRequestResult;
import org.keycloak.representations.idm.AdminEventRepresentation;
import org.keycloak.representations.idm.ClientRepresentation;
Expand Down Expand Up @@ -282,4 +283,9 @@ Response testLDAPConnection(@FormParam("action") String action, @FormParam("conn
@Path("localization")
RealmLocalizationResource localization();

@Path("client-policies/policies")
ClientPoliciesPoliciesResource clientPoliciesPoliciesResource();

@Path("client-policies/profiles")
ClientPoliciesProfilesResource clientPoliciesProfilesResource();
}
Expand Up @@ -51,4 +51,9 @@
<modifyDataType newDataType="VARCHAR(255)" tableName="CLIENT_SCOPE_CLIENT" columnName="CLIENT_ID"/>
<modifyDataType newDataType="VARCHAR(255)" tableName="CLIENT_SCOPE_CLIENT" columnName="SCOPE_ID"/>
</changeSet>

<changeSet author="keycloak" id="json-string-accomodation">
<modifyDataType tableName="REALM_ATTRIBUTE" columnName="VALUE" newDataType="NCLOB"/>
</changeSet>

</databaseChangeLog>
Expand Up @@ -58,6 +58,7 @@ private void initializeKeycloakSessionFactory() {
QuarkusKeycloakSessionFactory instance = QuarkusKeycloakSessionFactory.getInstance();
sessionFactory = instance;
instance.init();
instance.create().clientPolicy().setupClientPoliciesOnKeycloakApp("/keycloak-default-client-profiles.json", "/keycloak-default-client-policies.json");
sessionFactory.publish(new PostMigrationEvent());
}

Expand Down
Expand Up @@ -93,6 +93,9 @@ public class ModelToRepresentation {
REALM_EXCLUDED_ATTRIBUTES.add("webAuthnPolicyCreateTimeoutPasswordless");
REALM_EXCLUDED_ATTRIBUTES.add("webAuthnPolicyAvoidSameAuthenticatorRegisterPasswordless");
REALM_EXCLUDED_ATTRIBUTES.add("webAuthnPolicyAcceptableAaguidsPasswordless");

REALM_EXCLUDED_ATTRIBUTES.add("client-policies.profiles");
REALM_EXCLUDED_ATTRIBUTES.add("client-policies.policies");
}


Expand Down

0 comments on commit 42dec08

Please sign in to comment.