diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/PrivilegeUsersService.java b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/PrivilegeUsersService.java index 3081c1592..67d9eafae 100644 --- a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/PrivilegeUsersService.java +++ b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/PrivilegeUsersService.java @@ -17,6 +17,7 @@ package li.strolch.rest.endpoint; import static java.util.Comparator.comparing; import static li.strolch.privilege.handler.PrivilegeHandler.PRIVILEGE_GET_USER; +import static li.strolch.rest.helper.ResponseUtil.toResponse; import static li.strolch.rest.helper.RestfulHelper.toJson; import static li.strolch.search.SearchBuilder.buildSimpleValueSearch; @@ -44,7 +45,6 @@ import li.strolch.privilege.model.UserState; import li.strolch.rest.RestfulStrolchComponent; import li.strolch.rest.StrolchRestfulConstants; import li.strolch.rest.StrolchSessionHandler; -import li.strolch.rest.helper.ResponseUtil; import li.strolch.rest.model.QueryData; import li.strolch.search.SearchResult; import li.strolch.search.ValueSearch; @@ -168,8 +168,8 @@ public class PrivilegeUsersService { PrivilegeUserNameArgument arg = new PrivilegeUserNameArgument(); arg.username = username; - PrivilegeUserResult svcResult = svcHandler.doService(cert, svc, arg); - return handleServiceResult(svcResult); + ServiceResult svcResult = svcHandler.doService(cert, svc, arg); + return toResponse(svcResult); } @PUT @@ -255,7 +255,7 @@ public class PrivilegeUsersService { userState = UserState.valueOf(state); } catch (Exception e) { String msg = MessageFormat.format("UserState {0} is not valid!", state); - return ResponseUtil.toResponse(msg); + return toResponse(msg); } ServiceHandler svcHandler = RestfulStrolchComponent.getInstance().getComponent(ServiceHandler.class); @@ -280,7 +280,7 @@ public class PrivilegeUsersService { locale = new Locale(localeS); } catch (Exception e) { String msg = MessageFormat.format("Locale {0} is not valid!", localeS); - return ResponseUtil.toResponse(msg); + return toResponse(msg); } ServiceHandler svcHandler = RestfulStrolchComponent.getInstance().getComponent(ServiceHandler.class); @@ -313,7 +313,7 @@ public class PrivilegeUsersService { ServiceResult svcResult = svcHandler.doService(cert, svc, arg); if (svcResult.isNok()) - return ResponseUtil.toResponse(svcResult); + return toResponse(svcResult); // if user changes their own password, then invalidate the session if (cert.getUsername().equals(username)) { @@ -321,7 +321,7 @@ public class PrivilegeUsersService { sessionHandler.invalidate(cert); } - return ResponseUtil.toResponse(); + return toResponse(); } @PUT @@ -339,7 +339,7 @@ public class PrivilegeUsersService { arg.map.put(Tags.Json.STATE, jsonObject.get(Tags.Json.STATE).getAsString()); ServiceResult svcResult = svcHandler.doService(cert, svc, arg); - return ResponseUtil.toResponse(svcResult); + return toResponse(svcResult); } @DELETE @@ -353,16 +353,15 @@ public class PrivilegeUsersService { arg.username = username; ServiceResult svcResult = svcHandler.doService(cert, svc, arg); - return ResponseUtil.toResponse(svcResult); + return toResponse(svcResult); } private Response handleServiceResult(PrivilegeUserResult svcResult) { if (svcResult.isOk()) { UserRep userRep = svcResult.getUser(); - return Response - .ok(userRep.accept(new PrivilegeElementToJsonVisitor()).toString(), MediaType.APPLICATION_JSON) - .build(); + return Response.ok(userRep.accept(new PrivilegeElementToJsonVisitor()).toString(), + MediaType.APPLICATION_JSON).build(); } - return ResponseUtil.toResponse(svcResult); + return toResponse(svcResult); } } \ No newline at end of file diff --git a/li.strolch.service/src/main/java/li/strolch/service/privilege/users/PrivilegeRemoveUserCommand.java b/li.strolch.service/src/main/java/li/strolch/service/privilege/users/PrivilegeRemoveUserCommand.java new file mode 100644 index 000000000..e3b0ca996 --- /dev/null +++ b/li.strolch.service/src/main/java/li/strolch/service/privilege/users/PrivilegeRemoveUserCommand.java @@ -0,0 +1,42 @@ +package li.strolch.service.privilege.users; + +import static li.strolch.runtime.StrolchConstants.StrolchPrivilegeConstants.PRIVILEGE; +import static li.strolch.runtime.StrolchConstants.StrolchPrivilegeConstants.USER; + +import li.strolch.model.audit.AccessType; +import li.strolch.model.audit.Audit; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.privilege.handler.PrivilegeHandler; +import li.strolch.service.api.Command; +import li.strolch.utils.dbc.DBC; + +public class PrivilegeRemoveUserCommand extends Command { + + private String username; + + public PrivilegeRemoveUserCommand(StrolchTransaction tx) { + super(tx); + } + + public void setUsername(String username) { + this.username = username; + } + + @Override + public void validate() { + DBC.PRE.assertNotEmpty("username must be set", this.username); + } + + @Override + public void doCommand() { + + li.strolch.runtime.privilege.PrivilegeHandler strolchPrivilegeHandler = getContainer().getPrivilegeHandler(); + PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler(); + + privilegeHandler.removeUser(tx().getCertificate(), this.username); + privilegeHandler.persist(tx().getCertificate()); + + Audit audit = tx().auditFrom(AccessType.DELETE, PRIVILEGE, USER, this.username); + tx().getAuditTrail().add(tx(), audit); + } +} diff --git a/li.strolch.service/src/main/java/li/strolch/service/privilege/users/PrivilegeRemoveUserService.java b/li.strolch.service/src/main/java/li/strolch/service/privilege/users/PrivilegeRemoveUserService.java index 6ba10113e..1f03d554a 100644 --- a/li.strolch.service/src/main/java/li/strolch/service/privilege/users/PrivilegeRemoveUserService.java +++ b/li.strolch.service/src/main/java/li/strolch/service/privilege/users/PrivilegeRemoveUserService.java @@ -15,23 +15,20 @@ */ package li.strolch.service.privilege.users; -import li.strolch.model.audit.AccessType; -import li.strolch.model.audit.Audit; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.privilege.handler.PrivilegeHandler; -import li.strolch.privilege.model.UserRep; -import li.strolch.runtime.StrolchConstants.StrolchPrivilegeConstants; import li.strolch.service.api.AbstractService; +import li.strolch.service.api.ServiceResult; import li.strolch.service.api.ServiceResultState; /** * @author Robert von Burg */ -public class PrivilegeRemoveUserService extends AbstractService { +public class PrivilegeRemoveUserService extends AbstractService { @Override - protected PrivilegeUserResult getResultInstance() { - return new PrivilegeUserResult(ServiceResultState.FAILED); + protected ServiceResult getResultInstance() { + return new ServiceResult(ServiceResultState.FAILED); } @Override @@ -40,24 +37,18 @@ public class PrivilegeRemoveUserService extends AbstractService