Source:
public Response createUser(final UserRepresentation rep) { auth.users().requireManage(); String username = rep.getUsername(); if (username == null || username.length() == 0) { return ErrorResponse.error("User name is missing", Response.Status.BAD_REQUEST); } if (session.users().getUserByUsername(username, realm) != null) { return ErrorResponse.exists("User exists with same username"); } if (rep.getEmail() != null && !realm.isDuplicateEmailsAllowed() && session.users().getUserByEmail(rep.getEmail(), realm) != null) { return ErrorResponse.exists("User exists with same email"); } try { UserModel user = session.users().addUser(realm, username); Set<String> emptySet = Collections.emptySet(); UserResource.updateUserFromRep(user, rep, emptySet, realm, session, false); RepresentationToModel.createCredentials(rep, session, realm, user, true); adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri(), user.getId()).representation(rep).success(); if (session.getTransactionManager().isActive()) { session.getTransactionManager().commit(); } return Response.created(session.getContext().getUri().getAbsolutePathBuilder().path(user.getId()).build()).build(); } catch (ModelDuplicateException e) { if (session.getTransactionManager().isActive()) { session.getTransactionManager().setRollbackOnly(); } return ErrorResponse.exists("User exists with same username or email"); } catch (PasswordPolicyNotMetException e) { if (session.getTransactionManager().isActive()) { session.getTransactionManager().setRollbackOnly(); } return ErrorResponse.error("Password policy not met for user " + username, Response.Status.BAD_REQUEST); } catch (ModelException me){ if (session.getTransactionManager().isActive()) { session.getTransactionManager().setRollbackOnly(); } logger.warn("Could not create user", me); return ErrorResponse.error("Could not create user", Response.Status.INTERNAL_SERVER_ERROR); } }

Target:
public Response createUser(final UserRepresentation rep) { auth.users().requireManage(); String username = rep.getUsername(); if (ObjectUtil.isBlank(username)) { return ErrorResponse.error("User name is missing", Response.Status.BAD_REQUEST); } if (session.users().getUserByUsername(username, realm) != null) { return ErrorResponse.exists("User exists with same username"); } if (rep.getEmail() != null && !realm.isDuplicateEmailsAllowed() && session.users().getUserByEmail(rep.getEmail(), realm) != null) { return ErrorResponse.exists("User exists with same email"); } try { UserModel user = session.users().addUser(realm, username); Set<String> emptySet = Collections.emptySet(); UserResource.updateUserFromRep(user, rep, emptySet, realm, session, false); RepresentationToModel.createCredentials(rep, session, realm, user, true); adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri(), user.getId()).representation(rep).success(); if (session.getTransactionManager().isActive()) { session.getTransactionManager().commit(); } return Response.created(session.getContext().getUri().getAbsolutePathBuilder().path(user.getId()).build()).build(); } catch (ModelDuplicateException e) { if (session.getTransactionManager().isActive()) { session.getTransactionManager().setRollbackOnly(); } return ErrorResponse.exists("User exists with same username or email"); } catch (PasswordPolicyNotMetException e) { if (session.getTransactionManager().isActive()) { session.getTransactionManager().setRollbackOnly(); } return ErrorResponse.error("Password policy not met", Response.Status.BAD_REQUEST); } catch (ModelException me){ if (session.getTransactionManager().isActive()) { session.getTransactionManager().setRollbackOnly(); } logger.warn("Could not create user", me); return ErrorResponse.error("Could not create user", Response.Status.BAD_REQUEST); } }