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
@@ -61,6 +61,12 @@
|
|||||||
</column>
|
</column>
|
||||||
</addColumn>
|
</addColumn>
|
||||||
|
|
||||||
|
<addColumn tableName="CLIENT">
|
||||||
|
<column name="CLIENT_AUTHENTICATOR_TYPE" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
</addColumn>
|
||||||
|
|
||||||
<!-- Sybase specific hacks -->
|
<!-- Sybase specific hacks -->
|
||||||
<modifySql dbms="sybase">
|
<modifySql dbms="sybase">
|
||||||
<regExpReplace replace=".*(SET DEFAULT NULL)" with="SELECT 1" />
|
<regExpReplace replace=".*(SET DEFAULT NULL)" with="SELECT 1" />
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class ClientRepresentation {
|
|||||||
protected String baseUrl;
|
protected String baseUrl;
|
||||||
protected Boolean surrogateAuthRequired;
|
protected Boolean surrogateAuthRequired;
|
||||||
protected Boolean enabled;
|
protected Boolean enabled;
|
||||||
|
protected String clientAuthenticatorType;
|
||||||
protected String secret;
|
protected String secret;
|
||||||
protected String[] defaultRoles;
|
protected String[] defaultRoles;
|
||||||
protected List<String> redirectUris;
|
protected List<String> redirectUris;
|
||||||
@@ -89,6 +90,14 @@ public class ClientRepresentation {
|
|||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getClientAuthenticatorType() {
|
||||||
|
return clientAuthenticatorType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientAuthenticatorType(String clientAuthenticatorType) {
|
||||||
|
this.clientAuthenticatorType = clientAuthenticatorType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSecret() {
|
public String getSecret() {
|
||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -921,7 +921,7 @@ public class SecretQuestionRequiredActionFactory implements RequiredActionFactor
|
|||||||
in the location accessible to your client application
|
in the location accessible to your client application
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
Uploaded in Keycloak admin console - This option is useful if you already has existing private key of your client.
|
Uploaded in Keycloak admin console - This option is useful if you already have existing private key of your client.
|
||||||
In this case, you just need to upload the public key and certificate to the Keycloak server.
|
In this case, you just need to upload the public key and certificate to the Keycloak server.
|
||||||
</listitem>
|
</listitem>
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
@@ -993,7 +993,8 @@ public class SecretQuestionRequiredActionFactory implements RequiredActionFactor
|
|||||||
<para>
|
<para>
|
||||||
Finally you need to configure admin console . You need to create new client authentication flow and define execution
|
Finally you need to configure admin console . You need to create new client authentication flow and define execution
|
||||||
with your authenticator (you can also add the builtin authenticators and configure requirements etc)
|
with your authenticator (you can also add the builtin authenticators and configure requirements etc)
|
||||||
and finally configure Clients binding . See <link linkend="adding_authenticator">Adding Authenticator</link> for more details.
|
and finally configure Clients binding . See <link linkend="adding_authenticator">Adding Authenticator</link> for more details. Then
|
||||||
|
you need to go to Client credentials tab and choose the method for authentication your client and configure client credentials (if possible).
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
"realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB",
|
"realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB",
|
||||||
"auth-server-url" : "http://localhost:8080/auth",
|
"auth-server-url" : "http://localhost:8080/auth",
|
||||||
"ssl-required" : "external",
|
"ssl-required" : "external",
|
||||||
"resource" : "product-sa-client",
|
"resource" : "product-sa-client-jwt-auth",
|
||||||
"credentials": {
|
"credentials": {
|
||||||
"jwt": {
|
"jwt": {
|
||||||
"client-keystore-file": "classpath:keystore-client.jks",
|
"client-keystore-file": "classpath:keystore-client.jks",
|
||||||
|
|||||||
@@ -78,6 +78,13 @@
|
|||||||
"email" : "service-account-product-sa-client@placeholder.org",
|
"email" : "service-account-product-sa-client@placeholder.org",
|
||||||
"serviceAccountClientId": "product-sa-client",
|
"serviceAccountClientId": "product-sa-client",
|
||||||
"realmRoles": [ "user" ]
|
"realmRoles": [ "user" ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"username" : "service-account-product-sa-client-jwt-auth",
|
||||||
|
"enabled": true,
|
||||||
|
"email" : "service-account-product-sa-client-jwt-auth@placeholder.org",
|
||||||
|
"serviceAccountClientId": "product-sa-client-jwt-auth",
|
||||||
|
"realmRoles": [ "user" ]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"roles" : {
|
"roles" : {
|
||||||
@@ -173,7 +180,13 @@
|
|||||||
"clientId": "product-sa-client",
|
"clientId": "product-sa-client",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"secret": "password",
|
"secret": "password",
|
||||||
|
"serviceAccountsEnabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"clientId": "product-sa-client-jwt-auth",
|
||||||
|
"enabled": true,
|
||||||
"serviceAccountsEnabled": true,
|
"serviceAccountsEnabled": true,
|
||||||
|
"clientAuthenticatorType": "client-jwt",
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"jwt.credential.certificate": "MIICnTCCAYUCBgFPPLDaTzANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdjbGllbnQxMB4XDTE1MDgxNzE3MjI0N1oXDTI1MDgxNzE3MjQyN1owEjEQMA4GA1UEAwwHY2xpZW50MTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIUjjgv+V3s96O+Za9002Lp/trtGuHBeaeVL9dFKMKzO2MPqdRmHB4PqNlDdd28Rwf5Xn6iWdFpyUKOnI/yXDLhdcuFpR0sMNK/C9Lt+hSpPFLuzDqgtPgDotlMxiHIWDOZ7g9/gPYNXbNvjv8nSiyqoguoCQiiafW90bPHsiVLdP7ZIUwCcfi1qQm7FhxRJ1NiW5dvUkuCnnWEf0XR+Wzc5eC9EgB0taLFiPsSEIlWMm5xlahYyXkPdNOqZjiRnrTWm5Y4uk8ZcsD/KbPTf/7t7cQXipVaswgjdYi1kK2/zRwOhg1QwWFX/qmvdd+fLxV0R6VqRDhn7Qep2cxwMxLsCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAKE6OA46sf20bz8LZPoiNsqRwBUDkaMGXfnob7s/hJZIIwDEx0IAQ3uKsG7q9wb+aA6s+v7S340zb2k3IxuhFaHaZpAd4CyR5cn1FHylbzoZ7rI/3ASqHDqpljdJaFqPH+m7nZWtyDvtZf+gkZ8OjsndwsSBK1d/jMZPp29qYbl1+XfO7RCp/jDqro/R3saYFaIFiEZPeKn1hUJn6BO48vxH1xspSu9FmlvDOEAOz4AuM58z4zRMP49GcFdCWr1wkonJUHaSptJaQwmBwLFUkCbE5I1ixGMb7mjEud6Y5jhfzJiZMo2U8RfcjNbrN0diZl3jB6LQIwESnhYSghaTjNQ=="
|
"jwt.credential.certificate": "MIICnTCCAYUCBgFPPLDaTzANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdjbGllbnQxMB4XDTE1MDgxNzE3MjI0N1oXDTI1MDgxNzE3MjQyN1owEjEQMA4GA1UEAwwHY2xpZW50MTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIUjjgv+V3s96O+Za9002Lp/trtGuHBeaeVL9dFKMKzO2MPqdRmHB4PqNlDdd28Rwf5Xn6iWdFpyUKOnI/yXDLhdcuFpR0sMNK/C9Lt+hSpPFLuzDqgtPgDotlMxiHIWDOZ7g9/gPYNXbNvjv8nSiyqoguoCQiiafW90bPHsiVLdP7ZIUwCcfi1qQm7FhxRJ1NiW5dvUkuCnnWEf0XR+Wzc5eC9EgB0taLFiPsSEIlWMm5xlahYyXkPdNOqZjiRnrTWm5Y4uk8ZcsD/KbPTf/7t7cQXipVaswgjdYi1kK2/zRwOhg1QwWFX/qmvdd+fLxV0R6VqRDhn7Qep2cxwMxLsCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAKE6OA46sf20bz8LZPoiNsqRwBUDkaMGXfnob7s/hJZIIwDEx0IAQ3uKsG7q9wb+aA6s+v7S340zb2k3IxuhFaHaZpAd4CyR5cn1FHylbzoZ7rI/3ASqHDqpljdJaFqPH+m7nZWtyDvtZf+gkZ8OjsndwsSBK1d/jMZPp29qYbl1+XfO7RCp/jDqro/R3saYFaIFiEZPeKn1hUJn6BO48vxH1xspSu9FmlvDOEAOz4AuM58z4zRMP49GcFdCWr1wkonJUHaSptJaQwmBwLFUkCbE5I1ixGMb7mjEud6Y5jhfzJiZMo2U8RfcjNbrN0diZl3jB6LQIwESnhYSghaTjNQ=="
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-3
@@ -30,10 +30,42 @@ module.controller('ClientRoleListCtrl', function($scope, $location, realm, clien
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
module.controller('ClientCredentialsCtrl', function($scope, $location, realm, client, clientAuthenticatorProviders, Notifications) {
|
module.controller('ClientCredentialsCtrl', function($scope, $location, realm, client, clientAuthenticatorProviders, Client) {
|
||||||
$scope.realm = realm;
|
$scope.realm = realm;
|
||||||
$scope.client = client;
|
$scope.client = angular.copy(client);
|
||||||
$scope.clientAuthenticatorProviders = clientAuthenticatorProviders;
|
$scope.clientAuthenticatorProviders = clientAuthenticatorProviders;
|
||||||
|
|
||||||
|
var updateConfigButtonVisibility = function() {
|
||||||
|
for (var i=0 ; i<clientAuthenticatorProviders.length ; i++) {
|
||||||
|
var authenticator = clientAuthenticatorProviders[i];
|
||||||
|
if ($scope.client.clientAuthenticatorType === authenticator.id) {
|
||||||
|
$scope.configButtonVisible = authenticator.configurablePerClient;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
updateConfigButtonVisibility();
|
||||||
|
|
||||||
|
$scope.$watch('client', function() {
|
||||||
|
if (!angular.equals($scope.client, client)) {
|
||||||
|
|
||||||
|
console.log("Update client credentials!");
|
||||||
|
|
||||||
|
Client.update({
|
||||||
|
realm : realm.realm,
|
||||||
|
client : client.id
|
||||||
|
}, $scope.client, function() {
|
||||||
|
$scope.changed = false;
|
||||||
|
client = angular.copy($scope.client);
|
||||||
|
updateConfigButtonVisibility();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
$scope.configureAuthenticator = function() {
|
||||||
|
$location.url("/realms/" + realm.realm + "/clients/" + client.id + "/credentials/" + client.clientAuthenticatorType);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.controller('ClientSecretCtrl', function($scope, $location, realm, client, ClientSecret, Notifications) {
|
module.controller('ClientSecretCtrl', function($scope, $location, realm, client, ClientSecret, Notifications) {
|
||||||
@@ -115,7 +147,7 @@ module.controller('ClientGenericCredentialsCtrl', function($scope, $location, re
|
|||||||
client : client.id
|
client : client.id
|
||||||
}, $scope.client, function() {
|
}, $scope.client, function() {
|
||||||
$scope.changed = false;
|
$scope.changed = false;
|
||||||
client = $scope.client;
|
client = angular.copy($scope.client);
|
||||||
Notifications.success("Client authentication configuration has been saved to the client.");
|
Notifications.success("Client authentication configuration has been saved to the client.");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@
|
|||||||
<button class="btn btn-default" data-ng-click="copyFlow()">Copy</button>
|
<button class="btn btn-default" data-ng-click="copyFlow()">Copy</button>
|
||||||
<button class="btn btn-default" data-ng-hide="flow.builtIn" data-ng-click="removeFlow()">Delete</button>
|
<button class="btn btn-default" data-ng-hide="flow.builtIn" data-ng-click="removeFlow()">Delete</button>
|
||||||
<button class="btn btn-default" data-ng-hide="flow.builtIn" data-ng-click="addExecution()">Add Execution</button>
|
<button class="btn btn-default" data-ng-hide="flow.builtIn" data-ng-click="addExecution()">Add Execution</button>
|
||||||
<button class="btn btn-default" data-ng-hide="flow.builtIn" data-ng-click="addFlow()">Add Flow</button>
|
<button class="btn btn-default" data-ng-hide="flow.builtIn || flow.providerId === 'client-flow'" data-ng-click="addFlow()">Add Flow</button>
|
||||||
</div>
|
</div>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
+21
-18
@@ -7,24 +7,27 @@
|
|||||||
|
|
||||||
<kc-tabs-client></kc-tabs-client>
|
<kc-tabs-client></kc-tabs-client>
|
||||||
|
|
||||||
<table class="table table-striped table-bordered">
|
<form class="form-horizontal" name="clientForm" novalidate kc-read-only="!access.manageClients">
|
||||||
<thead>
|
<fieldset class="border-top">
|
||||||
<tr data-ng-hide="executions.length == 0">
|
<div class="form-group clearfix">
|
||||||
<th>Client Auth Type</th>
|
<label class="col-md-2 control-label" for="clientAuthenticatorType"> Client Authenticator</label>
|
||||||
<th></th>
|
<div class="col-md-2">
|
||||||
</tr>
|
<div>
|
||||||
</thead>
|
<select class="form-control" id="clientAuthenticatorType"
|
||||||
<tbody>
|
ng-model="client.clientAuthenticatorType"
|
||||||
<tr ng-repeat="authenticator in clientAuthenticatorProviders" data-ng-show="clientAuthenticatorProviders.length > 0">
|
ng-options="authenticator.id as authenticator.displayName for authenticator in clientAuthenticatorProviders"
|
||||||
<td ng-repeat="lev in execution.preLevels"></td>
|
required>
|
||||||
<td>{{authenticator.displayName|capitalize}}</td>
|
</select>
|
||||||
<td><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/credentials/{{authenticator.id}}" data-ng-show="authenticator.configurablePerClient">Configure</a></td>
|
</div>
|
||||||
</tr>
|
</div>
|
||||||
<tr data-ng-show="clientAuthenticatorProviders.length == 0">
|
<kc-tooltip>Client Authenticator used for authentication this client against Keycloak server</kc-tooltip>
|
||||||
<td>No client authenticators available</td>
|
<div class="col-sm-4" data-ng-show="access.manageRealm">
|
||||||
</tr>
|
<a class="btn btn-primary" data-ng-show="configButtonVisible" data-ng-click="configureAuthenticator()">Configure chosen authenticator</a>
|
||||||
</tbody>
|
</div>
|
||||||
</table>
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<kc-menu></kc-menu>
|
<kc-menu></kc-menu>
|
||||||
@@ -2,6 +2,7 @@ package org.keycloak.migration.migrators;
|
|||||||
|
|
||||||
import org.keycloak.migration.ModelVersion;
|
import org.keycloak.migration.ModelVersion;
|
||||||
import org.keycloak.models.AuthenticationFlowModel;
|
import org.keycloak.models.AuthenticationFlowModel;
|
||||||
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.ImpersonationConstants;
|
import org.keycloak.models.ImpersonationConstants;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.OTPPolicy;
|
import org.keycloak.models.OTPPolicy;
|
||||||
@@ -38,6 +39,10 @@ public class MigrateTo1_5_0 {
|
|||||||
} else {
|
} else {
|
||||||
realm.setClientAuthenticationFlow(realm.getFlowByAlias(DefaultAuthenticationFlows.CLIENT_AUTHENTICATION_FLOW));
|
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);
|
void setNodeReRegistrationTimeout(int timeout);
|
||||||
|
|
||||||
|
String getClientAuthenticatorType();
|
||||||
|
void setClientAuthenticatorType(String clientAuthenticatorType);
|
||||||
|
|
||||||
boolean validateSecret(String secret);
|
boolean validateSecret(String secret);
|
||||||
String getSecret();
|
String getSecret();
|
||||||
public void setSecret(String secret);
|
public void setSecret(String secret);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public class ClientEntity extends AbstractIdentifiableEntity {
|
|||||||
private String name;
|
private String name;
|
||||||
private String realmId;
|
private String realmId;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
private String clientAuthenticatorType;
|
||||||
private String secret;
|
private String secret;
|
||||||
private String protocol;
|
private String protocol;
|
||||||
private int notBefore;
|
private int notBefore;
|
||||||
@@ -67,6 +68,14 @@ public class ClientEntity extends AbstractIdentifiableEntity {
|
|||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getClientAuthenticatorType() {
|
||||||
|
return clientAuthenticatorType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientAuthenticatorType(String clientAuthenticatorType) {
|
||||||
|
this.clientAuthenticatorType = clientAuthenticatorType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSecret() {
|
public String getSecret() {
|
||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,12 +180,17 @@ public final class KeycloakModelUtils {
|
|||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getDefaultClientAuthenticatorType() {
|
||||||
|
return "client-secret";
|
||||||
|
}
|
||||||
|
|
||||||
public static String generateCodeSecret() {
|
public static String generateCodeSecret() {
|
||||||
return UUID.randomUUID().toString();
|
return UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClientModel createClient(RealmModel realm, String name) {
|
public static ClientModel createClient(RealmModel realm, String name) {
|
||||||
ClientModel app = realm.addClient(name);
|
ClientModel app = realm.addClient(name);
|
||||||
|
app.setClientAuthenticatorType(getDefaultClientAuthenticatorType());
|
||||||
generateSecret(app);
|
generateSecret(app);
|
||||||
app.setFullScopeAllowed(true);
|
app.setFullScopeAllowed(true);
|
||||||
|
|
||||||
|
|||||||
@@ -307,6 +307,7 @@ public class ModelToRepresentation {
|
|||||||
rep.setBaseUrl(clientModel.getBaseUrl());
|
rep.setBaseUrl(clientModel.getBaseUrl());
|
||||||
rep.setNotBefore(clientModel.getNotBefore());
|
rep.setNotBefore(clientModel.getNotBefore());
|
||||||
rep.setNodeReRegistrationTimeout(clientModel.getNodeReRegistrationTimeout());
|
rep.setNodeReRegistrationTimeout(clientModel.getNodeReRegistrationTimeout());
|
||||||
|
rep.setClientAuthenticatorType(clientModel.getClientAuthenticatorType());
|
||||||
|
|
||||||
Set<String> redirectUris = clientModel.getRedirectUris();
|
Set<String> redirectUris = clientModel.getRedirectUris();
|
||||||
if (redirectUris != null) {
|
if (redirectUris != null) {
|
||||||
|
|||||||
@@ -692,6 +692,12 @@ public class RepresentationToModel {
|
|||||||
client.setNotBefore(resourceRep.getNotBefore());
|
client.setNotBefore(resourceRep.getNotBefore());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resourceRep.getClientAuthenticatorType() != null) {
|
||||||
|
client.setClientAuthenticatorType(resourceRep.getClientAuthenticatorType());
|
||||||
|
} else {
|
||||||
|
client.setClientAuthenticatorType(KeycloakModelUtils.getDefaultClientAuthenticatorType());
|
||||||
|
}
|
||||||
|
|
||||||
client.setSecret(resourceRep.getSecret());
|
client.setSecret(resourceRep.getSecret());
|
||||||
if (client.getSecret() == null) {
|
if (client.getSecret() == null) {
|
||||||
KeycloakModelUtils.generateSecret(client);
|
KeycloakModelUtils.generateSecret(client);
|
||||||
@@ -770,6 +776,7 @@ public class RepresentationToModel {
|
|||||||
if (rep.getBaseUrl() != null) resource.setBaseUrl(rep.getBaseUrl());
|
if (rep.getBaseUrl() != null) resource.setBaseUrl(rep.getBaseUrl());
|
||||||
if (rep.isSurrogateAuthRequired() != null) resource.setSurrogateAuthRequired(rep.isSurrogateAuthRequired());
|
if (rep.isSurrogateAuthRequired() != null) resource.setSurrogateAuthRequired(rep.isSurrogateAuthRequired());
|
||||||
if (rep.getNodeReRegistrationTimeout() != null) resource.setNodeReRegistrationTimeout(rep.getNodeReRegistrationTimeout());
|
if (rep.getNodeReRegistrationTimeout() != null) resource.setNodeReRegistrationTimeout(rep.getNodeReRegistrationTimeout());
|
||||||
|
if (rep.getClientAuthenticatorType() != null) resource.setClientAuthenticatorType(rep.getClientAuthenticatorType());
|
||||||
resource.updateClient();
|
resource.updateClient();
|
||||||
|
|
||||||
if (rep.getProtocol() != null) resource.setProtocol(rep.getProtocol());
|
if (rep.getProtocol() != null) resource.setProtocol(rep.getProtocol());
|
||||||
|
|||||||
@@ -145,6 +145,16 @@ public class ClientAdapter implements ClientModel {
|
|||||||
entity.setEnabled(enabled);
|
entity.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClientAuthenticatorType() {
|
||||||
|
return entity.getClientAuthenticatorType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setClientAuthenticatorType(String clientAuthenticatorType) {
|
||||||
|
entity.setClientAuthenticatorType(clientAuthenticatorType);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validateSecret(String secret) {
|
public boolean validateSecret(String secret) {
|
||||||
return secret.equals(entity.getSecret());
|
return secret.equals(entity.getSecret());
|
||||||
|
|||||||
+12
@@ -95,6 +95,18 @@ public class ClientAdapter implements ClientModel {
|
|||||||
updated.setEnabled(enabled);
|
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) {
|
public boolean validateSecret(String secret) {
|
||||||
return secret.equals(getSecret());
|
return secret.equals(getSecret());
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -29,6 +29,7 @@ public class CachedClient implements Serializable {
|
|||||||
private String realm;
|
private String realm;
|
||||||
private Set<String> redirectUris = new HashSet<String>();
|
private Set<String> redirectUris = new HashSet<String>();
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
private String clientAuthenticatorType;
|
||||||
private String secret;
|
private String secret;
|
||||||
private String protocol;
|
private String protocol;
|
||||||
private Map<String, String> attributes = new HashMap<String, String>();
|
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) {
|
public CachedClient(RealmCache cache, RealmProvider delegate, RealmModel realm, ClientModel model) {
|
||||||
id = model.getId();
|
id = model.getId();
|
||||||
|
clientAuthenticatorType = model.getClientAuthenticatorType();
|
||||||
secret = model.getSecret();
|
secret = model.getSecret();
|
||||||
clientId = model.getClientId();
|
clientId = model.getClientId();
|
||||||
name = model.getName();
|
name = model.getName();
|
||||||
@@ -112,6 +114,10 @@ public class CachedClient implements Serializable {
|
|||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getClientAuthenticatorType() {
|
||||||
|
return clientAuthenticatorType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSecret() {
|
public String getSecret() {
|
||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,6 +151,16 @@ public class ClientAdapter implements ClientModel {
|
|||||||
entity.getRedirectUris().remove(redirectUri);
|
entity.getRedirectUris().remove(redirectUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClientAuthenticatorType() {
|
||||||
|
return entity.getClientAuthenticatorType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setClientAuthenticatorType(String clientAuthenticatorType) {
|
||||||
|
entity.setClientAuthenticatorType(clientAuthenticatorType);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSecret() {
|
public String getSecret() {
|
||||||
return entity.getSecret();
|
return entity.getSecret();
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ public class ClientEntity {
|
|||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
@Column(name="SECRET")
|
@Column(name="SECRET")
|
||||||
private String secret;
|
private String secret;
|
||||||
|
@Column(name="CLIENT_AUTHENTICATOR_TYPE")
|
||||||
|
private String clientAuthenticatorType;
|
||||||
@Column(name="NOT_BEFORE")
|
@Column(name="NOT_BEFORE")
|
||||||
private int notBefore;
|
private int notBefore;
|
||||||
@Column(name="PUBLIC_CLIENT")
|
@Column(name="PUBLIC_CLIENT")
|
||||||
@@ -170,6 +172,14 @@ public class ClientEntity {
|
|||||||
this.redirectUris = redirectUris;
|
this.redirectUris = redirectUris;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getClientAuthenticatorType() {
|
||||||
|
return clientAuthenticatorType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientAuthenticatorType(String clientAuthenticatorType) {
|
||||||
|
this.clientAuthenticatorType = clientAuthenticatorType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSecret() {
|
public String getSecret() {
|
||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|||||||
+11
@@ -141,6 +141,17 @@ public class ClientAdapter extends AbstractMongoAdapter<MongoClientEntity> imple
|
|||||||
updateMongoEntity();
|
updateMongoEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClientAuthenticatorType() {
|
||||||
|
return getMongoEntity().getClientAuthenticatorType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setClientAuthenticatorType(String clientAuthenticatorType) {
|
||||||
|
getMongoEntity().setClientAuthenticatorType(clientAuthenticatorType);
|
||||||
|
updateMongoEntity();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validateSecret(String secret) {
|
public boolean validateSecret(String secret) {
|
||||||
return secret.equals(getMongoEntity().getSecret());
|
return secret.equals(getMongoEntity().getSecret());
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.keycloak.authentication;
|
package org.keycloak.authentication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -11,6 +13,7 @@ import org.keycloak.events.Errors;
|
|||||||
import org.keycloak.models.AuthenticationExecutionModel;
|
import org.keycloak.models.AuthenticationExecutionModel;
|
||||||
import org.keycloak.models.AuthenticationFlowModel;
|
import org.keycloak.models.AuthenticationFlowModel;
|
||||||
import org.keycloak.models.ClientModel;
|
import org.keycloak.models.ClientModel;
|
||||||
|
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||||
@@ -18,19 +21,12 @@ import org.keycloak.models.ClientModel;
|
|||||||
public class ClientAuthenticationFlow implements AuthenticationFlow {
|
public class ClientAuthenticationFlow implements AuthenticationFlow {
|
||||||
|
|
||||||
Response alternativeChallenge = null;
|
Response alternativeChallenge = null;
|
||||||
boolean alternativeSuccessful = false;
|
|
||||||
List<AuthenticationExecutionModel> executions;
|
|
||||||
Iterator<AuthenticationExecutionModel> executionIterator;
|
|
||||||
AuthenticationProcessor processor;
|
AuthenticationProcessor processor;
|
||||||
AuthenticationFlowModel flow;
|
AuthenticationFlowModel flow;
|
||||||
|
|
||||||
private List<String> successAuthenticators = new LinkedList<>();
|
|
||||||
|
|
||||||
public ClientAuthenticationFlow(AuthenticationProcessor processor, AuthenticationFlowModel flow) {
|
public ClientAuthenticationFlow(AuthenticationProcessor processor, AuthenticationFlowModel flow) {
|
||||||
this.processor = processor;
|
this.processor = processor;
|
||||||
this.flow = flow;
|
this.flow = flow;
|
||||||
this.executions = processor.getRealm().getAuthenticationExecutions(flow.getId());
|
|
||||||
this.executionIterator = executions.iterator();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -40,131 +36,109 @@ public class ClientAuthenticationFlow implements AuthenticationFlow {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response processFlow() {
|
public Response processFlow() {
|
||||||
while (executionIterator.hasNext()) {
|
List<AuthenticationExecutionModel> executions = findExecutionsToRun();
|
||||||
AuthenticationExecutionModel model = executionIterator.next();
|
|
||||||
|
|
||||||
if (model.isDisabled()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (model.isAlternative() && alternativeSuccessful) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (model.isAuthenticatorFlow()) {
|
|
||||||
AuthenticationFlow authenticationFlow;
|
|
||||||
authenticationFlow = processor.createFlowExecution(model.getFlowId(), model);
|
|
||||||
|
|
||||||
Response flowChallenge = authenticationFlow.processFlow();
|
|
||||||
if (flowChallenge == null) {
|
|
||||||
if (model.isAlternative()) alternativeSuccessful = true;
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
if (model.isAlternative()) {
|
|
||||||
alternativeChallenge = flowChallenge;
|
|
||||||
} else if (model.isRequired()) {
|
|
||||||
return flowChallenge;
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return flowChallenge;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for (AuthenticationExecutionModel model : executions) {
|
||||||
ClientAuthenticatorFactory factory = (ClientAuthenticatorFactory) processor.getSession().getKeycloakSessionFactory().getProviderFactory(ClientAuthenticator.class, model.getAuthenticator());
|
ClientAuthenticatorFactory factory = (ClientAuthenticatorFactory) processor.getSession().getKeycloakSessionFactory().getProviderFactory(ClientAuthenticator.class, model.getAuthenticator());
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
throw new AuthenticationFlowException("Could not find ClientAuthenticatorFactory for: " + model.getAuthenticator(), AuthenticationFlowError.INTERNAL_ERROR);
|
throw new AuthenticationFlowException("Could not find ClientAuthenticatorFactory for: " + model.getAuthenticator(), AuthenticationFlowError.INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
ClientAuthenticator authenticator = factory.create();
|
ClientAuthenticator authenticator = factory.create();
|
||||||
AuthenticationProcessor.logger.debugv("client authenticator: {0}", factory.getId());
|
AuthenticationProcessor.logger.debugv("client authenticator: {0}", factory.getId());
|
||||||
ClientModel authClient = processor.getClient();
|
|
||||||
|
|
||||||
if (authenticator.requiresClient() && authClient == null) {
|
|
||||||
// Continue if it's alternative or optional flow
|
|
||||||
if (model.isAlternative() || model.isOptional()) {
|
|
||||||
AuthenticationProcessor.logger.debugv("client authenticator: {0} requires client, but client not available. Skipping", factory.getId());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alternativeChallenge != null) {
|
|
||||||
return alternativeChallenge;
|
|
||||||
}
|
|
||||||
throw new AuthenticationFlowException("client authenticator: " + factory.getId(), AuthenticationFlowError.CLIENT_NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (authenticator.requiresClient() && authClient != null) {
|
|
||||||
boolean configuredFor = authenticator.configuredFor(processor.getSession(), processor.getRealm(), authClient);
|
|
||||||
if (!configuredFor) {
|
|
||||||
if (model.isRequired()) {
|
|
||||||
throw new AuthenticationFlowException("Client setup required for authenticator " + factory.getId() + " for client " + authClient.getClientId(),
|
|
||||||
AuthenticationFlowError.CLIENT_CREDENTIALS_SETUP_REQUIRED);
|
|
||||||
} else if (model.isOptional()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AuthenticationProcessor.Result context = processor.createClientAuthenticatorContext(model, authenticator, executions);
|
AuthenticationProcessor.Result context = processor.createClientAuthenticatorContext(model, authenticator, executions);
|
||||||
authenticator.authenticateClient(context);
|
authenticator.authenticateClient(context);
|
||||||
Response response = processResult(context);
|
Response response = processResult(context);
|
||||||
if (response != null) return response;
|
if (response != null) return response;
|
||||||
|
|
||||||
authClient = processor.getClient();
|
ClientModel client = processor.getClient();
|
||||||
if (authClient != null && authClient.isPublicClient()) {
|
if (client != null) {
|
||||||
AuthenticationProcessor.logger.debugv("Public client {0} identified by {1} . Skip next client authenticators", authClient.getClientId(), factory.getId());
|
|
||||||
logSuccessEvent();
|
String expectedClientAuthType = client.getClientAuthenticatorType();
|
||||||
return null;
|
|
||||||
|
// Fallback to secret just in case (for backwards compatibility)
|
||||||
|
if (expectedClientAuthType == null) {
|
||||||
|
expectedClientAuthType = KeycloakModelUtils.getDefaultClientAuthenticatorType();
|
||||||
|
AuthenticationProcessor.logger.warnv("Client {0} doesn't have have authentication method configured. Fallback to {1}", client.getClientId(), expectedClientAuthType);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if client authentication matches
|
||||||
|
if (factory.getId().equals(expectedClientAuthType)) {
|
||||||
|
AuthenticationProcessor.logger.debugv("Client {0} authenticated by {1}", client.getClientId(), factory.getId());
|
||||||
|
processor.getEvent().detail(Details.CLIENT_AUTH_METHOD, factory.getId());
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
throw new AuthenticationFlowException("Client " + client.getClientId() + " was authenticated by incorrect method " + factory.getId(),
|
||||||
|
AuthenticationFlowError.INVALID_CLIENT_CREDENTIALS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return finishClientAuthentication();
|
// Check if any alternative challenge was identified
|
||||||
|
if (alternativeChallenge != null) {
|
||||||
|
processor.getEvent().error(Errors.INVALID_CLIENT);
|
||||||
|
return alternativeChallenge;
|
||||||
|
}
|
||||||
|
throw new AuthenticationFlowException("Client was not identified by any client authenticator", AuthenticationFlowError.UNKNOWN_CLIENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected List<AuthenticationExecutionModel> findExecutionsToRun() {
|
||||||
|
List<AuthenticationExecutionModel> executions = processor.getRealm().getAuthenticationExecutions(flow.getId());
|
||||||
|
List<AuthenticationExecutionModel> executionsToRun = new ArrayList<>();
|
||||||
|
|
||||||
public Response processResult(AuthenticationProcessor.Result result) {
|
for (AuthenticationExecutionModel execution : executions) {
|
||||||
|
if (execution.isRequired()) {
|
||||||
|
executionsToRun = Arrays.asList(execution);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (execution.isAlternative()) {
|
||||||
|
executionsToRun.add(execution);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AuthenticationProcessor.logger.isTraceEnabled()) {
|
||||||
|
List<String> exIds = new ArrayList<>();
|
||||||
|
for (AuthenticationExecutionModel execution : executionsToRun) {
|
||||||
|
exIds.add(execution.getId());
|
||||||
|
}
|
||||||
|
AuthenticationProcessor.logger.tracef("Using executions for client authentication: %s", exIds.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return executionsToRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Response processResult(AuthenticationProcessor.Result result) {
|
||||||
AuthenticationExecutionModel execution = result.getExecution();
|
AuthenticationExecutionModel execution = result.getExecution();
|
||||||
FlowStatus status = result.getStatus();
|
FlowStatus status = result.getStatus();
|
||||||
|
|
||||||
|
AuthenticationProcessor.logger.debugv("client authenticator {0}: {1}", status.toString(), execution.getAuthenticator());
|
||||||
|
|
||||||
if (status == FlowStatus.SUCCESS) {
|
if (status == FlowStatus.SUCCESS) {
|
||||||
AuthenticationProcessor.logger.debugv("client authenticator SUCCESS: {0}", execution.getAuthenticator());
|
|
||||||
if (execution.isAlternative()) alternativeSuccessful = true;
|
|
||||||
successAuthenticators.add(execution.getAuthenticator());
|
|
||||||
return null;
|
return null;
|
||||||
} else if (status == FlowStatus.FAILED) {
|
} else if (status == FlowStatus.FAILED) {
|
||||||
AuthenticationProcessor.logger.debugv("client authenticator FAILED: {0}", execution.getAuthenticator());
|
|
||||||
if (result.getChallenge() != null) {
|
if (result.getChallenge() != null) {
|
||||||
return sendChallenge(result, execution);
|
return sendChallenge(result, execution);
|
||||||
|
} else {
|
||||||
|
throw new AuthenticationFlowException(result.getError());
|
||||||
}
|
}
|
||||||
throw new AuthenticationFlowException(result.getError());
|
|
||||||
} else if (status == FlowStatus.FORCE_CHALLENGE) {
|
} else if (status == FlowStatus.FORCE_CHALLENGE) {
|
||||||
return sendChallenge(result, execution);
|
return sendChallenge(result, execution);
|
||||||
} else if (status == FlowStatus.CHALLENGE) {
|
} else if (status == FlowStatus.CHALLENGE) {
|
||||||
AuthenticationProcessor.logger.debugv("client authenticator CHALLENGE: {0}", execution.getAuthenticator());
|
|
||||||
if (execution.isRequired()) {
|
|
||||||
return sendChallenge(result, execution);
|
|
||||||
}
|
|
||||||
ClientModel client = processor.getClient();
|
|
||||||
if (execution.isOptional() && client != null && result.getClientAuthenticator().configuredFor(processor.getSession(), processor.getRealm(), client)) {
|
|
||||||
return sendChallenge(result, execution);
|
|
||||||
}
|
|
||||||
// Make sure the first priority alternative challenge is used
|
// Make sure the first priority alternative challenge is used
|
||||||
if (execution.isAlternative() && alternativeChallenge == null) {
|
if (alternativeChallenge == null) {
|
||||||
alternativeChallenge = result.getChallenge();
|
alternativeChallenge = result.getChallenge();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (status == FlowStatus.FAILURE_CHALLENGE) {
|
} else if (status == FlowStatus.FAILURE_CHALLENGE) {
|
||||||
AuthenticationProcessor.logger.debugv("client authenticator FAILURE_CHALLENGE: {0}", execution.getAuthenticator());
|
|
||||||
return sendChallenge(result, execution);
|
return sendChallenge(result, execution);
|
||||||
} else if (status == FlowStatus.ATTEMPTED) {
|
} else if (status == FlowStatus.ATTEMPTED) {
|
||||||
AuthenticationProcessor.logger.debugv("client authenticator ATTEMPTED: {0}", execution.getAuthenticator());
|
|
||||||
if (execution.getRequirement() == AuthenticationExecutionModel.Requirement.REQUIRED) {
|
|
||||||
throw new AuthenticationFlowException(AuthenticationFlowError.INVALID_CLIENT_CREDENTIALS);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
AuthenticationProcessor.logger.debugv("client authenticator INTERNAL_ERROR: {0}", execution.getAuthenticator());
|
|
||||||
AuthenticationProcessor.logger.error("Unknown result status");
|
AuthenticationProcessor.logger.error("Unknown result status");
|
||||||
throw new AuthenticationFlowException(AuthenticationFlowError.INTERNAL_ERROR);
|
throw new AuthenticationFlowException(AuthenticationFlowError.INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response sendChallenge(AuthenticationProcessor.Result result, AuthenticationExecutionModel execution) {
|
public Response sendChallenge(AuthenticationProcessor.Result result, AuthenticationExecutionModel execution) {
|
||||||
@@ -183,34 +157,4 @@ public class ClientAuthenticationFlow implements AuthenticationFlow {
|
|||||||
|
|
||||||
return result.getChallenge();
|
return result.getChallenge();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response finishClientAuthentication() {
|
|
||||||
if (processor.getClient() == null) {
|
|
||||||
// Check if any alternative challenge was identified
|
|
||||||
if (alternativeChallenge != null) {
|
|
||||||
processor.getEvent().error(Errors.INVALID_CLIENT);
|
|
||||||
return alternativeChallenge;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new AuthenticationFlowException("Client was not identified by any client authenticator", AuthenticationFlowError.UNKNOWN_CLIENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
logSuccessEvent();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void logSuccessEvent() {
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
boolean first = true;
|
|
||||||
for (String authenticator : successAuthenticators) {
|
|
||||||
if (first) {
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
result.append(" ");
|
|
||||||
}
|
|
||||||
result.append(authenticator);
|
|
||||||
}
|
|
||||||
|
|
||||||
processor.getEvent().detail(Details.CLIENT_AUTH_METHOD, result.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -28,21 +28,4 @@ public interface ClientAuthenticator extends Provider {
|
|||||||
*/
|
*/
|
||||||
void authenticateClient(ClientAuthenticationFlowContext context);
|
void authenticateClient(ClientAuthenticationFlowContext context);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Does this authenticator require that the client has already been identified? That ClientAuthenticationFlowContext.getClient() is not null?
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
boolean requiresClient();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is this authenticator configured for this client?
|
|
||||||
*
|
|
||||||
* @param session
|
|
||||||
* @param realm
|
|
||||||
* @param client
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
boolean configuredFor(KeycloakSession session, RealmModel realm, ClientModel client);
|
|
||||||
}
|
}
|
||||||
-11
@@ -36,7 +36,6 @@ public class ClientIdAndSecretAuthenticator extends AbstractClientAuthenticator
|
|||||||
public static final String PROVIDER_ID = "client-secret";
|
public static final String PROVIDER_ID = "client-secret";
|
||||||
|
|
||||||
public static final AuthenticationExecutionModel.Requirement[] REQUIREMENT_CHOICES = {
|
public static final AuthenticationExecutionModel.Requirement[] REQUIREMENT_CHOICES = {
|
||||||
AuthenticationExecutionModel.Requirement.REQUIRED,
|
|
||||||
AuthenticationExecutionModel.Requirement.ALTERNATIVE,
|
AuthenticationExecutionModel.Requirement.ALTERNATIVE,
|
||||||
AuthenticationExecutionModel.Requirement.DISABLED
|
AuthenticationExecutionModel.Requirement.DISABLED
|
||||||
};
|
};
|
||||||
@@ -133,16 +132,6 @@ public class ClientIdAndSecretAuthenticator extends AbstractClientAuthenticator
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean requiresClient() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean configuredFor(KeycloakSession session, RealmModel realm, ClientModel client) {
|
|
||||||
return client.getSecret() != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthenticationExecutionModel.Requirement[] getRequirementChoices() {
|
public AuthenticationExecutionModel.Requirement[] getRequirementChoices() {
|
||||||
return REQUIREMENT_CHOICES;
|
return REQUIREMENT_CHOICES;
|
||||||
|
|||||||
-11
@@ -41,7 +41,6 @@ public class JWTClientAuthenticator extends AbstractClientAuthenticator {
|
|||||||
public static final String CERTIFICATE_ATTR = "jwt.credential.certificate";
|
public static final String CERTIFICATE_ATTR = "jwt.credential.certificate";
|
||||||
|
|
||||||
public static final AuthenticationExecutionModel.Requirement[] REQUIREMENT_CHOICES = {
|
public static final AuthenticationExecutionModel.Requirement[] REQUIREMENT_CHOICES = {
|
||||||
AuthenticationExecutionModel.Requirement.REQUIRED,
|
|
||||||
AuthenticationExecutionModel.Requirement.ALTERNATIVE,
|
AuthenticationExecutionModel.Requirement.ALTERNATIVE,
|
||||||
AuthenticationExecutionModel.Requirement.DISABLED
|
AuthenticationExecutionModel.Requirement.DISABLED
|
||||||
};
|
};
|
||||||
@@ -135,16 +134,6 @@ public class JWTClientAuthenticator extends AbstractClientAuthenticator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean requiresClient() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean configuredFor(KeycloakSession session, RealmModel realm, ClientModel client) {
|
|
||||||
return client.getAttribute(CERTIFICATE_ATTR) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayType() {
|
public String getDisplayType() {
|
||||||
return "Signed Jwt";
|
return "Signed Jwt";
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class AuthorizeClientUtil {
|
|||||||
|
|
||||||
ClientModel client = processor.getClient();
|
ClientModel client = processor.getClient();
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
throw new ErrorResponseException("invalid_client", "Client authentication was successful, but client is null", Response.Status.BAD_REQUEST);
|
throw new ErrorResponseException("invalid_client", "Client authentication ended, but client is null", Response.Status.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ClientAuthResult(client, processor.getClientAuthAttributes());
|
return new ClientAuthResult(client, processor.getClientAuthAttributes());
|
||||||
|
|||||||
@@ -133,6 +133,9 @@ public class AdminAPITest {
|
|||||||
ClientRepresentation newApp = new ClientRepresentation();
|
ClientRepresentation newApp = new ClientRepresentation();
|
||||||
if (appRep.getId() != null) newApp.setId(appRep.getId());
|
if (appRep.getId() != null) newApp.setId(appRep.getId());
|
||||||
newApp.setClientId(appRep.getClientId());
|
newApp.setClientId(appRep.getClientId());
|
||||||
|
if (appRep.getClientAuthenticatorType() != null) {
|
||||||
|
newApp.setClientAuthenticatorType(appRep.getClientAuthenticatorType());
|
||||||
|
}
|
||||||
if (appRep.getSecret() != null) {
|
if (appRep.getSecret() != null) {
|
||||||
newApp.setSecret(appRep.getSecret());
|
newApp.setSecret(appRep.getSecret());
|
||||||
}
|
}
|
||||||
@@ -177,6 +180,7 @@ public class AdminAPITest {
|
|||||||
if (appRep.getAdminUrl() != null) Assert.assertEquals(appRep.getAdminUrl(), storedApp.getAdminUrl());
|
if (appRep.getAdminUrl() != null) Assert.assertEquals(appRep.getAdminUrl(), storedApp.getAdminUrl());
|
||||||
if (appRep.getBaseUrl() != null) Assert.assertEquals(appRep.getBaseUrl(), storedApp.getBaseUrl());
|
if (appRep.getBaseUrl() != null) Assert.assertEquals(appRep.getBaseUrl(), storedApp.getBaseUrl());
|
||||||
if (appRep.isSurrogateAuthRequired() != null) Assert.assertEquals(appRep.isSurrogateAuthRequired(), storedApp.isSurrogateAuthRequired());
|
if (appRep.isSurrogateAuthRequired() != null) Assert.assertEquals(appRep.isSurrogateAuthRequired(), storedApp.isSurrogateAuthRequired());
|
||||||
|
if (appRep.getClientAuthenticatorType() != null) Assert.assertEquals(appRep.getClientAuthenticatorType(), storedApp.getClientAuthenticatorType());
|
||||||
|
|
||||||
if (appRep.getNotBefore() != null) {
|
if (appRep.getNotBefore() != null) {
|
||||||
Assert.assertEquals(appRep.getNotBefore(), storedApp.getNotBefore());
|
Assert.assertEquals(appRep.getNotBefore(), storedApp.getNotBefore());
|
||||||
|
|||||||
+2
-1
@@ -30,6 +30,7 @@ import org.keycloak.models.UserFederationProviderModel;
|
|||||||
import org.keycloak.models.UserModel;
|
import org.keycloak.models.UserModel;
|
||||||
import org.keycloak.protocol.oidc.OIDCLoginProtocolService;
|
import org.keycloak.protocol.oidc.OIDCLoginProtocolService;
|
||||||
import org.keycloak.protocol.oidc.mappers.UserAttributeMapper;
|
import org.keycloak.protocol.oidc.mappers.UserAttributeMapper;
|
||||||
|
import org.keycloak.services.managers.ClientManager;
|
||||||
import org.keycloak.services.managers.RealmManager;
|
import org.keycloak.services.managers.RealmManager;
|
||||||
import org.keycloak.testsuite.OAuthClient;
|
import org.keycloak.testsuite.OAuthClient;
|
||||||
import org.keycloak.testsuite.adapter.AdapterTest;
|
import org.keycloak.testsuite.adapter.AdapterTest;
|
||||||
@@ -78,7 +79,7 @@ public class LDAPMultipleAttributesTest {
|
|||||||
ldapFedProvider.getLdapIdentityStore().updatePassword(bruce, "password");
|
ldapFedProvider.getLdapIdentityStore().updatePassword(bruce, "password");
|
||||||
|
|
||||||
// Create ldap-portal client
|
// Create ldap-portal client
|
||||||
ClientModel ldapClient = appRealm.addClient("ldap-portal");
|
ClientModel ldapClient = new ClientManager(manager).createClient(appRealm, "ldap-portal");
|
||||||
ldapClient.addRedirectUri("/ldap-portal");
|
ldapClient.addRedirectUri("/ldap-portal");
|
||||||
ldapClient.addRedirectUri("/ldap-portal/*");
|
ldapClient.addRedirectUri("/ldap-portal/*");
|
||||||
ldapClient.setManagementUrl("/ldap-portal");
|
ldapClient.setManagementUrl("/ldap-portal");
|
||||||
|
|||||||
+6
-2
@@ -35,6 +35,7 @@ import org.keycloak.events.EventType;
|
|||||||
import org.keycloak.models.AuthenticationExecutionModel;
|
import org.keycloak.models.AuthenticationExecutionModel;
|
||||||
import org.keycloak.models.AuthenticationFlowModel;
|
import org.keycloak.models.AuthenticationFlowModel;
|
||||||
import org.keycloak.models.BrowserSecurityHeaders;
|
import org.keycloak.models.BrowserSecurityHeaders;
|
||||||
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.PasswordPolicy;
|
import org.keycloak.models.PasswordPolicy;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.UserCredentialModel;
|
import org.keycloak.models.UserCredentialModel;
|
||||||
@@ -120,8 +121,6 @@ public class CustomFlowTest {
|
|||||||
execution.setAuthenticatorFlow(false);
|
execution.setAuthenticatorFlow(false);
|
||||||
appRealm.addAuthenticatorExecution(execution);
|
appRealm.addAuthenticatorExecution(execution);
|
||||||
|
|
||||||
new ClientManager().createClient(appRealm, "dummy-client");
|
|
||||||
|
|
||||||
AuthenticationFlowModel clientFlow = new AuthenticationFlowModel();
|
AuthenticationFlowModel clientFlow = new AuthenticationFlowModel();
|
||||||
clientFlow.setAlias("client-dummy");
|
clientFlow.setAlias("client-dummy");
|
||||||
clientFlow.setDescription("dummy pass through flow");
|
clientFlow.setDescription("dummy pass through flow");
|
||||||
@@ -138,6 +137,11 @@ public class CustomFlowTest {
|
|||||||
execution.setPriority(10);
|
execution.setPriority(10);
|
||||||
execution.setAuthenticatorFlow(false);
|
execution.setAuthenticatorFlow(false);
|
||||||
appRealm.addAuthenticatorExecution(execution);
|
appRealm.addAuthenticatorExecution(execution);
|
||||||
|
|
||||||
|
// Set passthrough clientAuthenticator for our clients
|
||||||
|
ClientModel dummyClient = new ClientManager().createClient(appRealm, "dummy-client");
|
||||||
|
dummyClient.setClientAuthenticatorType(PassThroughClientAuthenticator.PROVIDER_ID);
|
||||||
|
appRealm.getClientByClientId("test-app").setClientAuthenticatorType(PassThroughClientAuthenticator.PROVIDER_ID);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
-10
@@ -58,16 +58,6 @@ public class PassThroughClientAuthenticator extends AbstractClientAuthenticator
|
|||||||
context.success();
|
context.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean requiresClient() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean configuredFor(KeycloakSession session, RealmModel realm, ClientModel client) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayType() {
|
public String getDisplayType() {
|
||||||
return "PassThrough Client Validation";
|
return "PassThrough Client Validation";
|
||||||
|
|||||||
+2
-1
@@ -21,6 +21,7 @@ import org.junit.rules.ExternalResource;
|
|||||||
import org.keycloak.adapters.HttpClientBuilder;
|
import org.keycloak.adapters.HttpClientBuilder;
|
||||||
import org.keycloak.models.ClientModel;
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
|
import org.keycloak.services.managers.ClientManager;
|
||||||
import org.keycloak.services.managers.RealmManager;
|
import org.keycloak.services.managers.RealmManager;
|
||||||
import org.keycloak.testsuite.Constants;
|
import org.keycloak.testsuite.Constants;
|
||||||
import org.keycloak.testsuite.rule.KeycloakRule;
|
import org.keycloak.testsuite.rule.KeycloakRule;
|
||||||
@@ -42,7 +43,7 @@ public class JaxrsBasicAuthTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||||
ClientModel app = appRealm.addClient("jaxrs-app");
|
ClientModel app = new ClientManager(manager).createClient(appRealm, "jaxrs-app");
|
||||||
app.setEnabled(true);
|
app.setEnabled(true);
|
||||||
app.setSecret("password");
|
app.setSecret("password");
|
||||||
app.setFullScopeAllowed(true);
|
app.setFullScopeAllowed(true);
|
||||||
|
|||||||
@@ -110,6 +110,10 @@ public class ImportTest extends AbstractModelTest {
|
|||||||
Assert.assertTrue(10 == appRegisteredNodes.get("node1"));
|
Assert.assertTrue(10 == appRegisteredNodes.get("node1"));
|
||||||
Assert.assertTrue(20 == appRegisteredNodes.get("172.10.15.20"));
|
Assert.assertTrue(20 == appRegisteredNodes.get("172.10.15.20"));
|
||||||
|
|
||||||
|
// test clientAuthenticatorType
|
||||||
|
Assert.assertEquals(application.getClientAuthenticatorType(), "client-secret");
|
||||||
|
Assert.assertEquals(otherApp.getClientAuthenticatorType(), "client-jwt");
|
||||||
|
|
||||||
// Test finding applications by ID
|
// Test finding applications by ID
|
||||||
Assert.assertNull(realm.getClientById("982734"));
|
Assert.assertNull(realm.getClientById("982734"));
|
||||||
Assert.assertEquals(application, realm.getClientById(application.getId()));
|
Assert.assertEquals(application, realm.getClientById(application.getId()));
|
||||||
|
|||||||
+3
-1
@@ -58,9 +58,11 @@ public class ClientAuthSignedJWTTest {
|
|||||||
ClientModel app1 = appRealm.addClient("client1");
|
ClientModel app1 = appRealm.addClient("client1");
|
||||||
new ClientManager(manager).enableServiceAccount(app1);
|
new ClientManager(manager).enableServiceAccount(app1);
|
||||||
app1.setAttribute(JWTClientAuthenticator.CERTIFICATE_ATTR, "MIICnTCCAYUCBgFPPLDaTzANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdjbGllbnQxMB4XDTE1MDgxNzE3MjI0N1oXDTI1MDgxNzE3MjQyN1owEjEQMA4GA1UEAwwHY2xpZW50MTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIUjjgv+V3s96O+Za9002Lp/trtGuHBeaeVL9dFKMKzO2MPqdRmHB4PqNlDdd28Rwf5Xn6iWdFpyUKOnI/yXDLhdcuFpR0sMNK/C9Lt+hSpPFLuzDqgtPgDotlMxiHIWDOZ7g9/gPYNXbNvjv8nSiyqoguoCQiiafW90bPHsiVLdP7ZIUwCcfi1qQm7FhxRJ1NiW5dvUkuCnnWEf0XR+Wzc5eC9EgB0taLFiPsSEIlWMm5xlahYyXkPdNOqZjiRnrTWm5Y4uk8ZcsD/KbPTf/7t7cQXipVaswgjdYi1kK2/zRwOhg1QwWFX/qmvdd+fLxV0R6VqRDhn7Qep2cxwMxLsCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAKE6OA46sf20bz8LZPoiNsqRwBUDkaMGXfnob7s/hJZIIwDEx0IAQ3uKsG7q9wb+aA6s+v7S340zb2k3IxuhFaHaZpAd4CyR5cn1FHylbzoZ7rI/3ASqHDqpljdJaFqPH+m7nZWtyDvtZf+gkZ8OjsndwsSBK1d/jMZPp29qYbl1+XfO7RCp/jDqro/R3saYFaIFiEZPeKn1hUJn6BO48vxH1xspSu9FmlvDOEAOz4AuM58z4zRMP49GcFdCWr1wkonJUHaSptJaQwmBwLFUkCbE5I1ixGMb7mjEud6Y5jhfzJiZMo2U8RfcjNbrN0diZl3jB6LQIwESnhYSghaTjNQ==");
|
app1.setAttribute(JWTClientAuthenticator.CERTIFICATE_ATTR, "MIICnTCCAYUCBgFPPLDaTzANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdjbGllbnQxMB4XDTE1MDgxNzE3MjI0N1oXDTI1MDgxNzE3MjQyN1owEjEQMA4GA1UEAwwHY2xpZW50MTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIUjjgv+V3s96O+Za9002Lp/trtGuHBeaeVL9dFKMKzO2MPqdRmHB4PqNlDdd28Rwf5Xn6iWdFpyUKOnI/yXDLhdcuFpR0sMNK/C9Lt+hSpPFLuzDqgtPgDotlMxiHIWDOZ7g9/gPYNXbNvjv8nSiyqoguoCQiiafW90bPHsiVLdP7ZIUwCcfi1qQm7FhxRJ1NiW5dvUkuCnnWEf0XR+Wzc5eC9EgB0taLFiPsSEIlWMm5xlahYyXkPdNOqZjiRnrTWm5Y4uk8ZcsD/KbPTf/7t7cQXipVaswgjdYi1kK2/zRwOhg1QwWFX/qmvdd+fLxV0R6VqRDhn7Qep2cxwMxLsCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAKE6OA46sf20bz8LZPoiNsqRwBUDkaMGXfnob7s/hJZIIwDEx0IAQ3uKsG7q9wb+aA6s+v7S340zb2k3IxuhFaHaZpAd4CyR5cn1FHylbzoZ7rI/3ASqHDqpljdJaFqPH+m7nZWtyDvtZf+gkZ8OjsndwsSBK1d/jMZPp29qYbl1+XfO7RCp/jDqro/R3saYFaIFiEZPeKn1hUJn6BO48vxH1xspSu9FmlvDOEAOz4AuM58z4zRMP49GcFdCWr1wkonJUHaSptJaQwmBwLFUkCbE5I1ixGMb7mjEud6Y5jhfzJiZMo2U8RfcjNbrN0diZl3jB6LQIwESnhYSghaTjNQ==");
|
||||||
|
app1.setClientAuthenticatorType(JWTClientAuthenticator.PROVIDER_ID);
|
||||||
|
|
||||||
ClientModel app2 = appRealm.addClient("client2");
|
ClientModel app2 = appRealm.addClient("client2");
|
||||||
new ClientManager(manager).enableServiceAccount(app2);
|
new ClientManager(manager).enableServiceAccount(app2);
|
||||||
|
app2.setClientAuthenticatorType(JWTClientAuthenticator.PROVIDER_ID);
|
||||||
|
|
||||||
// This one is for keystore-client2.p12 , which doesn't work on Sun JDK
|
// This one is for keystore-client2.p12 , which doesn't work on Sun JDK
|
||||||
// app2.setAttribute(JWTClientAuthenticator.CERTIFICATE_ATTR, "MIICnTCCAYUCBgFPPLGHHjANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdjbGllbnQxMB4XDTE1MDgxNzE3MjMzMVoXDTI1MDgxNzE3MjUxMVowEjEQMA4GA1UEAwwHY2xpZW50MTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIsatXj38fFD9fHslNrsWrubobudXYwwdZpGYqkHIhuDeSojGvhBSLmKIFmtbHMVcLEbS0dIEsSbNVrwjdFfuRuvd9Vu6Ng0JUC8fRhSeQniC3jcBuP8P4WlXK4+ir3Wlya+T6Hum9b68BiH0KyNZtFGJ6zLHuCcq9Bl0JifvibnUkDeTZPwgJNA9+GxS/x8fAkApcAbJrgBZvr57PwhbgHoZdB8aAY5f5ogbGzKDtSUMvFh+Jah39gWtn7p3VOuuMXA8SugogoH8C5m2itrPBL1UPhAcKUeWiqx4SmZe/lZo7x2WbSecNiFaiqBhIW+QbqCYW6I4u0YvuLuEe3+TC8CAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAZzW5DZviCxUQdV5Ab07PZkUfvImHZ73oWWHZqzUQtZtbVdzfp3cnbb2wyXtlOvingO3hgpoTxV8vbKgLbIQfvkGGHBG1F5e0QVdtikfdcwWb7cy4/9F80OD7cgG0ZAzFbQ8ZY7iS3PToBp3+4tbIK2NK0ntt/MYgJnPbHeG4V4qfgUbFm1YgEK7WpbSVU8jGuJ5DWE+mlYgECZKZ5TSlaVGs2XOm6WXrJScucNekwcBWWiHyRsFHZEDzWmzt8TLTLnnb0vVjhx3qCYxah3RbyyMZm6WLZlLAaGEcwNDO8jaA3hAjrxoOA1xEaolQfGVsb/ElelHcR1Zfe0u4Ekd4tw==");
|
// app2.setAttribute(JWTClientAuthenticator.CERTIFICATE_ATTR, "MIICnTCCAYUCBgFPPLGHHjANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdjbGllbnQxMB4XDTE1MDgxNzE3MjMzMVoXDTI1MDgxNzE3MjUxMVowEjEQMA4GA1UEAwwHY2xpZW50MTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIsatXj38fFD9fHslNrsWrubobudXYwwdZpGYqkHIhuDeSojGvhBSLmKIFmtbHMVcLEbS0dIEsSbNVrwjdFfuRuvd9Vu6Ng0JUC8fRhSeQniC3jcBuP8P4WlXK4+ir3Wlya+T6Hum9b68BiH0KyNZtFGJ6zLHuCcq9Bl0JifvibnUkDeTZPwgJNA9+GxS/x8fAkApcAbJrgBZvr57PwhbgHoZdB8aAY5f5ogbGzKDtSUMvFh+Jah39gWtn7p3VOuuMXA8SugogoH8C5m2itrPBL1UPhAcKUeWiqx4SmZe/lZo7x2WbSecNiFaiqBhIW+QbqCYW6I4u0YvuLuEe3+TC8CAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAZzW5DZviCxUQdV5Ab07PZkUfvImHZ73oWWHZqzUQtZtbVdzfp3cnbb2wyXtlOvingO3hgpoTxV8vbKgLbIQfvkGGHBG1F5e0QVdtikfdcwWb7cy4/9F80OD7cgG0ZAzFbQ8ZY7iS3PToBp3+4tbIK2NK0ntt/MYgJnPbHeG4V4qfgUbFm1YgEK7WpbSVU8jGuJ5DWE+mlYgECZKZ5TSlaVGs2XOm6WXrJScucNekwcBWWiHyRsFHZEDzWmzt8TLTLnnb0vVjhx3qCYxah3RbyyMZm6WLZlLAaGEcwNDO8jaA3hAjrxoOA1xEaolQfGVsb/ElelHcR1Zfe0u4Ekd4tw==");
|
||||||
@@ -176,7 +178,7 @@ public class ClientAuthSignedJWTTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDirectGrantRequest() throws Exception {
|
public void testDirectGrantRequestSuccess() throws Exception {
|
||||||
oauth.clientId("client2");
|
oauth.clientId("client2");
|
||||||
OAuthClient.AccessTokenResponse response = doGrantAccessTokenRequest("test-user@localhost", "password", getClient2SignedJWT());
|
OAuthClient.AccessTokenResponse response = doGrantAccessTokenRequest("test-user@localhost", "password", getClient2SignedJWT());
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -29,6 +29,7 @@ import org.keycloak.OAuth2Constants;
|
|||||||
import org.keycloak.models.ClientModel;
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.Constants;
|
import org.keycloak.models.Constants;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
|
import org.keycloak.services.managers.ClientManager;
|
||||||
import org.keycloak.services.managers.RealmManager;
|
import org.keycloak.services.managers.RealmManager;
|
||||||
import org.keycloak.testsuite.OAuthClient;
|
import org.keycloak.testsuite.OAuthClient;
|
||||||
import org.keycloak.testsuite.pages.ErrorPage;
|
import org.keycloak.testsuite.pages.ErrorPage;
|
||||||
@@ -49,18 +50,18 @@ public class OAuthRedirectUriTest {
|
|||||||
public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakRule.KeycloakSetup() {
|
public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakRule.KeycloakSetup() {
|
||||||
@Override
|
@Override
|
||||||
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||||
ClientModel installedApp = appRealm.addClient("test-installed");
|
ClientModel installedApp = new ClientManager(manager).createClient(appRealm, "test-installed");
|
||||||
installedApp.setEnabled(true);
|
installedApp.setEnabled(true);
|
||||||
installedApp.addRedirectUri(Constants.INSTALLED_APP_URN);
|
installedApp.addRedirectUri(Constants.INSTALLED_APP_URN);
|
||||||
installedApp.addRedirectUri(Constants.INSTALLED_APP_URL);
|
installedApp.addRedirectUri(Constants.INSTALLED_APP_URL);
|
||||||
installedApp.setSecret("password");
|
installedApp.setSecret("password");
|
||||||
|
|
||||||
ClientModel installedApp2 = appRealm.addClient("test-installed2");
|
ClientModel installedApp2 = new ClientManager(manager).createClient(appRealm, "test-installed2");
|
||||||
installedApp2.setEnabled(true);
|
installedApp2.setEnabled(true);
|
||||||
installedApp2.addRedirectUri(Constants.INSTALLED_APP_URL + "/myapp");
|
installedApp2.addRedirectUri(Constants.INSTALLED_APP_URL + "/myapp");
|
||||||
installedApp2.setSecret("password");
|
installedApp2.setSecret("password");
|
||||||
|
|
||||||
ClientModel installedApp3 = appRealm.addClient("test-wildcard");
|
ClientModel installedApp3 = new ClientManager(manager).createClient(appRealm, "test-wildcard");
|
||||||
installedApp3.setEnabled(true);
|
installedApp3.setEnabled(true);
|
||||||
installedApp3.addRedirectUri("http://example.com/foo/*");
|
installedApp3.addRedirectUri("http://example.com/foo/*");
|
||||||
installedApp3.addRedirectUri("http://localhost:8081/foo/*");
|
installedApp3.addRedirectUri("http://localhost:8081/foo/*");
|
||||||
|
|||||||
+2
-1
@@ -17,6 +17,7 @@ import org.keycloak.models.UserCredentialModel;
|
|||||||
import org.keycloak.models.UserModel;
|
import org.keycloak.models.UserModel;
|
||||||
import org.keycloak.representations.AccessToken;
|
import org.keycloak.representations.AccessToken;
|
||||||
import org.keycloak.representations.RefreshToken;
|
import org.keycloak.representations.RefreshToken;
|
||||||
|
import org.keycloak.services.managers.ClientManager;
|
||||||
import org.keycloak.services.managers.RealmManager;
|
import org.keycloak.services.managers.RealmManager;
|
||||||
import org.keycloak.testsuite.AssertEvents;
|
import org.keycloak.testsuite.AssertEvents;
|
||||||
import org.keycloak.testsuite.OAuthClient;
|
import org.keycloak.testsuite.OAuthClient;
|
||||||
@@ -36,7 +37,7 @@ public class ResourceOwnerPasswordCredentialsGrantTest {
|
|||||||
public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakRule.KeycloakSetup() {
|
public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakRule.KeycloakSetup() {
|
||||||
@Override
|
@Override
|
||||||
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||||
ClientModel app = appRealm.addClient("resource-owner");
|
ClientModel app = new ClientManager(manager).createClient(appRealm, "resource-owner");
|
||||||
app.setSecret("secret");
|
app.setSecret("secret");
|
||||||
|
|
||||||
UserModel user = session.users().addUser(appRealm, "direct-login");
|
UserModel user = session.users().addUser(appRealm, "direct-login");
|
||||||
|
|||||||
+2
-2
@@ -34,11 +34,11 @@ public class ServiceAccountTest {
|
|||||||
public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakRule.KeycloakSetup() {
|
public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakRule.KeycloakSetup() {
|
||||||
@Override
|
@Override
|
||||||
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||||
ClientModel app = appRealm.addClient("service-account-cl");
|
ClientModel app = new ClientManager(manager).createClient(appRealm, "service-account-cl");
|
||||||
app.setSecret("secret1");
|
app.setSecret("secret1");
|
||||||
new ClientManager(manager).enableServiceAccount(app);
|
new ClientManager(manager).enableServiceAccount(app);
|
||||||
|
|
||||||
ClientModel disabledApp = appRealm.addClient("service-account-disabled");
|
ClientModel disabledApp = new ClientManager(manager).createClient(appRealm, "service-account-disabled");
|
||||||
disabledApp.setSecret("secret1");
|
disabledApp.setSecret("secret1");
|
||||||
|
|
||||||
UserModel serviceAccountUser = session.users().getUserByUsername(ServiceAccountConstants.SERVICE_ACCOUNT_USER_PREFIX + "service-account-cl", appRealm);
|
UserModel serviceAccountUser = session.users().getUserByUsername(ServiceAccountConstants.SERVICE_ACCOUNT_USER_PREFIX + "service-account-cl", appRealm);
|
||||||
|
|||||||
@@ -123,6 +123,7 @@
|
|||||||
"enabled": true,
|
"enabled": true,
|
||||||
"adminUrl": "http://localhost:8081/secure-portal",
|
"adminUrl": "http://localhost:8081/secure-portal",
|
||||||
"baseUrl": "http://localhost:8081/secure-portal",
|
"baseUrl": "http://localhost:8081/secure-portal",
|
||||||
|
"clientAuthenticatorType": "client-jwt",
|
||||||
"redirectUris": [
|
"redirectUris": [
|
||||||
"http://localhost:8081/secure-portal/*"
|
"http://localhost:8081/secure-portal/*"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -164,6 +164,7 @@
|
|||||||
"name": "Other Application",
|
"name": "Other Application",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"serviceAccountsEnabled": true,
|
"serviceAccountsEnabled": true,
|
||||||
|
"clientAuthenticatorType": "client-jwt",
|
||||||
"protocolMappers" : [
|
"protocolMappers" : [
|
||||||
{
|
{
|
||||||
"name" : "gss delegation credential",
|
"name" : "gss delegation credential",
|
||||||
|
|||||||
@@ -123,6 +123,7 @@
|
|||||||
"enabled": true,
|
"enabled": true,
|
||||||
"adminUrl": "http://localhost:8082/secure-portal",
|
"adminUrl": "http://localhost:8082/secure-portal",
|
||||||
"baseUrl": "http://localhost:8082/secure-portal",
|
"baseUrl": "http://localhost:8082/secure-portal",
|
||||||
|
"clientAuthenticatorType": "client-jwt",
|
||||||
"redirectUris": [
|
"redirectUris": [
|
||||||
"http://localhost:8082/secure-portal/*"
|
"http://localhost:8082/secure-portal/*"
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in new issue
Block a user