From 08769a2daa9b0ecd860bce754c8f38d36ed69cb9 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Thu, 13 Mar 2014 10:56:09 -0400 Subject: [PATCH] NPE in create user --- .../resources/admin/UsersResource.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java b/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java index 8aac6918cb..c548c78b76 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java @@ -10,13 +10,15 @@ import org.keycloak.models.RealmModel; import org.keycloak.models.RoleModel; import org.keycloak.models.UserCredentialModel; import org.keycloak.models.UserModel; -import org.keycloak.representations.adapters.action.SessionStats; import org.keycloak.representations.adapters.action.UserStats; -import org.keycloak.representations.idm.*; +import org.keycloak.representations.idm.ApplicationMappingsRepresentation; +import org.keycloak.representations.idm.CredentialRepresentation; +import org.keycloak.representations.idm.MappingsRepresentation; +import org.keycloak.representations.idm.RoleRepresentation; +import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.services.email.EmailException; import org.keycloak.services.email.EmailSender; import org.keycloak.services.managers.AccessCodeEntry; -import org.keycloak.services.managers.Auth; import org.keycloak.services.managers.ModelToRepresentation; import org.keycloak.services.managers.RealmManager; import org.keycloak.services.managers.ResourceAdminManager; @@ -108,7 +110,7 @@ public class UsersResource { return Response.created(uriInfo.getAbsolutePathBuilder().path(user.getLoginName()).build()).build(); } - private void updateUserFromRep(UserModel user, UserRepresentation rep){ + private void updateUserFromRep(UserModel user, UserRepresentation rep) { user.setEmail(rep.getEmail()); user.setFirstName(rep.getFirstName()); user.setLastName(rep.getLastName()); @@ -119,11 +121,13 @@ public class UsersResource { List reqActions = rep.getRequiredActions(); - for(UserModel.RequiredAction ra : UserModel.RequiredAction.values()){ - if (reqActions.contains(ra.name())) { - user.addRequiredAction(ra); - } else { - user.removeRequiredAction(ra); + if (reqActions != null) { + for (UserModel.RequiredAction ra : UserModel.RequiredAction.values()) { + if (reqActions.contains(ra.name())) { + user.addRequiredAction(ra); + } else { + user.removeRequiredAction(ra); + } } } @@ -152,7 +156,7 @@ public class UsersResource { @GET @NoCache @Produces(MediaType.APPLICATION_JSON) - public Map getSessionStats(final @PathParam("username") String username) { + public Map getSessionStats(final @PathParam("username") String username) { logger.info("session-stats"); auth.requireView(); UserModel user = realm.getUser(username); @@ -177,12 +181,11 @@ public class UsersResource { throw new NotFoundException(); } // set notBefore so that user will be forced to log in. - user.setNotBefore((int)(System.currentTimeMillis()/1000)); + user.setNotBefore((int) (System.currentTimeMillis() / 1000)); new ResourceAdminManager().logoutUser(realm, user); } - @Path("{username}") @DELETE @NoCache @@ -431,7 +434,7 @@ public class UsersResource { Set roleModels = application.getApplicationRoleMappings(user); for (RoleModel roleModel : roleModels) { if (!(roleModel.getContainer() instanceof ApplicationModel)) { - ApplicationModel app = (ApplicationModel)roleModel.getContainer(); + ApplicationModel app = (ApplicationModel) roleModel.getContainer(); if (!app.getId().equals(application.getId())) continue; } realm.deleteRoleMapping(user, roleModel);