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 2a70f7807e..912b9598f2 100644 --- a/ui/src/main/java/org/keycloak/ui/example/Admin.java +++ b/ui/src/main/java/org/keycloak/ui/example/Admin.java @@ -28,34 +28,37 @@ public class Admin extends javax.ws.rs.core.Application { private static Map realms = new HashMap(); + private static Map> users = new HashMap>(); + @DELETE - @Path("/applications/{id}") - public void delete(@PathParam("id") String id) { + @Path("applications/{id}") + public void deleteApplication(@PathParam("id") String id) { applications.remove(id); } @DELETE - @Path("/realms/{id}") + @Path("realms/{id}") public void deleteRealm(@PathParam("id") String id) { realms.remove(id); + users.remove(id); } @GET - @Path("/applications/{id}") + @Path("applications/{id}") @Produces(MediaType.APPLICATION_JSON) public Application getApplication(@PathParam("id") String id) { return applications.get(id); } @GET - @Path("/applications") + @Path("applications") @Produces(MediaType.APPLICATION_JSON) public List getApplications() { return new LinkedList(applications.values()); } @GET - @Path("/realms/{id}") + @Path("realms/{id}") @Produces(MediaType.APPLICATION_JSON) public Realm getRealm(@PathParam("id") String id) { return realms.get(id); @@ -63,14 +66,14 @@ public class Admin extends javax.ws.rs.core.Application { @GET - @Path("/realms") + @Path("realms") @Produces(MediaType.APPLICATION_JSON) public List getRealms() { return new LinkedList(realms.values()); } @POST - @Path("/applications") + @Path("applications") @Consumes(MediaType.APPLICATION_JSON) public Response save(Application application) { String id = UUID.randomUUID().toString(); @@ -80,26 +83,56 @@ public class Admin extends javax.ws.rs.core.Application { } @POST - @Path("/realms") + @Path("realms") @Consumes(MediaType.APPLICATION_JSON) public Response save(Realm realm) { 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(); } @PUT - @Path("/applications/{id}") + @Path("applications/{id}") @Consumes(MediaType.APPLICATION_JSON) public void save(@PathParam("id") String id, Application application) { applications.put(id, application); } @PUT - @Path("/realms/{id}") + @Path("realms/{id}") @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); + } + + @GET + @Path("realms/{realm}/users") + @Produces(MediaType.APPLICATION_JSON) + public List getUsers(@PathParam("realm") String realm) { + return new LinkedList(users.get(realm).values()); + } + + @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); + } + + @DELETE + @Path("realms/{realm}/users/{id}") + public void deleteUser(@PathParam("realm") String realm, @PathParam("id") String id) { + users.get(realm).remove(id); + } + } \ No newline at end of file diff --git a/ui/src/main/java/org/keycloak/ui/example/Attribute.java b/ui/src/main/java/org/keycloak/ui/example/Attribute.java new file mode 100644 index 0000000000..7e95923a24 --- /dev/null +++ b/ui/src/main/java/org/keycloak/ui/example/Attribute.java @@ -0,0 +1,40 @@ +package org.keycloak.ui.example; + +import java.io.Serializable; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class Attribute implements Serializable { + + private static final long serialVersionUID = 1L; + + private String name; + + private String value; + + public Attribute() { + } + + public Attribute(String name, String value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public String getValue() { + return value; + } + + public void setName(String name) { + this.name = name; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/ui/src/main/java/org/keycloak/ui/example/User.java b/ui/src/main/java/org/keycloak/ui/example/User.java new file mode 100644 index 0000000000..e38778fcc0 --- /dev/null +++ b/ui/src/main/java/org/keycloak/ui/example/User.java @@ -0,0 +1,84 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2012, Red Hat, Inc., and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.keycloak.ui.example; + +import java.io.Serializable; +import java.util.List; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class User implements Serializable { + + private static final long serialVersionUID = 1L; + + private List attributes; + private String email; + private String firstName; + private String lastName; + private String userId; + private String password; + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public List getAttributes() { + return attributes; + } + + public String getEmail() { + return email; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getUserId() { + return userId; + } + + public void setAttributes(List attributes) { + this.attributes = attributes; + } + + public void setEmail(String email) { + this.email = email; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public void setUserId(String userId) { + this.userId = userId; + } + +} \ No newline at end of file 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 7b5546f6a8..f3559c0153 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 @@ -46,6 +46,20 @@ module.config([ '$routeProvider', function($routeProvider) { } }, controller : 'ApplicationListCtrl' + }).when('/create/user/:realm', { + templateUrl : 'partials/user-detail.html', + resolve : { + realms : function(RealmListLoader) { + return RealmListLoader(); + }, + realm : function(RealmLoader) { + return RealmLoader(); + }, + user : function(UserLoader) { + return {}; + } + }, + controller : 'UserDetailCtrl' }).when('/realms/:realm/users/:user', { templateUrl : 'partials/user-detail.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 a18d6e3c99..a90d3bb8c8 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 @@ -215,13 +215,14 @@ module.controller('UserDetailCtrl', function($scope, realms, realm, user, User, $scope.save = function() { if ($scope.userForm.$valid) { User.save({ - realmKey : realm.key + realm : realm.id, + id : $scope.user.userId }, $scope.user, function() { $scope.changed = false; user = angular.copy($scope.user); if ($scope.create) { - $location.url("/realms/" + realm.key + "/users/" + user.userId); + $location.url("/realms/" + realm.id + "/users/" + $scope.user.userId); Notifications.success("Created user"); } else { Notifications.success("Saved changes to user"); @@ -239,16 +240,16 @@ module.controller('UserDetailCtrl', function($scope, realms, realm, user, User, }; $scope.cancel = function() { - $location.url("/realms/" + realm.key + "/users"); + $location.url("/realms/" + realm.id + "/users"); }; $scope.remove = function() { Dialog.confirmDelete($scope.user.userId, 'user', function() { $scope.user.$remove({ - realmKey : realm.key, - userId : $scope.user.userId + realm : realm.id, + id : $scope.user.userId }, function() { - $location.url("/realms/" + realm.key + "/users"); + $location.url("/realms/" + realm.id + "/users"); Notifications.success("Deleted user"); }); }); diff --git a/ui/src/main/resources/META-INF/resources/ui/js/services.js b/ui/src/main/resources/META-INF/resources/ui/js/services.js index e39d0b4513..f8d46c2085 100644 --- a/ui/src/main/resources/META-INF/resources/ui/js/services.js +++ b/ui/src/main/resources/META-INF/resources/ui/js/services.js @@ -20,14 +20,14 @@ module.factory('Notifications', function($rootScope, $timeout) { if (!$rootScope.notifications) { $rootScope.notifications = []; } - + notifications.message = function(type, message) { $rootScope.notification = { - type : type, - message : message - }; + type : type, + message : message + }; - schedulePop(); + schedulePop(); } notifications.info = function(message) { @@ -140,7 +140,7 @@ module.factory('RealmLoader', function(Realm, $route, $q) { }); module.factory('User', function($resource) { - return $resource('/ejs-identity/api/im/:realm/users/:id', { + return $resource('/keycloak-server/ui/api/realms/:realm/users/:id', { realm : '@realm', id : '@id' }, { @@ -154,7 +154,7 @@ module.factory('UserListLoader', function(User, $route, $q) { return function() { var delay = $q.defer(); User.query({ - realmKey : $route.current.params.realmKey + realm : $route.current.params.realm }, function(users) { delay.resolve(users); }, function() { @@ -166,21 +166,17 @@ module.factory('UserListLoader', function(User, $route, $q) { module.factory('UserLoader', function(User, $route, $q) { return function() { - var name = $route.current.params.user; - if (name == 'new') { - return {}; - } else { - var delay = $q.defer(); - User.get({ - realm : $route.current.params.realm, - name : name - }, function(user) { - delay.resolve(user); - }, function() { - delay.reject('Unable to fetch user ' + name); - }); - return delay.promise; - } + var id = $route.current.params.user; + var delay = $q.defer(); + User.get({ + realm : $route.current.params.realm, + id : id + }, function(user) { + delay.resolve(user); + }, function() { + delay.reject('Unable to fetch user ' + name); + }); + return delay.promise; }; }); diff --git a/ui/src/main/resources/META-INF/resources/ui/partials/user-detail.html b/ui/src/main/resources/META-INF/resources/ui/partials/user-detail.html index 742711526a..8591a8b655 100644 --- a/ui/src/main/resources/META-INF/resources/ui/partials/user-detail.html +++ b/ui/src/main/resources/META-INF/resources/ui/partials/user-detail.html @@ -77,7 +77,7 @@
- View users » + View users »
diff --git a/ui/src/main/resources/META-INF/resources/ui/partials/user-list.html b/ui/src/main/resources/META-INF/resources/ui/partials/user-list.html index 0b31608f62..d5aec2cd55 100644 --- a/ui/src/main/resources/META-INF/resources/ui/partials/user-list.html +++ b/ui/src/main/resources/META-INF/resources/ui/partials/user-list.html @@ -4,7 +4,7 @@
- Add User + Add User

{{realm.name}} users @@ -20,7 +20,7 @@ - {{user.userId}} + {{user.userId}} {{user.firstName}} {{user.lastName}} {{user.email}}