KEYCLOAK-251 Added installation page for oauth clients to admin console
This commit is contained in:
parent
fcac30d3a2
commit
f14931d234
12 changed files with 130 additions and 1 deletions
|
@ -396,7 +396,21 @@ module.config([ '$routeProvider', function($routeProvider) {
|
|||
},
|
||||
controller : 'OAuthClientScopeMappingCtrl'
|
||||
})
|
||||
|
||||
.when('/realms/:realm/oauth-clients/:oauth/installation', {
|
||||
templateUrl : 'partials/oauth-client-installation.html',
|
||||
resolve : {
|
||||
realm : function(RealmLoader) {
|
||||
return RealmLoader();
|
||||
},
|
||||
oauth : function(OAuthClientLoader) {
|
||||
return OAuthClientLoader();
|
||||
},
|
||||
installation : function(OAuthClientInstallationLoader) {
|
||||
return OAuthClientInstallationLoader();
|
||||
}
|
||||
},
|
||||
controller : 'OAuthClientInstallationCtrl'
|
||||
})
|
||||
.when('/create/oauth-client/:realm', {
|
||||
templateUrl : 'partials/oauth-client-detail.html',
|
||||
resolve : {
|
||||
|
|
|
@ -294,3 +294,11 @@ module.controller('OAuthClientScopeMappingCtrl', function($scope, $http, realm,
|
|||
|
||||
|
||||
});
|
||||
|
||||
|
||||
module.controller('OAuthClientInstallationCtrl', function($scope, realm, installation, oauth, OAuthClientInstallation, $routeParams) {
|
||||
$scope.realm = realm;
|
||||
$scope.oauth = oauth;
|
||||
$scope.installation = installation;
|
||||
$scope.download = OAuthClientInstallation.url({ realm: $routeParams.realm, oauth: $routeParams.oauth });
|
||||
});
|
||||
|
|
|
@ -152,3 +152,12 @@ module.factory('OAuthClientListLoader', function(Loader, OAuthClient, $route, $q
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
module.factory('OAuthClientInstallationLoader', function(Loader, OAuthClientInstallation, $route, $q) {
|
||||
return Loader.get(OAuthClientInstallation, function() {
|
||||
return {
|
||||
realm : $route.current.params.realm,
|
||||
oauth : $route.current.params.oauth
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -291,6 +291,22 @@ module.factory('OAuthClientApplicationScopeMapping', function($resource) {
|
|||
});
|
||||
});
|
||||
|
||||
module.factory('OAuthClientInstallation', function($resource) {
|
||||
var url = '/auth-server/rest/saas/admin/realms/:realm/oauth-clients/:oauth/installation';
|
||||
var resource = $resource('/auth-server/rest/saas/admin/realms/:realm/oauth-clients/:oauth/installation', {
|
||||
realm : '@realm',
|
||||
oauth : '@oauth'
|
||||
}, {
|
||||
update : {
|
||||
method : 'PUT'
|
||||
}
|
||||
});
|
||||
resource.url = function(parameters) {
|
||||
return url.replace(':realm', parameters.realm).replace(':oauth', parameters.oauth);
|
||||
}
|
||||
return resource;
|
||||
});
|
||||
|
||||
|
||||
module.factory('Current', function(Realm, $route) {
|
||||
var current = {};
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<li><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}">Settings</a></li>
|
||||
<li class="active"><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}/credentials">Credentials</a></li>
|
||||
<li><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}/scope-mappings">Scope</a></li>
|
||||
<li><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}/installation">Installation</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="content">
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<li class="active"><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}">Settings</a></li>
|
||||
<li><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}/credentials">Credentials</a></li>
|
||||
<li><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}/scope-mappings">Scope</a></li>
|
||||
<li><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}/installation">Installation</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="top-nav" data-ng-show="create">
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<div id="wrapper" class="container">
|
||||
<div class="row">
|
||||
<div class="bs-sidebar col-md-3 clearfix" data-ng-include data-src="'partials/realm-menu.html'"></div>
|
||||
<div id="content-area" class="col-md-9" role="main">
|
||||
<div class="top-nav" data-ng-show="!create">
|
||||
<ul class="rcue-tabs">
|
||||
<li><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}">Settings</a></li>
|
||||
<li><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}/credentials">Credentials</a></li>
|
||||
<li><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}/scope-mappings">Scope</a></li>
|
||||
<li class="active"><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}/installation">Installation</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="top-nav" data-ng-show="create">
|
||||
<ul class="rcue-tabs">
|
||||
<li></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="content">
|
||||
<a class="button primary" href="{{download}}" download="keycloak.json" type="submit">Download</a></br>
|
||||
<textarea style="width: 100%;" rows="20" onclick="this.select()">{{installation | json}}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div id="container-right-bg"></div>
|
||||
</div>
|
||||
</div>
|
|
@ -7,6 +7,7 @@
|
|||
<li><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}">Settings</a></li>
|
||||
<li><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}/credentials">Credentials</a></li>
|
||||
<li class="active"><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}/scope-mappings">Scope</a></li>
|
||||
<li><a href="#/realms/{{realm.id}}/oauth-clients/{{oauth.id}}/installation">Installation</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="content">
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
package org.keycloak.services.managers;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.representations.adapters.config.BaseAdapterConfig;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
import org.keycloak.representations.idm.OAuthClientRepresentation;
|
||||
import org.keycloak.services.resources.flows.Urls;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -76,4 +82,26 @@ public class OAuthClientManager {
|
|||
}
|
||||
return rep;
|
||||
}
|
||||
|
||||
public BaseAdapterConfig toInstallationRepresentation(RealmModel realmModel, OAuthClientModel model, URI baseUri) {
|
||||
BaseAdapterConfig rep = new BaseAdapterConfig();
|
||||
rep.setRealm(realmModel.getId());
|
||||
rep.setRealmKey(realmModel.getPublicKeyPem());
|
||||
rep.setSslNotRequired(realmModel.isSslNotRequired());
|
||||
|
||||
rep.setAuthUrl(Urls.realmLoginPage(baseUri, realmModel.getId()).toString());
|
||||
rep.setCodeUrl(Urls.realmCode(baseUri, realmModel.getId()).toString());
|
||||
rep.setUseResourceRoleMappings(false);
|
||||
|
||||
rep.setResource(model.getOAuthAgent().getLoginName());
|
||||
|
||||
Map<String, String> creds = new HashMap<String, String>();
|
||||
creds.put(CredentialRepresentation.PASSWORD, "INSERT CLIENT PASSWORD");
|
||||
if (model.getOAuthAgent().isTotp()) {
|
||||
creds.put(CredentialRepresentation.TOTP, "INSERT CLIENT TOTP");
|
||||
}
|
||||
rep.setCredentials(creds);
|
||||
|
||||
return rep;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,13 @@ import org.keycloak.models.KeycloakSession;
|
|||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
import org.keycloak.representations.adapters.config.BaseAdapterConfig;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
import org.keycloak.representations.idm.OAuthClientRepresentation;
|
||||
import org.keycloak.services.managers.ApplicationManager;
|
||||
import org.keycloak.services.managers.OAuthClientManager;
|
||||
import org.keycloak.services.managers.RealmManager;
|
||||
import org.keycloak.util.JsonSerialization;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
|
@ -17,7 +20,10 @@ import javax.ws.rs.GET;
|
|||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -29,6 +35,8 @@ public class OAuthClientResource {
|
|||
protected RealmModel realm;
|
||||
protected OAuthClientModel oauthClient;
|
||||
protected KeycloakSession session;
|
||||
@Context
|
||||
protected UriInfo uriInfo;
|
||||
|
||||
public OAuthClientResource(RealmModel realm, OAuthClientModel oauthClient, KeycloakSession session) {
|
||||
this.realm = realm;
|
||||
|
@ -51,6 +59,18 @@ public class OAuthClientResource {
|
|||
return OAuthClientManager.toRepresentation(oauthClient);
|
||||
}
|
||||
|
||||
@GET
|
||||
@NoCache
|
||||
@Path("installation")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String getInstallation() throws IOException {
|
||||
OAuthClientManager manager = new OAuthClientManager(realm);
|
||||
BaseAdapterConfig rep = manager.toInstallationRepresentation(realm, oauthClient, uriInfo.getBaseUri());
|
||||
|
||||
// TODO Temporary solution to pretty-print
|
||||
return JsonSerialization.mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rep);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@NoCache
|
||||
public void deleteOAuthClient() {
|
||||
|
|
|
@ -15,6 +15,7 @@ import javax.ws.rs.POST;
|
|||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.container.ResourceContext;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -32,6 +33,9 @@ public class OAuthClientsResource {
|
|||
|
||||
protected KeycloakSession session;
|
||||
|
||||
@Context
|
||||
protected ResourceContext resourceContext;
|
||||
|
||||
public OAuthClientsResource(RealmModel realm, KeycloakSession session) {
|
||||
this.realm = realm;
|
||||
this.session = session;
|
||||
|
@ -64,6 +68,7 @@ public class OAuthClientsResource {
|
|||
throw new NotFoundException();
|
||||
}
|
||||
OAuthClientResource oAuthClientResource = new OAuthClientResource(realm, oauth, session);
|
||||
resourceContext.initResource(oAuthClientResource);
|
||||
return oAuthClientResource;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ public class RealmAdminResource extends RoleContainerResource {
|
|||
@Path("oauth-clients")
|
||||
public OAuthClientsResource getOAuthClients() {
|
||||
OAuthClientsResource oauth = new OAuthClientsResource(realm, session);
|
||||
resourceContext.initResource(oauth);
|
||||
return oauth;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue