From 2db41ef0522a613644a83dea3a289553304ba2b1 Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Tue, 28 Jun 2016 11:43:43 -0300 Subject: [PATCH] [KEYCLOAK-2999] - Changes to authz examples for integration test --- .../js/src/main/resources/keycloak-authz.js | 4 +- .../hello-world-authz-realm.json | 5 +- .../authz/hello-world-authz-service/pom.xml | 1 - .../src/main/webapp/WEB-INF/keycloak.json | 2 +- .../src/main/webapp/index.html | 1 - .../src/main/webapp/keycloak.json | 8 +-- .../main/webapp/partials/admin/albums.html | 2 +- .../main/webapp/partials/album/create.html | 4 +- .../src/main/webapp/partials/home.html | 8 +-- examples/authz/photoz/photoz-realm.json | 6 ++- .../photoz-restful-api-authz-service.json | 2 +- .../authz/photoz/photoz-restful-api/pom.xml | 1 + .../example/photoz/album/AlbumService.java | 35 ++++++++++-- .../src/main/resources/keycloak.json | 8 --- .../servlet-authz/src/main/webapp/index.jsp | 2 +- .../resources/js/authz/authz-controller.js | 54 ++++++++----------- .../resources/js/authz/authz-services.js | 1 + .../authz/resource-server-detail.html | 18 ++++--- 18 files changed, 85 insertions(+), 77 deletions(-) delete mode 100644 examples/authz/photoz/photoz-restful-api/src/main/resources/keycloak.json diff --git a/adapters/oidc/js/src/main/resources/keycloak-authz.js b/adapters/oidc/js/src/main/resources/keycloak-authz.js index 7658352ade..dd18477ec4 100644 --- a/adapters/oidc/js/src/main/resources/keycloak-authz.js +++ b/adapters/oidc/js/src/main/resources/keycloak-authz.js @@ -49,7 +49,7 @@ */ this.authorize = function (wwwAuthenticateHeader) { this.then = function (onGrant, onDeny, onError) { - if (wwwAuthenticateHeader.startsWith('UMA')) { + if (wwwAuthenticateHeader.indexOf('UMA') != -1) { var params = wwwAuthenticateHeader.split(','); for (i = 0; i < params.length; i++) { @@ -96,7 +96,7 @@ )); } } - } else if (wwwAuthenticateHeader.startsWith('KC_ETT')) { + } else if (wwwAuthenticateHeader.indexOf('KC_ETT') != -1) { var params = wwwAuthenticateHeader.substring('KC_ETT'.length).trim().split(','); var clientId = null; diff --git a/examples/authz/hello-world-authz-service/hello-world-authz-realm.json b/examples/authz/hello-world-authz-service/hello-world-authz-realm.json index 3ab917c058..022ee6f177 100644 --- a/examples/authz/hello-world-authz-service/hello-world-authz-realm.json +++ b/examples/authz/hello-world-authz-service/hello-world-authz-realm.json @@ -1,9 +1,8 @@ { "realm" : "hello-world-authz", "enabled" : true, - "privateKey" : "MIIEpQIBAAKCAQEAzMhNM9HXNQWhVf1m64zS67SIyQjj+tV5GR+MqlRTWDXdo8GAWHd+alY1urRhfRoqMy4F499+8wh2REKFykNt0ng6s6wWnEaKDboS3SAUV6lybcOAkwIOCtCZj1ItddKG3m64fzxDDQrcpkbiAvw3S8KJ4UJK+pyh9iX01duSDtM/HhPawsPdY8JSMfuo1IxQ2Vxw+8RKwbbdUeew6cyYGYAeFYwA66mlM3otB0RBHh4bjwg8297+2g53TdwM2rbCHRbrorMQD3031OTyFSp7lXCtoMLWRfAFnOP/2yZWZMXbiJheC0R3sLbU7Ef0/cUbYyk4Ckfq6pcYDR+VZBF7AwIDAQABAoIBAAwa4wVnKBOIS6srmYPfBTDNsTBBCEjxiYEErmn7JhoWxQ1DCPUxyxU6F177/q9Idqoj1FFOCtEO9P6/9+ym470HQmEQkR2Xxd1d3HOZy9oKuCro3ZbTDkVxY0JnlyxZz4MihGFxDH2e4MArfHy0sAgYbdIU+x2pWKGWSMzDd/TMSOExhc/sIQAg6ljbPCLLXCPQFAncoHRyGPrkRZs6UTZi5SJuCglVa2/3G+0drDdPuA83/mwsZfIBqQgbGbFgtq5T5C6CKMkPOQ42Rcclm7kEr6riTkJRo23EO1iOJVpxzI0tbxZsJAsW7zeqv0wWRyUgVfQAje6OdsNexp5aCtECgYEA6nMHCQ9xXvufCyzpIbYGxdAGqH6m1AR5gXerHqRiGNx+8UUt/E9cy/HTOhmZDK/eC4BT9tImeF01l1oSU/+wGKfux0SeAQchBhhq8GD6jmrtgczKAfZHp0Zrht7o9qu9KE7ZN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LGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQABAoGAfmO8gVhyBxdqlxmIuglbz8bcjQbhXJLR2EoS8ngTXmN1bo2L90M0mUKSdc7qF10LgETBzqL8jYlQIbt+e6TH8fcEpKCjUlyq0Mf/vVbfZSNaVycY13nTzo27iPyWQHK5NLuJzn1xvxxrUeXI6A2WFpGEBLbHjwpx5WQG9A+2scECQQDvdn9NE75HPTVPxBqsEd2z10TKkl9CZxu10Qby3iQQmWLEJ9LNmy3acvKrE3gMiYNWb6xHPKiIqOR1as7L24aTAkEAtyvQOlCvr5kAjVqrEKXalj0Tzewjweuxc0pskvArTI2Oo070h65GpoIKLc9jf+UA69cRtquwP93aZKtW06U8dQJAF2Y44ks/mK5+eyDqik3koCI08qaC8HYq2wVl7G2QkJ6sbAaILtcvD92ToOvyGyeE0flvmDZxMYlvaZnaQ0lcSQJBAKZU6umJi3/xeEbkJqMfeLclD27XGEFoPeNrmdx0q10Azp4NfJAY+Z8KRyQCR2BEG+oNitBOZ+YXF9KCpH3cdmECQHEigJhYg+ykOvr1aiZUMFT72HU0jnmQe2FVekuG+LJUt2Tm7GtMjTFoGpf0JwrVuZN39fOYAlo+nTixgeW7X8Y=", + "publicKey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", "requiredCredentials" : [ "password" ], "users" : [ diff --git a/examples/authz/hello-world-authz-service/pom.xml b/examples/authz/hello-world-authz-service/pom.xml index 5b9b646dd9..679dd72331 100755 --- a/examples/authz/hello-world-authz-service/pom.xml +++ b/examples/authz/hello-world-authz-service/pom.xml @@ -34,7 +34,6 @@ Keycloak Authz: Hello World Example - ${project.artifactId} org.jboss.as.plugins diff --git a/examples/authz/hello-world-authz-service/src/main/webapp/WEB-INF/keycloak.json b/examples/authz/hello-world-authz-service/src/main/webapp/WEB-INF/keycloak.json index f303fe1e55..a492837299 100644 --- a/examples/authz/hello-world-authz-service/src/main/webapp/WEB-INF/keycloak.json +++ b/examples/authz/hello-world-authz-service/src/main/webapp/WEB-INF/keycloak.json @@ -1,6 +1,6 @@ { "realm": "hello-world-authz", - "realm-public-key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzMhNM9HXNQWhVf1m64zS67SIyQjj+tV5GR+MqlRTWDXdo8GAWHd+alY1urRhfRoqMy4F499+8wh2REKFykNt0ng6s6wWnEaKDboS3SAUV6lybcOAkwIOCtCZj1ItddKG3m64fzxDDQrcpkbiAvw3S8KJ4UJK+pyh9iX01duSDtM/HhPawsPdY8JSMfuo1IxQ2Vxw+8RKwbbdUeew6cyYGYAeFYwA66mlM3otB0RBHh4bjwg8297+2g53TdwM2rbCHRbrorMQD3031OTyFSp7lXCtoMLWRfAFnOP/2yZWZMXbiJheC0R3sLbU7Ef0/cUbYyk4Ckfq6pcYDR+VZBF7AwIDAQAB", + "realm-public-key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", "auth-server-url": "http://localhost:8080/auth", "ssl-required": "external", "resource": "hello-world-authz-service", diff --git a/examples/authz/photoz/photoz-html5-client/src/main/webapp/index.html b/examples/authz/photoz/photoz-html5-client/src/main/webapp/index.html index f9375a299f..98f0856db0 100755 --- a/examples/authz/photoz/photoz-html5-client/src/main/webapp/index.html +++ b/examples/authz/photoz/photoz-html5-client/src/main/webapp/index.html @@ -13,7 +13,6 @@ - diff --git a/examples/authz/photoz/photoz-html5-client/src/main/webapp/keycloak.json b/examples/authz/photoz/photoz-html5-client/src/main/webapp/keycloak.json index 4b4d193d4a..c1dee24574 100644 --- a/examples/authz/photoz/photoz-html5-client/src/main/webapp/keycloak.json +++ b/examples/authz/photoz/photoz-html5-client/src/main/webapp/keycloak.json @@ -1,12 +1,8 @@ { "realm": "photoz", - "realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", + "realm-public-key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", "auth-server-url" : "http://localhost:8080/auth", "ssl-required" : "external", "resource" : "photoz-html5-client", - "public-client" : true, - "use-resource-role-mappings": "false", - "scope" : { - "realm" : [ "user" ] - } + "public-client" : true } \ No newline at end of file diff --git a/examples/authz/photoz/photoz-html5-client/src/main/webapp/partials/admin/albums.html b/examples/authz/photoz/photoz-html5-client/src/main/webapp/partials/admin/albums.html index bb381b9dd7..da78224f91 100644 --- a/examples/authz/photoz/photoz-html5-client/src/main/webapp/partials/admin/albums.html +++ b/examples/authz/photoz/photoz-html5-client/src/main/webapp/partials/admin/albums.html @@ -10,7 +10,7 @@ diff --git a/examples/authz/photoz/photoz-html5-client/src/main/webapp/partials/album/create.html b/examples/authz/photoz/photoz-html5-client/src/main/webapp/partials/album/create.html index 556693c7ce..d9ddd25813 100644 --- a/examples/authz/photoz/photoz-html5-client/src/main/webapp/partials/album/create.html +++ b/examples/authz/photoz/photoz-html5-client/src/main/webapp/partials/album/create.html @@ -1,7 +1,7 @@

Create an Album

- Name: + Name: - +
diff --git a/examples/authz/photoz/photoz-html5-client/src/main/webapp/partials/home.html b/examples/authz/photoz/photoz-html5-client/src/main/webapp/partials/home.html index 5e164b2fc7..bd5853ea8e 100644 --- a/examples/authz/photoz/photoz-html5-client/src/main/webapp/partials/home.html +++ b/examples/authz/photoz/photoz-html5-client/src/main/webapp/partials/home.html @@ -1,12 +1,12 @@

Welcome To Photoz, {{Identity.claims.name}} [Sign Out]

-
Administration: [All Albums]
+
Administration: [All Albums]


-Create Album | My Profile +Create Album | My Profile

-You don't have any albums, yet. +You don't have any albums, yet. @@ -15,7 +15,7 @@ - +
{{p.name}} - [X]{{p.name}} - [X]
diff --git a/examples/authz/photoz/photoz-realm.json b/examples/authz/photoz/photoz-realm.json index 342665ebc6..b3b2b8132a 100644 --- a/examples/authz/photoz/photoz-realm.json +++ b/examples/authz/photoz/photoz-realm.json @@ -92,17 +92,19 @@ "publicClient": true, "redirectUris": [ "/photoz-html5-client/*" - ] + ], + "webOrigins": ["*"] }, { "clientId": "photoz-restful-api", + "secret": "secret", "enabled": true, "baseUrl": "/photoz-restful-api", "authorizationServicesEnabled" : true, "redirectUris": [ "/photoz-restful-api/*" ], - "secret": "secret" + "webOrigins" : ["*"] } ] } diff --git a/examples/authz/photoz/photoz-restful-api-authz-service.json b/examples/authz/photoz/photoz-restful-api-authz-service.json index 1d0356c5c7..ff9ee9cd6d 100644 --- a/examples/authz/photoz/photoz-restful-api-authz-service.json +++ b/examples/authz/photoz/photoz-restful-api-authz-service.json @@ -152,7 +152,7 @@ } }, { - "name": "Delete Album Policy", + "name": "Delete Album Permission", "description": "A policy that only allows the owner to delete his albums.", "type": "scope", "logic": "POSITIVE", diff --git a/examples/authz/photoz/photoz-restful-api/pom.xml b/examples/authz/photoz/photoz-restful-api/pom.xml index eea3c17de5..4db7bb2654 100755 --- a/examples/authz/photoz/photoz-restful-api/pom.xml +++ b/examples/authz/photoz/photoz-restful-api/pom.xml @@ -25,6 +25,7 @@ org.jboss.spec.javax.servlet jboss-servlet-api_3.0_spec + provided javax.persistence diff --git a/examples/authz/photoz/photoz-restful-api/src/main/java/org/keycloak/example/photoz/album/AlbumService.java b/examples/authz/photoz/photoz-restful-api/src/main/java/org/keycloak/example/photoz/album/AlbumService.java index be2f1eb28c..388c9e4c8b 100644 --- a/examples/authz/photoz/photoz-restful-api/src/main/java/org/keycloak/example/photoz/album/AlbumService.java +++ b/examples/authz/photoz/photoz-restful-api/src/main/java/org/keycloak/example/photoz/album/AlbumService.java @@ -1,11 +1,14 @@ package org.keycloak.example.photoz.album; import org.keycloak.authorization.client.AuthzClient; +import org.keycloak.authorization.client.Configuration; import org.keycloak.authorization.client.representation.ResourceRepresentation; import org.keycloak.authorization.client.representation.ScopeRepresentation; import org.keycloak.authorization.client.resource.ProtectionResource; import org.keycloak.example.photoz.ErrorResponse; import org.keycloak.example.photoz.entity.Album; +import org.keycloak.representations.adapters.config.AdapterConfig; +import org.keycloak.util.JsonSerialization; import javax.ejb.Stateless; import javax.persistence.EntityManager; @@ -38,9 +41,18 @@ public class AlbumService { @PersistenceContext private EntityManager entityManager; + @Context + private HttpServletRequest request; + + private AuthzClient authzClient; + + public AlbumService() { + + } + @POST @Consumes("application/json") - public Response create(@Context HttpServletRequest request, Album newAlbum) { + public Response create(Album newAlbum) { Principal userPrincipal = request.getUserPrincipal(); newAlbum.setUserId(userPrincipal.getName()); @@ -78,7 +90,7 @@ public class AlbumService { @GET @Produces("application/json") - public Response findAll(@Context HttpServletRequest request) { + public Response findAll() { return Response.ok(this.entityManager.createQuery("from Album where userId = '" + request.getUserPrincipal().getName() + "'").getResultList()).build(); } @@ -107,7 +119,7 @@ public class AlbumService { albumResource.setOwner(album.getUserId()); - AuthzClient.create().protection().resource().create(albumResource); + getAuthzClient().protection().resource().create(albumResource); } catch (Exception e) { throw new RuntimeException("Could not register protected resource.", e); } @@ -117,7 +129,7 @@ public class AlbumService { String uri = "/album/" + album.getId(); try { - ProtectionResource protection = AuthzClient.create().protection(); + ProtectionResource protection = getAuthzClient().protection(); Set search = protection.resource().findByFilter("uri=" + uri); if (search.isEmpty()) { @@ -129,4 +141,19 @@ public class AlbumService { throw new RuntimeException("Could not search protected resource.", e); } } + + private AuthzClient getAuthzClient() { + if (this.authzClient == null) { + try { + AdapterConfig adapterConfig = JsonSerialization.readValue(this.request.getServletContext().getResourceAsStream("/WEB-INF/keycloak.json"), AdapterConfig.class); + Configuration configuration = new Configuration(adapterConfig.getAuthServerUrl(), adapterConfig.getRealm(), adapterConfig.getResource(), adapterConfig.getCredentials(), null); + + this.authzClient = AuthzClient.create(configuration); + } catch (Exception e) { + throw new RuntimeException("Could not create authorization client.", e); + } + } + + return this.authzClient; + } } diff --git a/examples/authz/photoz/photoz-restful-api/src/main/resources/keycloak.json b/examples/authz/photoz/photoz-restful-api/src/main/resources/keycloak.json deleted file mode 100644 index e7288274b0..0000000000 --- a/examples/authz/photoz/photoz-restful-api/src/main/resources/keycloak.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "realm": "photoz", - "auth-server-url": "http://localhost:8080/auth", - "resource": "photoz-restful-api", - "credentials": { - "secret": "secret" - } -} \ No newline at end of file diff --git a/examples/authz/servlet-authz/src/main/webapp/index.jsp b/examples/authz/servlet-authz/src/main/webapp/index.jsp index 78c54440b1..3fbfca269c 100755 --- a/examples/authz/servlet-authz/src/main/webapp/index.jsp +++ b/examples/authz/servlet-authz/src/main/webapp/index.jsp @@ -1,6 +1,6 @@ <%@page import="org.keycloak.AuthorizationContext" %> <%@ page import="org.keycloak.KeycloakSecurityContext" %> -<%@ page import="org.keycloak.representations.authorization.Permission" %> +<%@ page import="org.keycloak.representations.idm.authorization.Permission" %> <% KeycloakSecurityContext keycloakSecurityContext = (KeycloakSecurityContext) request.getAttribute(KeycloakSecurityContext.class.getName()); diff --git a/themes/src/main/resources/theme/base/admin/resources/js/authz/authz-controller.js b/themes/src/main/resources/theme/base/admin/resources/js/authz/authz-controller.js index ecbe9d533e..216a5a9681 100644 --- a/themes/src/main/resources/theme/base/admin/resources/js/authz/authz-controller.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/authz/authz-controller.js @@ -6,7 +6,7 @@ module.controller('ResourceServerCtrl', function($scope, realm, ResourceServer) }); }); -module.controller('ResourceServerDetailCtrl', function($scope, $http, $route, $location, $upload, realm, ResourceServer, client, AuthzDialog, Notifications) { +module.controller('ResourceServerDetailCtrl', function($scope, $http, $route, $location, $upload, $modal, realm, ResourceServer, client, AuthzDialog, Notifications) { $scope.realm = realm; $scope.client = client; @@ -31,8 +31,7 @@ module.controller('ResourceServerDetailCtrl', function($scope, $http, $route, $l } $scope.reset = function() { - $scope.server = angular.copy(data); - $scope.changed = false; + $route.reload(); } $scope.export = function() { @@ -54,38 +53,29 @@ module.controller('ResourceServerDetailCtrl', function($scope, $http, $route, $l delete $scope.settings } - $scope.onFileSelect = function($files) { - $scope.files = $files; + $scope.onFileSelect = function($fileContent) { + $scope.server = angular.copy(JSON.parse($fileContent)); + $scope.importing = true; }; - $scope.clearFileSelect = function() { - $scope.files = null; + $scope.viewImportDetails = function() { + $modal.open({ + templateUrl: resourceUrl + '/partials/modal/view-object.html', + controller: 'ObjectModalCtrl', + resolve: { + object: function () { + return $scope.server; + } + } + }) + }; + + $scope.import = function () { + ResourceServer.import({realm : realm.realm, client : client.id}, $scope.server, function() { + $route.reload(); + Notifications.success("The resource server has been updated."); + }); } - - $scope.uploadFile = function() { - //$files: an array of files selected, each file has name, size, and type. - for (var i = 0; i < $scope.files.length; i++) { - var $file = $scope.files[i]; - $scope.upload = $upload.upload({ - url: authUrl + '/admin/realms/' + $route.current.params.realm + '/clients/' + client.id + '/authz/resource-server', //upload.php script, node.js route, or servlet url - // method: POST or PUT, - // headers: {'headerKey': 'headerValue'}, withCredential: true, - data: {myObj: ""}, - file: $file - /* set file formData name for 'Content-Desposition' header. Default: 'file' */ - //fileFormDataName: myFile, - /* customize how data is added to formData. See #40#issuecomment-28612000 for example */ - //formDataAppender: function(formData, key, val){} - }).progress(function(evt) { - console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total)); - }).success(function(data, status, headers) { - $route.reload(); - Notifications.success("The resource server has been updated."); - }).error(function() { - Notifications.error("The resource server can not be uploaded. Please verify the file."); - }); - } - }; }); }); diff --git a/themes/src/main/resources/theme/base/admin/resources/js/authz/authz-services.js b/themes/src/main/resources/theme/base/admin/resources/js/authz/authz-services.js index c74db28386..e6114309d6 100644 --- a/themes/src/main/resources/theme/base/admin/resources/js/authz/authz-services.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/authz/authz-services.js @@ -4,6 +4,7 @@ module.factory('ResourceServer', function($resource) { client: '@client' }, { 'update' : {method : 'PUT'}, + 'import' : {url: authUrl + '/admin/realms/:realm/clients/:client/authz/resource-server/import', method : 'POST'}, 'settings' : {url: authUrl + '/admin/realms/:realm/clients/:client/authz/resource-server/settings', method : 'GET'} }); }); diff --git a/themes/src/main/resources/theme/base/admin/resources/partials/authz/resource-server-detail.html b/themes/src/main/resources/theme/base/admin/resources/partials/authz/resource-server-detail.html index 918cadf8ea..2b3cd70c60 100644 --- a/themes/src/main/resources/theme/base/admin/resources/partials/authz/resource-server-detail.html +++ b/themes/src/main/resources/theme/base/admin/resources/partials/authz/resource-server-detail.html @@ -7,22 +7,24 @@
-
+
- + +
+
+
- {{files[0].name}}
Import a JSON file containing all settings for this resource server.
-
- - +
+ +
-
+
@@ -54,7 +56,7 @@
-
+
Export Settings Here you can export all settings for this resource server.