From ae3c4e84590091c38c81a30b542fe3299960bb40 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Tue, 20 May 2014 17:40:45 -0400 Subject: [PATCH] default web origin is redirect uris --- .../resources/js/controllers/applications.js | 4 ++-- .../partials/application-detail.html | 2 +- .../services/managers/ApplicationManager.java | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/forms/common-themes/src/main/resources/theme/admin/base/resources/js/controllers/applications.js b/forms/common-themes/src/main/resources/theme/admin/base/resources/js/controllers/applications.js index bff3774d05..6c492d452a 100755 --- a/forms/common-themes/src/main/resources/theme/admin/base/resources/js/controllers/applications.js +++ b/forms/common-themes/src/main/resources/theme/admin/base/resources/js/controllers/applications.js @@ -268,11 +268,11 @@ module.controller('ApplicationDetailCtrl', function($scope, $document, realm, ap Notifications.error("You must specify at least one redirect uri"); } else { // automatically add redirects to web origins - var parser = $document.createElement('a'); + var parser = document.createElement('a'); var originSet = {}; for (var i = 0; i < $scope.application.redirectUris.length; i++) { parser.href = $scope.application.redirectUris[i]; - var origin = href.protocol + "//" + href.host; + var origin = parser.protocol + "//" + parser.host; originSet[origin] = true; } for (var key in originSet) { diff --git a/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/application-detail.html b/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/application-detail.html index 600f72e7a1..7f81b5c71f 100755 --- a/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/application-detail.html +++ b/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/application-detail.html @@ -90,7 +90,7 @@ data-ng-model="application.adminUrl"> -
+
diff --git a/services/src/main/java/org/keycloak/services/managers/ApplicationManager.java b/services/src/main/java/org/keycloak/services/managers/ApplicationManager.java index 1bb7e52a99..ae760e8d85 100755 --- a/services/src/main/java/org/keycloak/services/managers/ApplicationManager.java +++ b/services/src/main/java/org/keycloak/services/managers/ApplicationManager.java @@ -80,6 +80,26 @@ public class ApplicationManager { logger.debugv("Application: {0} webOrigin: {1}", resourceRep.getName(), webOrigin); applicationModel.addWebOrigin(webOrigin); } + } else { + // add origins from redirect uris + if (resourceRep.getRedirectUris() != null) { + Set origins = new HashSet(); + for (String redirectUri : resourceRep.getRedirectUris()) { + logger.info("add redirectUri to origin: " + redirectUri); + if (redirectUri.startsWith("http:")) { + URI uri = URI.create(redirectUri); + String origin = uri.getScheme() + "://" + uri.getHost(); + if (uri.getPort() != -1) { + origin += ":" + uri.getPort(); + } + logger.debugv("adding default application origin: {0}" , origin); + origins.add(origin); + } + } + if (origins.size() > 0) { + applicationModel.setWebOrigins(origins); + } + } } if (resourceRep.getDefaultRoles() != null) {