KEYCLOAK-1795 Add just one clientAuthenticatorType per client
This commit is contained in:
1 parent
25e53db96f
commit
bc189554aa
38 files changed
+275
-206
No files matched your search
@@ -2,6 +2,7 @@ package org.keycloak.migration.migrators;
|
||||
|
||||
import org.keycloak.migration.ModelVersion;
|
||||
import org.keycloak.models.AuthenticationFlowModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ImpersonationConstants;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OTPPolicy;
|
||||
@@ -38,6 +39,10 @@ public class MigrateTo1_5_0 {
|
||||
} else {
|
||||
realm.setClientAuthenticationFlow(realm.getFlowByAlias(DefaultAuthenticationFlows.CLIENT_AUTHENTICATION_FLOW));
|
||||
}
|
||||
|
||||
for (ClientModel client : realm.getClients()) {
|
||||
client.setClientAuthenticatorType(KeycloakModelUtils.getDefaultClientAuthenticatorType());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -75,6 +75,9 @@ public interface ClientModel extends RoleContainerModel {
|
||||
|
||||
void setNodeReRegistrationTimeout(int timeout);
|
||||
|
||||
String getClientAuthenticatorType();
|
||||
void setClientAuthenticatorType(String clientAuthenticatorType);
|
||||
|
||||
boolean validateSecret(String secret);
|
||||
String getSecret();
|
||||
public void setSecret(String secret);
|
||||
|
||||
@@ -14,6 +14,7 @@ public class ClientEntity extends AbstractIdentifiableEntity {
|
||||
private String name;
|
||||
private String realmId;
|
||||
private boolean enabled;
|
||||
private String clientAuthenticatorType;
|
||||
private String secret;
|
||||
private String protocol;
|
||||
private int notBefore;
|
||||
@@ -67,6 +68,14 @@ public class ClientEntity extends AbstractIdentifiableEntity {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getClientAuthenticatorType() {
|
||||
return clientAuthenticatorType;
|
||||
}
|
||||
|
||||
public void setClientAuthenticatorType(String clientAuthenticatorType) {
|
||||
this.clientAuthenticatorType = clientAuthenticatorType;
|
||||
}
|
||||
|
||||
public String getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
@@ -180,12 +180,17 @@ public final class KeycloakModelUtils {
|
||||
return secret;
|
||||
}
|
||||
|
||||
public static String getDefaultClientAuthenticatorType() {
|
||||
return "client-secret";
|
||||
}
|
||||
|
||||
public static String generateCodeSecret() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public static ClientModel createClient(RealmModel realm, String name) {
|
||||
ClientModel app = realm.addClient(name);
|
||||
app.setClientAuthenticatorType(getDefaultClientAuthenticatorType());
|
||||
generateSecret(app);
|
||||
app.setFullScopeAllowed(true);
|
||||
|
||||
|
||||
@@ -307,6 +307,7 @@ public class ModelToRepresentation {
|
||||
rep.setBaseUrl(clientModel.getBaseUrl());
|
||||
rep.setNotBefore(clientModel.getNotBefore());
|
||||
rep.setNodeReRegistrationTimeout(clientModel.getNodeReRegistrationTimeout());
|
||||
rep.setClientAuthenticatorType(clientModel.getClientAuthenticatorType());
|
||||
|
||||
Set<String> redirectUris = clientModel.getRedirectUris();
|
||||
if (redirectUris != null) {
|
||||
|
||||
@@ -692,6 +692,12 @@ public class RepresentationToModel {
|
||||
client.setNotBefore(resourceRep.getNotBefore());
|
||||
}
|
||||
|
||||
if (resourceRep.getClientAuthenticatorType() != null) {
|
||||
client.setClientAuthenticatorType(resourceRep.getClientAuthenticatorType());
|
||||
} else {
|
||||
client.setClientAuthenticatorType(KeycloakModelUtils.getDefaultClientAuthenticatorType());
|
||||
}
|
||||
|
||||
client.setSecret(resourceRep.getSecret());
|
||||
if (client.getSecret() == null) {
|
||||
KeycloakModelUtils.generateSecret(client);
|
||||
@@ -770,6 +776,7 @@ public class RepresentationToModel {
|
||||
if (rep.getBaseUrl() != null) resource.setBaseUrl(rep.getBaseUrl());
|
||||
if (rep.isSurrogateAuthRequired() != null) resource.setSurrogateAuthRequired(rep.isSurrogateAuthRequired());
|
||||
if (rep.getNodeReRegistrationTimeout() != null) resource.setNodeReRegistrationTimeout(rep.getNodeReRegistrationTimeout());
|
||||
if (rep.getClientAuthenticatorType() != null) resource.setClientAuthenticatorType(rep.getClientAuthenticatorType());
|
||||
resource.updateClient();
|
||||
|
||||
if (rep.getProtocol() != null) resource.setProtocol(rep.getProtocol());
|
||||
|
||||
@@ -145,6 +145,16 @@ public class ClientAdapter implements ClientModel {
|
||||
entity.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientAuthenticatorType() {
|
||||
return entity.getClientAuthenticatorType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientAuthenticatorType(String clientAuthenticatorType) {
|
||||
entity.setClientAuthenticatorType(clientAuthenticatorType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateSecret(String secret) {
|
||||
return secret.equals(entity.getSecret());
|
||||
|
||||
+12
@@ -95,6 +95,18 @@ public class ClientAdapter implements ClientModel {
|
||||
updated.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientAuthenticatorType() {
|
||||
if (updated != null) return updated.getClientAuthenticatorType();
|
||||
return cached.getClientAuthenticatorType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientAuthenticatorType(String clientAuthenticatorType) {
|
||||
getDelegateForUpdate();
|
||||
updated.setClientAuthenticatorType(clientAuthenticatorType);
|
||||
}
|
||||
|
||||
public boolean validateSecret(String secret) {
|
||||
return secret.equals(getSecret());
|
||||
}
|
||||
|
||||
+6
@@ -29,6 +29,7 @@ public class CachedClient implements Serializable {
|
||||
private String realm;
|
||||
private Set<String> redirectUris = new HashSet<String>();
|
||||
private boolean enabled;
|
||||
private String clientAuthenticatorType;
|
||||
private String secret;
|
||||
private String protocol;
|
||||
private Map<String, String> attributes = new HashMap<String, String>();
|
||||
@@ -53,6 +54,7 @@ public class CachedClient implements Serializable {
|
||||
|
||||
public CachedClient(RealmCache cache, RealmProvider delegate, RealmModel realm, ClientModel model) {
|
||||
id = model.getId();
|
||||
clientAuthenticatorType = model.getClientAuthenticatorType();
|
||||
secret = model.getSecret();
|
||||
clientId = model.getClientId();
|
||||
name = model.getName();
|
||||
@@ -112,6 +114,10 @@ public class CachedClient implements Serializable {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public String getClientAuthenticatorType() {
|
||||
return clientAuthenticatorType;
|
||||
}
|
||||
|
||||
public String getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
@@ -151,6 +151,16 @@ public class ClientAdapter implements ClientModel {
|
||||
entity.getRedirectUris().remove(redirectUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientAuthenticatorType() {
|
||||
return entity.getClientAuthenticatorType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientAuthenticatorType(String clientAuthenticatorType) {
|
||||
entity.setClientAuthenticatorType(clientAuthenticatorType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSecret() {
|
||||
return entity.getSecret();
|
||||
|
||||
@@ -40,6 +40,8 @@ public class ClientEntity {
|
||||
private boolean enabled;
|
||||
@Column(name="SECRET")
|
||||
private String secret;
|
||||
@Column(name="CLIENT_AUTHENTICATOR_TYPE")
|
||||
private String clientAuthenticatorType;
|
||||
@Column(name="NOT_BEFORE")
|
||||
private int notBefore;
|
||||
@Column(name="PUBLIC_CLIENT")
|
||||
@@ -170,6 +172,14 @@ public class ClientEntity {
|
||||
this.redirectUris = redirectUris;
|
||||
}
|
||||
|
||||
public String getClientAuthenticatorType() {
|
||||
return clientAuthenticatorType;
|
||||
}
|
||||
|
||||
public void setClientAuthenticatorType(String clientAuthenticatorType) {
|
||||
this.clientAuthenticatorType = clientAuthenticatorType;
|
||||
}
|
||||
|
||||
public String getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
+11
@@ -141,6 +141,17 @@ public class ClientAdapter extends AbstractMongoAdapter<MongoClientEntity> imple
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientAuthenticatorType() {
|
||||
return getMongoEntity().getClientAuthenticatorType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientAuthenticatorType(String clientAuthenticatorType) {
|
||||
getMongoEntity().setClientAuthenticatorType(clientAuthenticatorType);
|
||||
updateMongoEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateSecret(String secret) {
|
||||
return secret.equals(getMongoEntity().getSecret());
|
||||
|
||||
Reference in new issue
Block a user