diff --git a/ui/src/main/java/org/keycloak/ui/example/Admin.java b/ui/src/main/java/org/keycloak/ui/example/Admin.java index 912b9598f2..603feae5c3 100644 --- a/ui/src/main/java/org/keycloak/ui/example/Admin.java +++ b/ui/src/main/java/org/keycloak/ui/example/Admin.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.UUID; import javax.ws.rs.ApplicationPath; @@ -28,7 +29,7 @@ public class Admin extends javax.ws.rs.core.Application { private static Map realms = new HashMap(); - private static Map> users = new HashMap>(); + private static Map users = new HashMap(); @DELETE @Path("applications/{id}") @@ -89,7 +90,6 @@ public class Admin extends javax.ws.rs.core.Application { String id = UUID.randomUUID().toString(); realm.setId(id); realms.put(id, realm); - users.put(id, new HashMap()); return Response.created(URI.create("/realms/" + id)).build(); } @@ -105,34 +105,39 @@ public class Admin extends javax.ws.rs.core.Application { @Consumes(MediaType.APPLICATION_JSON) public void save(@PathParam("id") String id, Realm realm) { realms.put(id, realm); - users.put(id, new HashMap()); } @GET @Path("realms/{realm}/users/{id}") @Produces(MediaType.APPLICATION_JSON) public User getUser(@PathParam("realm") String realm, @PathParam("id") String id) { - return users.get(realm).get(id); + return users.get(new UserId(realm, id)); } @GET @Path("realms/{realm}/users") @Produces(MediaType.APPLICATION_JSON) public List getUsers(@PathParam("realm") String realm) { - return new LinkedList(users.get(realm).values()); + LinkedList list = new LinkedList(); + for (Entry e : users.entrySet()) { + if (e.getKey().getRealm().equals(realm)) { + list.add(e.getValue()); + } + } + return list; } @PUT @Path("realms/{realm}/users/{id}") @Consumes(MediaType.APPLICATION_JSON) public void save(@PathParam("realm") String realm, @PathParam("id") String id, User user) { - users.get(realm).put(id, user); + users.put(new UserId(realm, id), user); } @DELETE @Path("realms/{realm}/users/{id}") public void deleteUser(@PathParam("realm") String realm, @PathParam("id") String id) { - users.get(realm).remove(id); + users.remove(new UserId(realm, id)); } } \ No newline at end of file diff --git a/ui/src/main/java/org/keycloak/ui/example/User.java b/ui/src/main/java/org/keycloak/ui/example/User.java index e38778fcc0..08f2bd210b 100644 --- a/ui/src/main/java/org/keycloak/ui/example/User.java +++ b/ui/src/main/java/org/keycloak/ui/example/User.java @@ -32,6 +32,15 @@ public class User implements Serializable { private String lastName; private String userId; private String password; + private String[] roles; + + public String[] getRoles() { + return roles; + } + + public void setRoles(String[] roles) { + this.roles = roles; + } public String getPassword() { return password; diff --git a/ui/src/main/java/org/keycloak/ui/example/UserId.java b/ui/src/main/java/org/keycloak/ui/example/UserId.java new file mode 100644 index 0000000000..55d1a1b7fc --- /dev/null +++ b/ui/src/main/java/org/keycloak/ui/example/UserId.java @@ -0,0 +1,52 @@ +package org.keycloak.ui.example; + +public class UserId { + + private String realm; + private String user; + + public UserId(String realm, String user) { + this.realm = realm; + this.user = user; + } + + public String getRealm() { + return realm; + } + + public String getUser() { + return user; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((realm == null) ? 0 : realm.hashCode()); + result = prime * result + ((user == null) ? 0 : user.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + UserId other = (UserId) obj; + if (realm == null) { + if (other.realm != null) + return false; + } else if (!realm.equals(other.realm)) + return false; + if (user == null) { + if (other.user != null) + return false; + } else if (!user.equals(other.user)) + return false; + return true; + } + +} diff --git a/ui/src/main/resources/META-INF/resources/ui/js/app.js b/ui/src/main/resources/META-INF/resources/ui/js/app.js index f3559c0153..08691e5d37 100644 --- a/ui/src/main/resources/META-INF/resources/ui/js/app.js +++ b/ui/src/main/resources/META-INF/resources/ui/js/app.js @@ -110,6 +110,40 @@ module.config([ '$routeProvider', function($routeProvider) { } }, controller : 'RealmDetailCtrl' + }).when('/realms/:realm/roles', { + templateUrl : 'partials/role-mapping.html', + resolve : { + realms : function(RealmListLoader) { + return RealmListLoader(); + }, + realm : function(RealmLoader) { + return RealmLoader(); + }, + users : function(UserListLoader) { + return UserListLoader(); + }, + role : function() { + return null; + } + }, + controller : 'RoleMappingCtrl' + }).when('/realms/:realm/roles/:role', { + templateUrl : 'partials/role-mapping.html', + resolve : { + realms : function(RealmListLoader) { + return RealmListLoader(); + }, + realm : function(RealmLoader) { + return RealmLoader(); + }, + users : function(UserListLoader) { + return UserListLoader(); + }, + role : function($route) { + return $route.current.params.role; + } + }, + controller : 'RoleMappingCtrl' }).when('/realms', { templateUrl : 'partials/realm-list.html', resolve : { diff --git a/ui/src/main/resources/META-INF/resources/ui/js/controllers.js b/ui/src/main/resources/META-INF/resources/ui/js/controllers.js index a90d3bb8c8..f24797e928 100644 --- a/ui/src/main/resources/META-INF/resources/ui/js/controllers.js +++ b/ui/src/main/resources/META-INF/resources/ui/js/controllers.js @@ -357,4 +357,39 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $loc }); }); }; -}); \ No newline at end of file +}); + +module.controller('RoleMappingCtrl', function($scope, realms, realm, users, role, Notifications) { + $scope.realms = realms; + $scope.realm = realm; + $scope.allUsers = users; + $scope.users = []; + $scope.name = realm.name; + $scope.role = role; + + console.debug("role: " + role) + + $scope.addUser = function() { + for (var i = 0; i < $scope.allUsers.length; i++) { + if ($scope.allUsers[i].userId == $scope.newUser) { + console.debug("add user " + $scope.allUsers[i]); + $scope.users.push($scope.allUsers[i]); + $scope.newUser = null; + + // Send notification when rest call is success + Notifications.success("Saved role mapping for user"); + } + } + } + + $scope.removeUser = function(id) { + for (var i = 0; i < $scope.users.length; i++) { + if ($scope.users[i].userId == id) { + $scope.users.splice(i, 1); + + // Send notification when rest call is success + Notifications.success("Removed role mapping for user"); + } + } + } +}); diff --git a/ui/src/main/resources/META-INF/resources/ui/partials/application-detail.html b/ui/src/main/resources/META-INF/resources/ui/partials/application-detail.html index 57ea1c5129..0cbd1aae6c 100644 --- a/ui/src/main/resources/META-INF/resources/ui/partials/application-detail.html +++ b/ui/src/main/resources/META-INF/resources/ui/partials/application-detail.html @@ -5,8 +5,8 @@

- New Application {{application.name}} - configuration + New Application + {{application.name}} configuration

Please fill in all required fields
diff --git a/ui/src/main/resources/META-INF/resources/ui/partials/realm-menu.html b/ui/src/main/resources/META-INF/resources/ui/partials/realm-menu.html index f568909bfd..d36f2c8d0d 100644 --- a/ui/src/main/resources/META-INF/resources/ui/partials/realm-menu.html +++ b/ui/src/main/resources/META-INF/resources/ui/partials/realm-menu.html @@ -10,6 +10,7 @@ diff --git a/ui/src/main/resources/META-INF/resources/ui/partials/role-mapping.html b/ui/src/main/resources/META-INF/resources/ui/partials/role-mapping.html new file mode 100644 index 0000000000..e9eeace888 --- /dev/null +++ b/ui/src/main/resources/META-INF/resources/ui/partials/role-mapping.html @@ -0,0 +1,45 @@ +
+
+ +
+ +
+

+ {{name}} role mapping +

+ + + +
+ + + + + + + + + + + + + + + + + + + +
UsernameFirstnameLastnameEmail
{{user.userId}}{{user.firstName}}{{user.lastName}}{{user.email}}
+
+
+ +
+
+
\ No newline at end of file