fix cors example

This commit is contained in:
Bill Burke 2014-08-05 16:45:21 -04:00
parent 19e1ddff1d
commit 790fd1d94d
9 changed files with 20 additions and 14 deletions

View file

@ -59,7 +59,7 @@ Step 5: Login and Observe Apps
--------------------------------------- ---------------------------------------
Try going to the customer app and view customer data: 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 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 should be brought back to a simple and boring HTML page. Click the Reload button to show the product listing. Reload

View file

@ -15,7 +15,7 @@
<description/> <description/>
<build> <build>
<finalName>angular-product</finalName> <finalName>angular-cors-product</finalName>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.jboss.as.plugins</groupId> <groupId>org.jboss.as.plugins</groupId>

View file

@ -18,7 +18,7 @@ angular.element(document).ready(function ($http) {
console.log('here login'); console.log('here login');
auth.loggedIn = true; auth.loggedIn = true;
auth.authz = keycloakAuth; 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() { module.factory('Auth', function() {
return auth; return auth;
}); });
@ -33,7 +33,7 @@ module.controller('GlobalCtrl', function($scope, $http) {
$scope.products = []; $scope.products = [];
$scope.roles = []; $scope.roles = [];
$scope.reloadData = function() { $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); $scope.products = angular.fromJson(data);
}); });

View file

@ -1,8 +1,8 @@
{ {
"realm" : "cors", "realm" : "cors",
"realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", "realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB",
"auth-server-url" : "/auth", "auth-server-url" : "http://localhost-auth:8080/auth",
"ssl-required" : "external", "ssl-required" : "external",
"resource" : "angular-product", "resource" : "angular-cors-product",
"public-client" : true "public-client" : true
} }

View file

@ -38,18 +38,18 @@
}, },
"scopeMappings": [ "scopeMappings": [
{ {
"client": "angular-product", "client": "angular-cors-product",
"roles": ["user"] "roles": ["user"]
} }
], ],
"applications": [ "applications": [
{ {
"name": "angular-product", "name": "angular-cors-product",
"enabled": true, "enabled": true,
"publicClient": true, "publicClient": true,
"baseUrl": "/angular-product/index.html", "baseUrl": "http://localhost:8080/angular-cors-product/index.html",
"redirectUris": [ "redirectUris": [
"/angular-product/*" "http://localhost:8080/angular-cors-product/*"
], ],
"webOrigins": [ "webOrigins": [
"http://localhost:8080" "http://localhost:8080"
@ -59,7 +59,7 @@
"applicationScopeMappings": { "applicationScopeMappings": {
"realm-management": [ "realm-management": [
{ {
"client": "angular-product", "client": "angular-cors-product",
"roles": ["realm-admin"] "roles": ["realm-admin"]
} }
] ]

View file

@ -55,7 +55,7 @@
</dependencies> </dependencies>
<build> <build>
<finalName>database</finalName> <finalName>cors-database</finalName>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.jboss.as.plugins</groupId> <groupId>org.jboss.as.plugins</groupId>

View file

@ -1,6 +1,6 @@
{ {
"realm" : "cors-realm", "realm" : "cors-realm",
"resource" : "database-service", "resource" : "cors-database-service",
"realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", "realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB",
"bearer-only" : true, "bearer-only" : true,
"ssl-required": "external", "ssl-required": "external",

View file

@ -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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"> version="3.0">
<module-name>database</module-name> <module-name>cors-database</module-name>
<security-constraint> <security-constraint>
<web-resource-collection> <web-resource-collection>

View file

@ -181,6 +181,9 @@ public class RepresentationToModel {
if (rep.getScopeMappings() != null) { if (rep.getScopeMappings() != null) {
for (ScopeMappingRepresentation scope : rep.getScopeMappings()) { for (ScopeMappingRepresentation scope : rep.getScopeMappings()) {
ClientModel client = newRealm.findClient(scope.getClient()); ClientModel client = newRealm.findClient(scope.getClient());
if (client == null) {
throw new RuntimeException("Unknown client specification in realm scope mappings");
}
for (String roleString : scope.getRoles()) { for (String roleString : scope.getRoles()) {
RoleModel role = newRealm.getRole(roleString.trim()); RoleModel role = newRealm.getRole(roleString.trim());
if (role == null) { if (role == null) {
@ -558,6 +561,9 @@ public class RepresentationToModel {
public static void createApplicationScopeMappings(RealmModel realm, ApplicationModel applicationModel, List<ScopeMappingRepresentation> mappings) { public static void createApplicationScopeMappings(RealmModel realm, ApplicationModel applicationModel, List<ScopeMappingRepresentation> mappings) {
for (ScopeMappingRepresentation mapping : mappings) { for (ScopeMappingRepresentation mapping : mappings) {
ClientModel client = realm.findClient(mapping.getClient()); ClientModel client = realm.findClient(mapping.getClient());
if (client == null) {
throw new RuntimeException("Unknown client specified in application scope mappings");
}
for (String roleString : mapping.getRoles()) { for (String roleString : mapping.getRoles()) {
RoleModel role = applicationModel.getRole(roleString.trim()); RoleModel role = applicationModel.getRole(roleString.trim());
if (role == null) { if (role == null) {