NPE in create user
This commit is contained in:
parent
7fff2588b2
commit
08769a2daa
1 changed files with 16 additions and 13 deletions
|
@ -10,13 +10,15 @@ import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.RoleModel;
|
import org.keycloak.models.RoleModel;
|
||||||
import org.keycloak.models.UserCredentialModel;
|
import org.keycloak.models.UserCredentialModel;
|
||||||
import org.keycloak.models.UserModel;
|
import org.keycloak.models.UserModel;
|
||||||
import org.keycloak.representations.adapters.action.SessionStats;
|
|
||||||
import org.keycloak.representations.adapters.action.UserStats;
|
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.EmailException;
|
||||||
import org.keycloak.services.email.EmailSender;
|
import org.keycloak.services.email.EmailSender;
|
||||||
import org.keycloak.services.managers.AccessCodeEntry;
|
import org.keycloak.services.managers.AccessCodeEntry;
|
||||||
import org.keycloak.services.managers.Auth;
|
|
||||||
import org.keycloak.services.managers.ModelToRepresentation;
|
import org.keycloak.services.managers.ModelToRepresentation;
|
||||||
import org.keycloak.services.managers.RealmManager;
|
import org.keycloak.services.managers.RealmManager;
|
||||||
import org.keycloak.services.managers.ResourceAdminManager;
|
import org.keycloak.services.managers.ResourceAdminManager;
|
||||||
|
@ -108,7 +110,7 @@ public class UsersResource {
|
||||||
return Response.created(uriInfo.getAbsolutePathBuilder().path(user.getLoginName()).build()).build();
|
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.setEmail(rep.getEmail());
|
||||||
user.setFirstName(rep.getFirstName());
|
user.setFirstName(rep.getFirstName());
|
||||||
user.setLastName(rep.getLastName());
|
user.setLastName(rep.getLastName());
|
||||||
|
@ -119,13 +121,15 @@ public class UsersResource {
|
||||||
|
|
||||||
List<String> reqActions = rep.getRequiredActions();
|
List<String> reqActions = rep.getRequiredActions();
|
||||||
|
|
||||||
for(UserModel.RequiredAction ra : UserModel.RequiredAction.values()){
|
if (reqActions != null) {
|
||||||
|
for (UserModel.RequiredAction ra : UserModel.RequiredAction.values()) {
|
||||||
if (reqActions.contains(ra.name())) {
|
if (reqActions.contains(ra.name())) {
|
||||||
user.addRequiredAction(ra);
|
user.addRequiredAction(ra);
|
||||||
} else {
|
} else {
|
||||||
user.removeRequiredAction(ra);
|
user.removeRequiredAction(ra);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (rep.getAttributes() != null) {
|
if (rep.getAttributes() != null) {
|
||||||
for (Map.Entry<String, String> attr : rep.getAttributes().entrySet()) {
|
for (Map.Entry<String, String> attr : rep.getAttributes().entrySet()) {
|
||||||
|
@ -152,7 +156,7 @@ public class UsersResource {
|
||||||
@GET
|
@GET
|
||||||
@NoCache
|
@NoCache
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Map<String,UserStats> getSessionStats(final @PathParam("username") String username) {
|
public Map<String, UserStats> getSessionStats(final @PathParam("username") String username) {
|
||||||
logger.info("session-stats");
|
logger.info("session-stats");
|
||||||
auth.requireView();
|
auth.requireView();
|
||||||
UserModel user = realm.getUser(username);
|
UserModel user = realm.getUser(username);
|
||||||
|
@ -177,12 +181,11 @@ public class UsersResource {
|
||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
// set notBefore so that user will be forced to log in.
|
// 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);
|
new ResourceAdminManager().logoutUser(realm, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Path("{username}")
|
@Path("{username}")
|
||||||
@DELETE
|
@DELETE
|
||||||
@NoCache
|
@NoCache
|
||||||
|
@ -431,7 +434,7 @@ public class UsersResource {
|
||||||
Set<RoleModel> roleModels = application.getApplicationRoleMappings(user);
|
Set<RoleModel> roleModels = application.getApplicationRoleMappings(user);
|
||||||
for (RoleModel roleModel : roleModels) {
|
for (RoleModel roleModel : roleModels) {
|
||||||
if (!(roleModel.getContainer() instanceof ApplicationModel)) {
|
if (!(roleModel.getContainer() instanceof ApplicationModel)) {
|
||||||
ApplicationModel app = (ApplicationModel)roleModel.getContainer();
|
ApplicationModel app = (ApplicationModel) roleModel.getContainer();
|
||||||
if (!app.getId().equals(application.getId())) continue;
|
if (!app.getId().equals(application.getId())) continue;
|
||||||
}
|
}
|
||||||
realm.deleteRoleMapping(user, roleModel);
|
realm.deleteRoleMapping(user, roleModel);
|
||||||
|
|
Loading…
Reference in a new issue