Details
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 912b959..603feae 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<String, Realm> realms = new HashMap<String, Realm>();
- private static Map<String, Map<String, User>> users = new HashMap<String, Map<String, User>>();
+ private static Map<UserId, User> users = new HashMap<UserId, User>();
@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<String, User>());
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<String, User>());
}
@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<User> getUsers(@PathParam("realm") String realm) {
- return new LinkedList<User>(users.get(realm).values());
+ LinkedList<User> list = new LinkedList<User>();
+ for (Entry<UserId, User> 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 e38778f..08f2bd2 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 0000000..55d1a1b
--- /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 f3559c0..08691e5 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 a90d3bb..f24797e 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 57ea1c5..0cbd1aa 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 @@
<div id="container-right" class="span9">
<h1>
- <span class="gray" data-ng-show="create">New Application</span> <span class="gray" data-ng-hide="create">{{application.name}}</span>
- configuration
+ <span class="gray" data-ng-show="create">New Application</span>
+ <span class="gray" data-ng-hide="create">{{application.name}}</span> configuration
</h1>
<div data-ng-show="applicationForm.showErrors && applicationForm.$error.required" class="alert alert-error">Please fill in all required fields</div>
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 f568909..d36f2c8 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 @@
<ul class="sub-items" data-ng-show="realm.id == r.id">
<li data-ng-class="!path[2] && 'active'"><a href="#/realms/{{r.id}}">Configuration</a></li>
<li data-ng-class="path[2] == 'users' && 'active'"><a href="#/realms/{{r.id}}/users">Users</a></li>
+ <li data-ng-class="path[2] == 'roles' && 'active'"><a href="#/realms/{{r.id}}/roles">Role mapping</a></li>
</ul>
</li>
</ul>
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 0000000..e9eeace
--- /dev/null
+++ b/ui/src/main/resources/META-INF/resources/ui/partials/role-mapping.html
@@ -0,0 +1,45 @@
+<div id="wrapper" class="container">
+ <div class="row">
+ <aside class="span3" data-ng-include data-src="'partials/realm-menu.html'"></aside>
+ <div id="actions-bg"></div>
+
+ <div id="container-right" class="span9">
+ <h1>
+ <span class="gray" data-ng-hide="create">{{name}}</span> role mapping
+ </h1>
+
+ <ul class="nav nav-tabs">
+ <li data-ng-class="path[3] == r && 'active'" data-ng-repeat="r in (realm.roles|orderBy:'toString()')"><a href="#/realms/{{realm.id}}/roles/{{r}}">{{r}}</a></li>
+ </ul>
+
+ <div data-ng-show="role">
+ <select id="realm" name="realm" data-ng-model="newUser" data-ng-click="addUser(u)">
+ <option data-ng-repeat="u in (allUsers|remove:users)" value="{{u.userId}}">{{u.userId}}</option>
+ </select>
+
+ <table class="table table-striped table-bordered">
+ <thead>
+ <tr>
+ <th>Username</th>
+ <th>Firstname</th>
+ <th>Lastname</th>
+ <th>Email</th>
+ <th></th>
+ </tr>
+ </thead>
+ <tr data-ng-repeat="user in users">
+ <td>{{user.userId}}</td>
+ <td>{{user.firstName}}</td>
+ <td>{{user.lastName}}</td>
+ <td>{{user.email}}</td>
+ <td><button ng-click="removeUser(user.userId)">
+ <i class="icon-remove"></i>
+ </button></td>
+ </tr>
+ </table>
+ </div>
+ </div>
+
+ <div id="container-right-bg"></div>
+ </div>
+</div>
\ No newline at end of file