KEYCLOAK-904 Consents support. Added scopeParamRequired flag to RoleModel
This commit is contained in:
1 parent
8cc4c8c5e2
commit
046edbbd54
53 files changed
+495
-171
No files matched your search
@@ -11,7 +11,7 @@ public interface MigrationModel {
|
||||
/**
|
||||
* Must have the form of major.minor.micro as the version is parsed and numbers are compared
|
||||
*/
|
||||
public static final String LATEST_VERSION = "1.5.0";
|
||||
public static final String LATEST_VERSION = "1.6.0";
|
||||
|
||||
String getStoredVersion();
|
||||
void setStoredVersion(String version);
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.jboss.logging.Logger;
|
||||
import org.keycloak.migration.migrators.MigrateTo1_3_0;
|
||||
import org.keycloak.migration.migrators.MigrateTo1_4_0;
|
||||
import org.keycloak.migration.migrators.MigrateTo1_5_0;
|
||||
import org.keycloak.migration.migrators.MigrateTo1_6_0;
|
||||
import org.keycloak.migration.migrators.MigrationTo1_2_0_CR1;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
|
||||
@@ -47,6 +48,12 @@ public class MigrationModelManager {
|
||||
}
|
||||
new MigrateTo1_5_0().migrate(session);
|
||||
}
|
||||
if (stored == null || stored.lessThan(MigrateTo1_6_0.VERSION)) {
|
||||
if (stored != null) {
|
||||
logger.debug("Migrating older model to 1.6.0 updates");
|
||||
}
|
||||
new MigrateTo1_6_0().migrate(session);
|
||||
}
|
||||
|
||||
model.setStoredVersion(MigrationModel.LATEST_VERSION);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.keycloak.migration.migrators;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.keycloak.migration.ModelVersion;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
public class MigrateTo1_6_0 {
|
||||
|
||||
public static final ModelVersion VERSION = new ModelVersion("1.6.0");
|
||||
|
||||
public void migrate(KeycloakSession session) {
|
||||
List<RealmModel> realms = session.realms().getRealms();
|
||||
for (RealmModel realm : realms) {
|
||||
KeycloakModelUtils.setupOfflineTokens(realm);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
|
||||
import java.util.List;
|
||||
@@ -26,7 +27,9 @@ public class MigrationTo1_2_0_CR1 {
|
||||
client.setFullScopeAllowed(false);
|
||||
|
||||
for (String role : Constants.BROKER_SERVICE_ROLES) {
|
||||
client.addRole(role).setDescription("${role_"+ role.toLowerCase().replaceAll("_", "-") +"}");
|
||||
RoleModel roleModel = client.addRole(role);
|
||||
roleModel.setDescription("${role_" + role.toLowerCase().replaceAll("_", "-") + "}");
|
||||
roleModel.setScopeParamRequired(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,9 +109,6 @@ public interface ClientModel extends RoleContainerModel {
|
||||
boolean isServiceAccountsEnabled();
|
||||
void setServiceAccountsEnabled(boolean serviceAccountsEnabled);
|
||||
|
||||
boolean isOfflineTokensEnabled();
|
||||
void setOfflineTokensEnabled(boolean offlineTokensEnabled);
|
||||
|
||||
Set<RoleModel> getScopeMappings();
|
||||
void addScopeMapping(RoleModel role);
|
||||
void deleteScopeMapping(RoleModel role);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.keycloak.models;
|
||||
|
||||
import org.keycloak.OAuth2Constants;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
@@ -16,4 +18,5 @@ public interface Constants {
|
||||
String INSTALLED_APP_URL = "http://localhost";
|
||||
String READ_TOKEN_ROLE = "read-token";
|
||||
String[] BROKER_SERVICE_ROLES = {READ_TOKEN_ROLE};
|
||||
String OFFLINE_ACCESS_ROLE = OAuth2Constants.OFFLINE_ACCESS;
|
||||
}
|
||||
@@ -26,6 +26,7 @@ public class ImpersonationConstants {
|
||||
if (realmAdminApp.getRole(IMPERSONATION_ROLE) != null) return;
|
||||
RoleModel impersonationRole = realmAdminApp.addRole(IMPERSONATION_ROLE);
|
||||
impersonationRole.setDescription("${role_" + IMPERSONATION_ROLE + "}");
|
||||
impersonationRole.setScopeParamRequired(false);
|
||||
adminRole.addCompositeRole(impersonationRole);
|
||||
}
|
||||
|
||||
@@ -36,6 +37,7 @@ public class ImpersonationConstants {
|
||||
if (realmAdminApp.getRole(IMPERSONATION_ROLE) != null) return;
|
||||
RoleModel impersonationRole = realmAdminApp.addRole(IMPERSONATION_ROLE);
|
||||
impersonationRole.setDescription("${role_" + IMPERSONATION_ROLE + "}");
|
||||
impersonationRole.setScopeParamRequired(false);
|
||||
RoleModel adminRole = realmAdminApp.getRole(AdminRoles.REALM_ADMIN);
|
||||
adminRole.addCompositeRole(impersonationRole);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ public interface RoleModel {
|
||||
|
||||
void setName(String name);
|
||||
|
||||
boolean isScopeParamRequired();
|
||||
|
||||
void setScopeParamRequired(boolean scopeParamRequired);
|
||||
|
||||
boolean isComposite();
|
||||
|
||||
void addCompositeRole(RoleModel role);
|
||||
|
||||
@@ -28,7 +28,6 @@ public class ClientEntity extends AbstractIdentifiableEntity {
|
||||
private boolean bearerOnly;
|
||||
private boolean consentRequired;
|
||||
private boolean serviceAccountsEnabled;
|
||||
private boolean offlineTokensEnabled;
|
||||
private boolean directGrantsOnly;
|
||||
private int nodeReRegistrationTimeout;
|
||||
|
||||
@@ -229,14 +228,6 @@ public class ClientEntity extends AbstractIdentifiableEntity {
|
||||
this.serviceAccountsEnabled = serviceAccountsEnabled;
|
||||
}
|
||||
|
||||
public boolean isOfflineTokensEnabled() {
|
||||
return offlineTokensEnabled;
|
||||
}
|
||||
|
||||
public void setOfflineTokensEnabled(boolean offlineTokensEnabled) {
|
||||
this.offlineTokensEnabled = offlineTokensEnabled;
|
||||
}
|
||||
|
||||
public boolean isDirectGrantsOnly() {
|
||||
return directGrantsOnly;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public class RoleEntity extends AbstractIdentifiableEntity {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private boolean scopeParamRequired;
|
||||
|
||||
private List<String> compositeRoleIds;
|
||||
|
||||
@@ -31,6 +32,14 @@ public class RoleEntity extends AbstractIdentifiableEntity {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isScopeParamRequired() {
|
||||
return scopeParamRequired;
|
||||
}
|
||||
|
||||
public void setScopeParamRequired(boolean scopeParamRequired) {
|
||||
this.scopeParamRequired = scopeParamRequired;
|
||||
}
|
||||
|
||||
public List<String> getCompositeRoleIds() {
|
||||
return compositeRoleIds;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.bouncycastle.openssl.PEMWriter;
|
||||
import org.keycloak.constants.KerberosConstants;
|
||||
import org.keycloak.constants.ServiceAccountConstants;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.models.KeycloakSessionTask;
|
||||
@@ -360,4 +361,13 @@ public final class KeycloakModelUtils {
|
||||
public static String toLowerCaseSafe(String str) {
|
||||
return str==null ? null : str.toLowerCase();
|
||||
}
|
||||
|
||||
public static void setupOfflineTokens(RealmModel realm) {
|
||||
if (realm.getRole(Constants.OFFLINE_ACCESS_ROLE) == null) {
|
||||
RoleModel role = realm.addRole(Constants.OFFLINE_ACCESS_ROLE);
|
||||
role.setDescription("${role_offline-access}");
|
||||
role.setScopeParamRequired(true);
|
||||
realm.addDefaultRole(Constants.OFFLINE_ACCESS_ROLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,7 @@ public class ModelToRepresentation {
|
||||
rep.setId(role.getId());
|
||||
rep.setName(role.getName());
|
||||
rep.setDescription(role.getDescription());
|
||||
rep.setScopeParamRequired(role.isScopeParamRequired());
|
||||
rep.setComposite(role.isComposite());
|
||||
return rep;
|
||||
}
|
||||
@@ -303,7 +304,6 @@ public class ModelToRepresentation {
|
||||
rep.setBearerOnly(clientModel.isBearerOnly());
|
||||
rep.setConsentRequired(clientModel.isConsentRequired());
|
||||
rep.setServiceAccountsEnabled(clientModel.isServiceAccountsEnabled());
|
||||
rep.setOfflineTokensEnabled(clientModel.isOfflineTokensEnabled());
|
||||
rep.setDirectGrantsOnly(clientModel.isDirectGrantsOnly());
|
||||
rep.setSurrogateAuthRequired(clientModel.isSurrogateAuthRequired());
|
||||
rep.setBaseUrl(clientModel.getBaseUrl());
|
||||
|
||||
@@ -181,6 +181,8 @@ public class RepresentationToModel {
|
||||
// Application role may already exists (for example if it is defaultRole)
|
||||
RoleModel role = roleRep.getId()!=null ? client.addRole(roleRep.getId(), roleRep.getName()) : client.addRole(roleRep.getName());
|
||||
role.setDescription(roleRep.getDescription());
|
||||
boolean scopeParamRequired = roleRep.isScopeParamRequired()==null ? false : roleRep.isScopeParamRequired();
|
||||
role.setScopeParamRequired(scopeParamRequired);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -633,6 +635,8 @@ public class RepresentationToModel {
|
||||
public static void createRole(RealmModel newRealm, RoleRepresentation roleRep) {
|
||||
RoleModel role = roleRep.getId()!=null ? newRealm.addRole(roleRep.getId(), roleRep.getName()) : newRealm.addRole(roleRep.getName());
|
||||
if (roleRep.getDescription() != null) role.setDescription(roleRep.getDescription());
|
||||
boolean scopeParamRequired = roleRep.isScopeParamRequired() == null ? false : roleRep.isScopeParamRequired();
|
||||
role.setScopeParamRequired(scopeParamRequired);
|
||||
}
|
||||
|
||||
private static void addComposites(RoleModel role, RoleRepresentation roleRep, RealmModel realm) {
|
||||
@@ -692,7 +696,6 @@ public class RepresentationToModel {
|
||||
if (resourceRep.isBearerOnly() != null) client.setBearerOnly(resourceRep.isBearerOnly());
|
||||
if (resourceRep.isConsentRequired() != null) client.setConsentRequired(resourceRep.isConsentRequired());
|
||||
if (resourceRep.isServiceAccountsEnabled() != null) client.setServiceAccountsEnabled(resourceRep.isServiceAccountsEnabled());
|
||||
if (resourceRep.isOfflineTokensEnabled() != null) client.setOfflineTokensEnabled(resourceRep.isOfflineTokensEnabled());
|
||||
if (resourceRep.isDirectGrantsOnly() != null) client.setDirectGrantsOnly(resourceRep.isDirectGrantsOnly());
|
||||
if (resourceRep.isPublicClient() != null) client.setPublicClient(resourceRep.isPublicClient());
|
||||
if (resourceRep.isFrontchannelLogout() != null) client.setFrontchannelLogout(resourceRep.isFrontchannelLogout());
|
||||
@@ -789,7 +792,6 @@ public class RepresentationToModel {
|
||||
if (rep.isBearerOnly() != null) resource.setBearerOnly(rep.isBearerOnly());
|
||||
if (rep.isConsentRequired() != null) resource.setConsentRequired(rep.isConsentRequired());
|
||||
if (rep.isServiceAccountsEnabled() != null) resource.setServiceAccountsEnabled(rep.isServiceAccountsEnabled());
|
||||
if (rep.isOfflineTokensEnabled() != null) resource.setOfflineTokensEnabled(rep.isOfflineTokensEnabled());
|
||||
if (rep.isDirectGrantsOnly() != null) resource.setDirectGrantsOnly(rep.isDirectGrantsOnly());
|
||||
if (rep.isPublicClient() != null) resource.setPublicClient(rep.isPublicClient());
|
||||
if (rep.isFullScopeAllowed() != null) resource.setFullScopeAllowed(rep.isFullScopeAllowed());
|
||||
|
||||
Reference in new issue
Block a user