Client Policies : Condition's negative logic configuration is not shown in Admin Console's form view

Closes #9447
This commit is contained in:
Takashi Norimatsu 2022-01-10 18:19:11 +09:00 committed by Marek Posolda
parent 9621d513b5
commit ef134390c2
9 changed files with 93 additions and 135 deletions

View file

@ -0,0 +1,52 @@
/*
* Copyright 2022 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.services.clientpolicy.condition;
import java.util.ArrayList;
import java.util.List;
import org.keycloak.Config.Scope;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.provider.ProviderConfigProperty;
/**
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/
public abstract class AbstractClientPolicyConditionProviderFactory implements ClientPolicyConditionProviderFactory {
public static final String IS_NEGATIVE_LOGIC = "is-negative-logic";
static protected void addCommonConfigProperties(List<ProviderConfigProperty> configProperties) {
ProviderConfigProperty property = new ProviderConfigProperty(IS_NEGATIVE_LOGIC, "Negative Logic",
"If On, the result of condition's evaluation is reverted from true to false and vice versa.",
ProviderConfigProperty.BOOLEAN_TYPE, false);
configProperties.add(property);
}
@Override
public void init(Scope config) {
}
@Override
public void postInit(KeycloakSessionFactory factory) {
}
@Override
public void close() {
}
}

View file

@ -17,38 +17,30 @@
package org.keycloak.services.clientpolicy.condition; package org.keycloak.services.clientpolicy.condition;
import java.util.Collections; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.keycloak.Config.Scope;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.provider.ProviderConfigProperty; import org.keycloak.provider.ProviderConfigProperty;
/** /**
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a> * @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/ */
public class AnyClientConditionFactory implements ClientPolicyConditionProviderFactory { public class AnyClientConditionFactory extends AbstractClientPolicyConditionProviderFactory {
public static final String PROVIDER_ID = "any-client"; public static final String PROVIDER_ID = "any-client";
private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>();
static {
addCommonConfigProperties(configProperties);
}
@Override @Override
public ClientPolicyConditionProvider create(KeycloakSession session) { public ClientPolicyConditionProvider create(KeycloakSession session) {
return new AnyClientCondition(session); return new AnyClientCondition(session);
} }
@Override
public void init(Scope config) {
}
@Override
public void postInit(KeycloakSessionFactory factory) {
}
@Override
public void close() {
}
@Override @Override
public String getId() { public String getId() {
return PROVIDER_ID; return PROVIDER_ID;
@ -59,9 +51,9 @@ public class AnyClientConditionFactory implements ClientPolicyConditionProviderF
return "The condition is satisfied by any client on any event."; return "The condition is satisfied by any client on any event.";
} }
@Override @Override
public List<ProviderConfigProperty> getConfigProperties() { public List<ProviderConfigProperty> getConfigProperties() {
return Collections.emptyList(); return configProperties;
} }
} }

View file

