[New] Added new PrivilegeAddUserAndSetPasswordCommand
This commit is contained in:
parent
872f3244ef
commit
cdfa57d1d8
|
@ -0,0 +1,32 @@
|
||||||
|
package li.strolch.service.privilege.users;
|
||||||
|
|
||||||
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import li.strolch.privilege.handler.PrivilegeHandler;
|
||||||
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
||||||
|
public class PrivilegeAddUserAndSetPasswordCommand extends PrivilegeAddUserCommand {
|
||||||
|
|
||||||
|
private char[] password;
|
||||||
|
|
||||||
|
public PrivilegeAddUserAndSetPasswordCommand(StrolchTransaction tx) {
|
||||||
|
super(tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(char[] password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() {
|
||||||
|
super.validate();
|
||||||
|
DBC.PRE.assertNotNull("password may not be null!", this.password);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doCommand() {
|
||||||
|
PrivilegeHandler privilegeHandler = getContainer().getPrivilegeHandler().getPrivilegeHandler();
|
||||||
|
this.userOut = privilegeHandler.addUser(this.cert, this.userIn, this.password);
|
||||||
|
privilegeHandler.persist(this.cert);
|
||||||
|
writeAudit();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package li.strolch.service.privilege.users;
|
package li.strolch.service.privilege.users;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
|
||||||
import li.strolch.model.audit.AccessType;
|
import li.strolch.model.audit.AccessType;
|
||||||
import li.strolch.model.audit.Audit;
|
import li.strolch.model.audit.Audit;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
@ -17,17 +16,17 @@ import li.strolch.utils.dbc.DBC;
|
||||||
public class PrivilegeAddUserCommand extends Command {
|
public class PrivilegeAddUserCommand extends Command {
|
||||||
|
|
||||||
// input
|
// input
|
||||||
private UserRep userIn;
|
protected UserRep userIn;
|
||||||
private Certificate cert;
|
protected Certificate cert;
|
||||||
|
|
||||||
// intermediary
|
// intermediary
|
||||||
private Audit audit;
|
protected Audit audit;
|
||||||
|
|
||||||
// output
|
// output
|
||||||
private UserRep userOut;
|
protected UserRep userOut;
|
||||||
|
|
||||||
public PrivilegeAddUserCommand(ComponentContainer container, StrolchTransaction tx) {
|
public PrivilegeAddUserCommand(StrolchTransaction tx) {
|
||||||
super(container, tx);
|
super(tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserIn(UserRep userIn) {
|
public void setUserIn(UserRep userIn) {
|
||||||
|
@ -51,14 +50,14 @@ public class PrivilegeAddUserCommand extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doCommand() {
|
public void doCommand() {
|
||||||
|
|
||||||
PrivilegeHandler privilegeHandler = getContainer().getPrivilegeHandler().getPrivilegeHandler();
|
PrivilegeHandler privilegeHandler = getContainer().getPrivilegeHandler().getPrivilegeHandler();
|
||||||
|
|
||||||
this.userOut = privilegeHandler.addUser(this.cert, this.userIn, null);
|
this.userOut = privilegeHandler.addUser(this.cert, this.userIn, null);
|
||||||
privilegeHandler.persist(this.cert);
|
privilegeHandler.persist(this.cert);
|
||||||
|
writeAudit();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void writeAudit() {
|
||||||
tx().setSuppressAuditsForAudits(true);
|
tx().setSuppressAuditsForAudits(true);
|
||||||
|
|
||||||
this.audit = tx()
|
this.audit = tx()
|
||||||
.auditFrom(AccessType.CREATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.USER,
|
.auditFrom(AccessType.CREATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.USER,
|
||||||
this.userOut.getUsername());
|
this.userOut.getUsername());
|
||||||
|
@ -67,7 +66,6 @@ public class PrivilegeAddUserCommand extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undo() {
|
public void undo() {
|
||||||
|
|
||||||
if (tx().isRollingBack()) {
|
if (tx().isRollingBack()) {
|
||||||
PrivilegeHandler privilegeHandler = getContainer().getPrivilegeHandler().getPrivilegeHandler();
|
PrivilegeHandler privilegeHandler = getContainer().getPrivilegeHandler().getPrivilegeHandler();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue