Skip to content

Commit

Permalink
KEYCLOAK-1801 Additional fix and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mposolda committed Sep 4, 2015
1 parent f23f1cc commit 35e63a9
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 93 deletions.
Expand Up @@ -638,6 +638,9 @@ module.config([ '$routeProvider', function($routeProvider) {
}, },
clientAuthenticatorProviders : function(ClientAuthenticatorProvidersLoader) { clientAuthenticatorProviders : function(ClientAuthenticatorProvidersLoader) {
return ClientAuthenticatorProvidersLoader(); return ClientAuthenticatorProvidersLoader();
},
clientConfigProperties: function(PerClientAuthenticationConfigDescriptionLoader) {
return PerClientAuthenticationConfigDescriptionLoader();
} }
}, },
controller : 'ClientCredentialsCtrl' controller : 'ClientCredentialsCtrl'
Expand Down
Expand Up @@ -30,57 +30,44 @@ module.controller('ClientRoleListCtrl', function($scope, $location, realm, clien
}); });
}); });


module.controller('ClientCredentialsCtrl', function($scope, $location, realm, client, clientAuthenticatorProviders, Client) { module.controller('ClientCredentialsCtrl', function($scope, $location, realm, client, clientAuthenticatorProviders, clientConfigProperties, Client) {
$scope.realm = realm; $scope.realm = realm;
$scope.client = angular.copy(client); $scope.client = angular.copy(client);
$scope.clientAuthenticatorProviders = clientAuthenticatorProviders; $scope.clientAuthenticatorProviders = clientAuthenticatorProviders;


var updateConfigButtonVisibility = function() { var updateCurrentPartial = function(val) {
for (var i=0 ; i<clientAuthenticatorProviders.length ; i++) { $scope.clientAuthenticatorConfigPartial;
var authenticator = clientAuthenticatorProviders[i]; switch(val) {
if ($scope.client.clientAuthenticatorType === authenticator.id) { case 'client-secret':
$scope.configButtonVisible = authenticator.configurablePerClient; $scope.clientAuthenticatorConfigPartial = 'client-credentials-secret.html';
} break;
case 'client-jwt':
$scope.clientAuthenticatorConfigPartial = 'client-credentials-jwt.html';
break;
default:
$scope.currentAuthenticatorConfigProperties = clientConfigProperties[val];
$scope.clientAuthenticatorConfigPartial = 'client-credentials-generic.html';
break;
} }
}; };
updateConfigButtonVisibility();


$scope.$watch('client', function() { updateCurrentPartial(client.clientAuthenticatorType);
if (!angular.equals($scope.client, client)) {


console.log("Update client credentials!"); $scope.$watch('client.clientAuthenticatorType', function() {
if (!angular.equals($scope.client.clientAuthenticatorType, client.clientAuthenticatorType)) {


Client.update({ Client.update({
realm : realm.realm, realm : realm.realm,
client : client.id client : client.id
}, $scope.client, function() { }, $scope.client, function() {
$scope.changed = false; $scope.changed = false;
client = angular.copy($scope.client); client = angular.copy($scope.client);
updateConfigButtonVisibility(); updateCurrentPartial(client.clientAuthenticatorType)
}); });


} }
}, true); }, true);


$scope.$watch('client.clientAuthenticatorType', function(val) {
$scope.clientAuthenticatorConfigPartial;
switch(val) {
case 'client-secret':
$scope.clientAuthenticatorConfigPartial = 'client-credentials-secret.html';
break;
case 'client-jwt':
$scope.clientAuthenticatorConfigPartial = 'client-credentials-jwt.html';
break;
default:
$scope.clientAuthenticatorConfigPartial = 'client-credentials-generic.html';
break;
}
});

$scope.configureAuthenticator = function() {
$location.url("/realms/" + realm.realm + "/clients/" + client.id + "/credentials/" + client.clientAuthenticatorType);
}

}); });


module.controller('ClientSecretCtrl', function($scope, $location, ClientSecret, Notifications) { module.controller('ClientSecretCtrl', function($scope, $location, ClientSecret, Notifications) {
Expand Down Expand Up @@ -134,35 +121,33 @@ module.controller('ClientSignedJWTCtrl', function($scope, $location, ClientCerti
}; };
}); });


module.controller('ClientGenericCredentialsCtrl', function($scope, $location, realm, client, clientConfigProperties, Client, Notifications) { module.controller('ClientGenericCredentialsCtrl', function($scope, $location, Client, Notifications) {


console.log('ClientGenericCredentialsCtrl invoked'); console.log('ClientGenericCredentialsCtrl invoked');


$scope.realm = realm; $scope.clientCopy = angular.copy($scope.client);
$scope.client = angular.copy(client);
$scope.clientConfigProperties = clientConfigProperties;
$scope.changed = false; $scope.changed = false;


$scope.$watch('client', function() { $scope.$watch('client', function() {
if (!angular.equals($scope.client, client)) { if (!angular.equals($scope.client, $scope.clientCopy)) {
$scope.changed = true; $scope.changed = true;
} }
}, true); }, true);


$scope.save = function() { $scope.save = function() {


Client.update({ Client.update({
realm : realm.realm, realm : $scope.realm.realm,
client : client.id client : $scope.client.id
}, $scope.client, function() { }, $scope.client, function() {
$scope.changed = false; $scope.changed = false;
client = angular.copy($scope.client); $scope.clientCopy = 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.");
}); });
}; };


$scope.reset = function() { $scope.reset = function() {
$scope.client = angular.copy(client); $scope.client = angular.copy($scope.clientCopy);
$scope.changed = false; $scope.changed = false;
}; };
}); });
Expand Down
Expand Up @@ -419,10 +419,9 @@ module.factory('AuthenticationConfigDescriptionLoader', function(Loader, Authent
}); });


module.factory('PerClientAuthenticationConfigDescriptionLoader', function(Loader, PerClientAuthenticationConfigDescription, $route, $q) { module.factory('PerClientAuthenticationConfigDescriptionLoader', function(Loader, PerClientAuthenticationConfigDescription, $route, $q) {
return Loader.query(PerClientAuthenticationConfigDescription, function () { return Loader.get(PerClientAuthenticationConfigDescription, function () {
return { return {
realm: $route.current.params.realm, realm: $route.current.params.realm
provider: $route.current.params.provider
} }
}); });
}); });
Expand Down
Expand Up @@ -1258,9 +1258,8 @@ module.factory('AuthenticationConfigDescription', function($resource) {
}); });
}); });
module.factory('PerClientAuthenticationConfigDescription', function($resource) { module.factory('PerClientAuthenticationConfigDescription', function($resource) {
return $resource(authUrl + '/admin/realms/:realm/authentication/per-client-config-description/:provider', { return $resource(authUrl + '/admin/realms/:realm/authentication/per-client-config-description', {
realm : '@realm', realm : '@realm'
provider: '@provider'
}); });
}); });


Expand Down
@@ -1,12 +1,14 @@
<form class="form-horizontal" name="credentialForm" novalidate kc-read-only="!access.manageClients" data-ng-show="client.attributes.length > 0"> <div>
<fieldset> <form class="form-horizontal" name="credentialForm" novalidate kc-read-only="!access.manageClients" data-ng-show="currentAuthenticatorConfigProperties.length > 0" data-ng-controller="ClientGenericCredentialsCtrl">
<kc-provider-config realm="realm" config="client.attributes" properties="clientConfigProperties"></kc-provider-config> <fieldset>
</fieldset> <kc-provider-config realm="realm" config="client.attributes" properties="currentAuthenticatorConfigProperties"></kc-provider-config>
</fieldset>


<div class="form-group"> <div class="form-group">
<div class="col-md-10 col-md-offset-2" data-ng-show="access.manageClients"> <div class="col-md-10 col-md-offset-2" data-ng-show="access.manageClients">
<button kc-save data-ng-disabled="!changed">Save</button> <button kc-save data-ng-disabled="!changed">Save</button>
<button kc-reset data-ng-disabled="!changed">Cancel</button> <button kc-reset data-ng-disabled="!changed">Cancel</button>
</div>
</div> </div>
</div> </form>
</form> </div>
Expand Up @@ -25,13 +25,6 @@ public interface ClientAuthenticatorFactory extends ProviderFactory<ClientAuthen
@Override @Override
boolean isConfigurable(); boolean isConfigurable();


/**
* Is this authenticator configurable per client? The configuration will be in "Clients" / "Credentials" tab in admin console
*
* @return
*/
boolean isConfigurablePerClient();

/** /**
* List of config properties for this client implementation. Those will be shown in admin console in clients credentials tab and can be configured per client. * List of config properties for this client implementation. Those will be shown in admin console in clients credentials tab and can be configured per client.
* Applicable only if "isConfigurablePerClient" is true * Applicable only if "isConfigurablePerClient" is true
Expand Down
Expand Up @@ -127,11 +127,6 @@ public boolean isConfigurable() {
return false; return false;
} }


@Override
public boolean isConfigurablePerClient() {
return true;
}

@Override @Override
public AuthenticationExecutionModel.Requirement[] getRequirementChoices() { public AuthenticationExecutionModel.Requirement[] getRequirementChoices() {
return REQUIREMENT_CHOICES; return REQUIREMENT_CHOICES;
Expand Down
Expand Up @@ -144,11 +144,6 @@ public boolean isConfigurable() {
return false; return false;
} }


@Override
public boolean isConfigurablePerClient() {
return true;
}

@Override @Override
public AuthenticationExecutionModel.Requirement[] getRequirementChoices() { public AuthenticationExecutionModel.Requirement[] getRequirementChoices() {
return REQUIREMENT_CHOICES; return REQUIREMENT_CHOICES;
Expand Down
Expand Up @@ -211,11 +211,6 @@ public List<Map<String, Object>> buildProviderMetadata(List<ProviderFactory> fac
data.put("description", configured.getHelpText()); data.put("description", configured.getHelpText());
data.put("displayName", configured.getDisplayType()); data.put("displayName", configured.getDisplayType());


if (configured instanceof ClientAuthenticatorFactory) {
ClientAuthenticatorFactory configuredClient = (ClientAuthenticatorFactory) configured;
data.put("configurablePerClient", configuredClient.isConfigurablePerClient());
}

providers.add(data); providers.add(data);
} }
return providers; return providers;
Expand Down Expand Up @@ -894,21 +889,30 @@ private ConfigPropertyRepresentation getConfigPropertyRep(ProviderConfigProperty
} }




@Path("per-client-config-description/{providerId}") @Path("per-client-config-description")
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@NoCache @NoCache
public List<ConfigPropertyRepresentation> getPerClientConfigDescription(@PathParam("providerId") String providerId) { public Map<String, List<ConfigPropertyRepresentation>> getPerClientConfigDescription() {
this.auth.requireView(); this.auth.requireView();
ConfigurableAuthenticatorFactory factory = CredentialHelper.getConfigurableAuthenticatorFactory(session, providerId); List<ProviderFactory> factories = session.getKeycloakSessionFactory().getProviderFactories(ClientAuthenticator.class);
ClientAuthenticatorFactory clientAuthFactory = (ClientAuthenticatorFactory) factory;
List<ProviderConfigProperty> perClientConfigProps = clientAuthFactory.getConfigPropertiesPerClient(); Map<String, List<ConfigPropertyRepresentation>> toReturn = new HashMap<>();
List<ConfigPropertyRepresentation> result = new LinkedList<>(); for (ProviderFactory clientAuthenticatorFactory : factories) {
for (ProviderConfigProperty prop : perClientConfigProps) { String providerId = clientAuthenticatorFactory.getId();
ConfigPropertyRepresentation propRep = getConfigPropertyRep(prop); ConfigurableAuthenticatorFactory factory = CredentialHelper.getConfigurableAuthenticatorFactory(session, providerId);
result.add(propRep); ClientAuthenticatorFactory clientAuthFactory = (ClientAuthenticatorFactory) factory;
List<ProviderConfigProperty> perClientConfigProps = clientAuthFactory.getConfigPropertiesPerClient();
List<ConfigPropertyRepresentation> result = new LinkedList<>();
for (ProviderConfigProperty prop : perClientConfigProps) {
ConfigPropertyRepresentation propRep = getConfigPropertyRep(prop);
result.add(propRep);
}

toReturn.put(providerId, result);
} }
return result;
return toReturn;
} }


@Path("config") @Path("config")
Expand Down
Expand Up @@ -68,11 +68,6 @@ public boolean isConfigurable() {
return false; return false;
} }


@Override
public boolean isConfigurablePerClient() {
return true;
}

@Override @Override
public AuthenticationExecutionModel.Requirement[] getRequirementChoices() { public AuthenticationExecutionModel.Requirement[] getRequirementChoices() {
return REQUIREMENT_CHOICES; return REQUIREMENT_CHOICES;
Expand Down

0 comments on commit 35e63a9

Please sign in to comment.