@ -21,15 +21,13 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.keycloak.Config.Scope;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.provider.ProviderConfigProperty; import org.keycloak.provider.ProviderConfigProperty;
/** /**
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a> * @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/ */
public class ClientAccessTypeConditionFactory implements ClientPolicyConditionProviderFactory { public class ClientAccessTypeConditionFactory extends AbstractClientPolicyConditionProviderFactory {
public static final String PROVIDER_ID = "client-access-type"; public static final String PROVIDER_ID = "client-access-type";
@ -42,6 +40,8 @@ public class ClientAccessTypeConditionFactory implements ClientPolicyConditionPr
private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>(); private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>();
static { static {
addCommonConfigProperties(configProperties);
ProviderConfigProperty property; ProviderConfigProperty property;
property = new ProviderConfigProperty(TYPE, "client-accesstype.label", "client-accesstype.tooltip", ProviderConfigProperty.MULTIVALUED_LIST_TYPE, TYPE_CONFIDENTIAL); property = new ProviderConfigProperty(TYPE, "client-accesstype.label", "client-accesstype.tooltip", ProviderConfigProperty.MULTIVALUED_LIST_TYPE, TYPE_CONFIDENTIAL);
List<String> updateProfileValues = Arrays.asList(TYPE_CONFIDENTIAL, TYPE_PUBLIC, TYPE_BEARERONLY); List<String> updateProfileValues = Arrays.asList(TYPE_CONFIDENTIAL, TYPE_PUBLIC, TYPE_BEARERONLY);
@ -54,18 +54,6 @@ public class ClientAccessTypeConditionFactory implements ClientPolicyConditionPr
return new ClientAccessTypeCondition(session); return new ClientAccessTypeCondition(session);
} }
@Override
public void init(Scope config) {
}
@Override
public void postInit(KeycloakSessionFactory factory) {
}
@Override
public void close() {
}
@Override @Override
public String getId() { public String getId() {
return PROVIDER_ID; return PROVIDER_ID;
@ -80,5 +68,4 @@ public class ClientAccessTypeConditionFactory implements ClientPolicyConditionPr
public List<ProviderConfigProperty> getConfigProperties() { public List<ProviderConfigProperty> getConfigProperties() {
return configProperties; return configProperties;
} }
} }

View file

@ -20,15 +20,13 @@ package org.keycloak.services.clientpolicy.condition;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.keycloak.Config.Scope;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.provider.ProviderConfigProperty; import org.keycloak.provider.ProviderConfigProperty;
/** /**
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a> * @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/ */
public class ClientRolesConditionFactory implements ClientPolicyConditionProviderFactory { public class ClientRolesConditionFactory extends AbstractClientPolicyConditionProviderFactory {
public static final String PROVIDER_ID = "client-roles"; public static final String PROVIDER_ID = "client-roles";
@ -37,6 +35,8 @@ public class ClientRolesConditionFactory implements ClientPolicyConditionProvide
private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>(); private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>();
static { static {
addCommonConfigProperties(configProperties);
ProviderConfigProperty property; ProviderConfigProperty property;
property = new ProviderConfigProperty(ROLES, PROVIDER_ID + ".label", PROVIDER_ID + "-condition.tooltip", ProviderConfigProperty.MULTIVALUED_STRING_TYPE, null); property = new ProviderConfigProperty(ROLES, PROVIDER_ID + ".label", PROVIDER_ID + "-condition.tooltip", ProviderConfigProperty.MULTIVALUED_STRING_TYPE, null);
configProperties.add(property); configProperties.add(property);
@ -47,18 +47,6 @@ public class ClientRolesConditionFactory implements ClientPolicyConditionProvide
return new ClientRolesCondition(session); return new ClientRolesCondition(session);
} }
@Override
public void init(Scope config) {
}
@Override
public void postInit(KeycloakSessionFactory factory) {
}
@Override
public void close() {
}
@Override @Override
public String getId() { public String getId() {
return PROVIDER_ID; return PROVIDER_ID;
@ -73,5 +61,4 @@ public class ClientRolesConditionFactory implements ClientPolicyConditionProvide
public List<ProviderConfigProperty> getConfigProperties() { public List<ProviderConfigProperty> getConfigProperties() {
return configProperties; return configProperties;
} }
} }

View file

@ -21,16 +21,14 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.keycloak.Config.Scope;
import org.keycloak.OAuth2Constants; import org.keycloak.OAuth2Constants;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.provider.ProviderConfigProperty; import org.keycloak.provider.ProviderConfigProperty;
/** /**
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a> * @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/ */
public class ClientScopesConditionFactory implements ClientPolicyConditionProviderFactory { public class ClientScopesConditionFactory extends AbstractClientPolicyConditionProviderFactory {
public static final String PROVIDER_ID = "client-scopes"; public static final String PROVIDER_ID = "client-scopes";
@ -42,6 +40,8 @@ public class ClientScopesConditionFactory implements ClientPolicyConditionProvid
private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>(); private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>();
static { static {
addCommonConfigProperties(configProperties);
ProviderConfigProperty property = new ProviderConfigProperty(SCOPES, PROVIDER_ID + "-condition.label", PROVIDER_ID + "-condition.tooltip", ProviderConfigProperty.MULTIVALUED_STRING_TYPE, OAuth2Constants.OFFLINE_ACCESS); ProviderConfigProperty property = new ProviderConfigProperty(SCOPES, PROVIDER_ID + "-condition.label", PROVIDER_ID + "-condition.tooltip", ProviderConfigProperty.MULTIVALUED_STRING_TYPE, OAuth2Constants.OFFLINE_ACCESS);
configProperties.add(property); configProperties.add(property);
property = new ProviderConfigProperty(TYPE, "Scope Type", property = new ProviderConfigProperty(TYPE, "Scope Type",
@ -57,18 +57,6 @@ public class ClientScopesConditionFactory implements ClientPolicyConditionProvid
return new ClientScopesCondition(session); return new ClientScopesCondition(session);
} }
@Override
public void init(Scope config) {
}
@Override
public void postInit(KeycloakSessionFactory factory) {
}
@Override
public void close() {
}
@Override @Override
public String getId() { public String getId() {
return PROVIDER_ID; return PROVIDER_ID;
@ -83,5 +71,4 @@ public class ClientScopesConditionFactory implements ClientPolicyConditionProvid
public List<ProviderConfigProperty> getConfigProperties() { public List<ProviderConfigProperty> getConfigProperties() {
return configProperties; return configProperties;
} }
} }

View file

@ -21,15 +21,13 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.keycloak.Config.Scope;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.provider.ProviderConfigProperty; import org.keycloak.provider.ProviderConfigProperty;
/** /**
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a> * @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/ */
public class ClientUpdaterContextConditionFactory implements ClientPolicyConditionProviderFactory { public class ClientUpdaterContextConditionFactory extends AbstractClientPolicyConditionProviderFactory {
public static final String PROVIDER_ID = "client-updater-context"; public static final String PROVIDER_ID = "client-updater-context";
@ -43,6 +41,8 @@ public class ClientUpdaterContextConditionFactory implements ClientPolicyConditi
private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>(); private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>();
static { static {
addCommonConfigProperties(configProperties);
ProviderConfigProperty property; ProviderConfigProperty property;
property = new ProviderConfigProperty(UPDATE_CLIENT_SOURCE, "Update Client Context", "Specifies the context how is client created or updated. " + property = new ProviderConfigProperty(UPDATE_CLIENT_SOURCE, "Update Client Context", "Specifies the context how is client created or updated. " +
"ByInitialAccessToken is usually OpenID Connect client registration with the initial access token. " + "ByInitialAccessToken is usually OpenID Connect client registration with the initial access token. " +
@ -59,18 +59,6 @@ public class ClientUpdaterContextConditionFactory implements ClientPolicyConditi
return new ClientUpdaterContextCondition(session); return new ClientUpdaterContextCondition(session);
} }
@Override
public void init(Scope config) {
}
@Override
public void postInit(KeycloakSessionFactory factory) {
}
@Override
public void close() {
}
@Override @Override
public String getId() { public String getId() {
return PROVIDER_ID; return PROVIDER_ID;
@ -85,5 +73,4 @@ public class ClientUpdaterContextConditionFactory implements ClientPolicyConditi
public List<ProviderConfigProperty> getConfigProperties() { public List<ProviderConfigProperty> getConfigProperties() {
return configProperties; return configProperties;
} }
} }

View file

@ -20,15 +20,13 @@ package org.keycloak.services.clientpolicy.condition;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.keycloak.Config.Scope;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.provider.ProviderConfigProperty; import org.keycloak.provider.ProviderConfigProperty;
/** /**
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a> * @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/ */
public class ClientUpdaterSourceGroupsConditionFactory implements ClientPolicyConditionProviderFactory { public class ClientUpdaterSourceGroupsConditionFactory extends AbstractClientPolicyConditionProviderFactory {
public static final String PROVIDER_ID = "client-updater-source-groups"; public static final String PROVIDER_ID = "client-updater-source-groups";
@ -37,6 +35,8 @@ public class ClientUpdaterSourceGroupsConditionFactory implements ClientPolicyCo
private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>(); private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>();
static { static {
addCommonConfigProperties(configProperties);
ProviderConfigProperty property; ProviderConfigProperty property;
property = new ProviderConfigProperty(GROUPS, PROVIDER_ID + ".label", PROVIDER_ID + ".tooltip", ProviderConfigProperty.MULTIVALUED_STRING_TYPE, "topGroup"); property = new ProviderConfigProperty(GROUPS, PROVIDER_ID + ".label", PROVIDER_ID + ".tooltip", ProviderConfigProperty.MULTIVALUED_STRING_TYPE, "topGroup");
configProperties.add(property); configProperties.add(property);
@ -47,18 +47,6 @@ public class ClientUpdaterSourceGroupsConditionFactory implements ClientPolicyCo
return new ClientUpdaterSourceGroupsCondition(session); return new ClientUpdaterSourceGroupsCondition(session);
} }
@Override
public void init(Scope config) {
}
@Override
public void postInit(KeycloakSessionFactory factory) {
}
@Override
public void close() {
}
@Override @Override
public String getId() { public String getId() {
return PROVIDER_ID; return PROVIDER_ID;
@ -73,5 +61,4 @@ public class ClientUpdaterSourceGroupsConditionFactory implements ClientPolicyCo
public List<ProviderConfigProperty> getConfigProperties() { public List<ProviderConfigProperty> getConfigProperties() {
return configProperties; return configProperties;
} }
} }

View file

@ -17,43 +17,37 @@
package org.keycloak.services.clientpolicy.condition; package org.keycloak.services.clientpolicy.condition;
import java.util.Arrays; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.keycloak.Config.Scope;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.provider.ProviderConfigProperty; import org.keycloak.provider.ProviderConfigProperty;
/** /**
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a> * @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/ */
public class ClientUpdaterSourceHostsConditionFactory implements ClientPolicyConditionProviderFactory { public class ClientUpdaterSourceHostsConditionFactory extends AbstractClientPolicyConditionProviderFactory {
public static final String PROVIDER_ID = "client-updater-source-host"; public static final String PROVIDER_ID = "client-updater-source-host";
public static final String TRUSTED_HOSTS = "trusted-hosts"; public static final String TRUSTED_HOSTS = "trusted-hosts";
private static final ProviderConfigProperty TRUSTED_HOSTS_PROPERTY = new ProviderConfigProperty(TRUSTED_HOSTS, "client-updater-trusted-hosts.label", private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>();
static {
addCommonConfigProperties(configProperties);
ProviderConfigProperty property;
property = new ProviderConfigProperty(TRUSTED_HOSTS, "client-updater-trusted-hosts.label",
"client-updater-trusted-hosts.tooltip", ProviderConfigProperty.MULTIVALUED_STRING_TYPE, null); "client-updater-trusted-hosts.tooltip", ProviderConfigProperty.MULTIVALUED_STRING_TYPE, null);
configProperties.add(property);
}
@Override @Override
public ClientPolicyConditionProvider create(KeycloakSession session) { public ClientPolicyConditionProvider create(KeycloakSession session) {
return new ClientUpdaterSourceHostsCondition(session); return new ClientUpdaterSourceHostsCondition(session);
} }
@Override
public void init(Scope config) {
}
@Override
public void postInit(KeycloakSessionFactory factory) {
}
@Override
public void close() {
}
@Override @Override
public String getId() { public String getId() {
return PROVIDER_ID; return PROVIDER_ID;
@ -66,7 +60,6 @@ public class ClientUpdaterSourceHostsConditionFactory implements ClientPolicyCon
@Override @Override
public List<ProviderConfigProperty> getConfigProperties() { public List<ProviderConfigProperty> getConfigProperties() {
return Arrays.asList(TRUSTED_HOSTS_PROPERTY); return configProperties;
} }
} }

View file

@ -20,15 +20,13 @@ package org.keycloak.services.clientpolicy.condition;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.keycloak.Config.Scope;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.provider.ProviderConfigProperty; import org.keycloak.provider.ProviderConfigProperty;
/** /**
* @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a> * @author <a href="mailto:takashi.norimatsu.ws@hitachi.com">Takashi Norimatsu</a>
*/ */
public class ClientUpdaterSourceRolesConditionFactory implements ClientPolicyConditionProviderFactory { public class ClientUpdaterSourceRolesConditionFactory extends AbstractClientPolicyConditionProviderFactory {
public static final String PROVIDER_ID = "client-updater-source-roles"; public static final String PROVIDER_ID = "client-updater-source-roles";
@ -37,6 +35,8 @@ public class ClientUpdaterSourceRolesConditionFactory implements ClientPolicyCon
private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>(); private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>();
static { static {
addCommonConfigProperties(configProperties);
ProviderConfigProperty property; ProviderConfigProperty property;
property = new ProviderConfigProperty(ROLES, PROVIDER_ID + ".label", PROVIDER_ID + ".tooltip", ProviderConfigProperty.MULTIVALUED_STRING_TYPE, "admin"); property = new ProviderConfigProperty(ROLES, PROVIDER_ID + ".label", PROVIDER_ID + ".tooltip", ProviderConfigProperty.MULTIVALUED_STRING_TYPE, "admin");
configProperties.add(property); configProperties.add(property);
@ -47,18 +47,6 @@ public class ClientUpdaterSourceRolesConditionFactory implements ClientPolicyCon
return new ClientUpdaterSourceRolesCondition(session); return new ClientUpdaterSourceRolesCondition(session);
} }
@Override
public void init(Scope config) {
}
@Override
public void postInit(KeycloakSessionFactory factory) {
}
@Override
public void close() {
}
@Override @Override
public String getId() { public String getId() {
return PROVIDER_ID; return PROVIDER_ID;
@ -67,12 +55,10 @@ public class ClientUpdaterSourceRolesConditionFactory implements ClientPolicyCon
@Override @Override
public String getHelpText() { public String getHelpText() {
return "The condition checks the role of the entity who tries to create/update the client to determine whether the policy is applied."; return "The condition checks the role of the entity who tries to create/update the client to determine whether the policy is applied.";
} }
@Override @Override
public List<ProviderConfigProperty> getConfigProperties() { public List<ProviderConfigProperty> getConfigProperties() {
return configProperties; return configProperties;
} }
} }