From 790fd1d94dda56a97626ed0370205da212e4cf5d Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Tue, 5 Aug 2014 16:45:21 -0400 Subject: [PATCH] fix cors example --- examples/cors/README.md | 2 +- examples/cors/angular-product-app/pom.xml | 2 +- .../cors/angular-product-app/src/main/webapp/js/app.js | 4 ++-- .../angular-product-app/src/main/webapp/keycloak.json | 4 ++-- examples/cors/cors-realm.json | 10 +++++----- examples/cors/database-service/pom.xml | 2 +- .../src/main/webapp/WEB-INF/keycloak.json | 2 +- .../database-service/src/main/webapp/WEB-INF/web.xml | 2 +- .../keycloak/models/utils/RepresentationToModel.java | 6 ++++++ 9 files changed, 20 insertions(+), 14 deletions(-) diff --git a/examples/cors/README.md b/examples/cors/README.md index 998d39027d..89ac4a85fd 100755 --- a/examples/cors/README.md +++ b/examples/cors/README.md @@ -59,7 +59,7 @@ Step 5: Login and Observe Apps --------------------------------------- Try going to the customer app and view customer data: -[http://localhost:8080/angular-product/index.html](http://localhost:8080/angular-product/index.html) +[http://localhost:8080/angular-cors-product/index.html](http://localhost:8080/angular-cors-product/index.html) This should take you to the auth-server login screen. Enter username: bburke@redhat.com and password: password. You should be brought back to a simple and boring HTML page. Click the Reload button to show the product listing. Reload diff --git a/examples/cors/angular-product-app/pom.xml b/examples/cors/angular-product-app/pom.xml index 4ba033ca88..0d0b1d6dd9 100755 --- a/examples/cors/angular-product-app/pom.xml +++ b/examples/cors/angular-product-app/pom.xml @@ -15,7 +15,7 @@ - angular-product + angular-cors-product org.jboss.as.plugins diff --git a/examples/cors/angular-product-app/src/main/webapp/js/app.js b/examples/cors/angular-product-app/src/main/webapp/js/app.js index d0939976c9..f2056cc68c 100755 --- a/examples/cors/angular-product-app/src/main/webapp/js/app.js +++ b/examples/cors/angular-product-app/src/main/webapp/js/app.js @@ -18,7 +18,7 @@ angular.element(document).ready(function ($http) { console.log('here login'); auth.loggedIn = true; auth.authz = keycloakAuth; - auth.logoutUrl = keycloakAuth.authServerUrl + "/realms/" + keycloakAuth.realm + "/tokens/logout?redirect_uri=/angular-product/index.html"; + auth.logoutUrl = keycloakAuth.authServerUrl + "/realms/" + keycloakAuth.realm + "/tokens/logout?redirect_uri=http://localhost:8080/angular-cors-product/index.html"; module.factory('Auth', function() { return auth; }); @@ -33,7 +33,7 @@ module.controller('GlobalCtrl', function($scope, $http) { $scope.products = []; $scope.roles = []; $scope.reloadData = function() { - $http.get("http://localhost-db:8080/database/products").success(function(data) { + $http.get("http://localhost-db:8080/cors-database/products").success(function(data) { $scope.products = angular.fromJson(data); }); diff --git a/examples/cors/angular-product-app/src/main/webapp/keycloak.json b/examples/cors/angular-product-app/src/main/webapp/keycloak.json index d9c653ba0a..40b35a1953 100755 --- a/examples/cors/angular-product-app/src/main/webapp/keycloak.json +++ b/examples/cors/angular-product-app/src/main/webapp/keycloak.json @@ -1,8 +1,8 @@ { "realm" : "cors", "realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-server-url" : "/auth", + "auth-server-url" : "http://localhost-auth:8080/auth", "ssl-required" : "external", - "resource" : "angular-product", + "resource" : "angular-cors-product", "public-client" : true } \ No newline at end of file diff --git a/examples/cors/cors-realm.json b/examples/cors/cors-realm.json index 423ddb2e39..82dcf0c681 100755 --- a/examples/cors/cors-realm.json +++ b/examples/cors/cors-realm.json @@ -38,18 +38,18 @@ }, "scopeMappings": [ { - "client": "angular-product", + "client": "angular-cors-product", "roles": ["user"] } ], "applications": [ { - "name": "angular-product", + "name": "angular-cors-product", "enabled": true, "publicClient": true, - "baseUrl": "/angular-product/index.html", + "baseUrl": "http://localhost:8080/angular-cors-product/index.html", "redirectUris": [ - "/angular-product/*" + "http://localhost:8080/angular-cors-product/*" ], "webOrigins": [ "http://localhost:8080" @@ -59,7 +59,7 @@ "applicationScopeMappings": { "realm-management": [ { - "client": "angular-product", + "client": "angular-cors-product", "roles": ["realm-admin"] } ] diff --git a/examples/cors/database-service/pom.xml b/examples/cors/database-service/pom.xml index e1c6dbf2ab..59e76eea79 100755 --- a/examples/cors/database-service/pom.xml +++ b/examples/cors/database-service/pom.xml @@ -55,7 +55,7 @@ - database + cors-database org.jboss.as.plugins diff --git a/examples/cors/database-service/src/main/webapp/WEB-INF/keycloak.json b/examples/cors/database-service/src/main/webapp/WEB-INF/keycloak.json index 23f6960207..0d292996e0 100755 --- a/examples/cors/database-service/src/main/webapp/WEB-INF/keycloak.json +++ b/examples/cors/database-service/src/main/webapp/WEB-INF/keycloak.json @@ -1,6 +1,6 @@ { "realm" : "cors-realm", - "resource" : "database-service", + "resource" : "cors-database-service", "realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", "bearer-only" : true, "ssl-required": "external", diff --git a/examples/cors/database-service/src/main/webapp/WEB-INF/web.xml b/examples/cors/database-service/src/main/webapp/WEB-INF/web.xml index dd90e3a331..6d78c1c9b3 100755 --- a/examples/cors/database-service/src/main/webapp/WEB-INF/web.xml +++ b/examples/cors/database-service/src/main/webapp/WEB-INF/web.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> - database + cors-database diff --git a/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java b/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java index 35a4acb32d..ec7a3ccd57 100755 --- a/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java +++ b/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java @@ -181,6 +181,9 @@ public class RepresentationToModel { if (rep.getScopeMappings() != null) { for (ScopeMappingRepresentation scope : rep.getScopeMappings()) { ClientModel client = newRealm.findClient(scope.getClient()); + if (client == null) { + throw new RuntimeException("Unknown client specification in realm scope mappings"); + } for (String roleString : scope.getRoles()) { RoleModel role = newRealm.getRole(roleString.trim()); if (role == null) { @@ -558,6 +561,9 @@ public class RepresentationToModel { public static void createApplicationScopeMappings(RealmModel realm, ApplicationModel applicationModel, List mappings) { for (ScopeMappingRepresentation mapping : mappings) { ClientModel client = realm.findClient(mapping.getClient()); + if (client == null) { + throw new RuntimeException("Unknown client specified in application scope mappings"); + } for (String roleString : mapping.getRoles()) { RoleModel role = applicationModel.getRole(roleString.trim()); if (role == null) {