[Minor] Persist roles and users after changes

This commit is contained in:
Robert von Burg 2018-03-20 14:30:12 +01:00
parent 6faebf278d
commit 9ccaf5392a
13 changed files with 88 additions and 63 deletions

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -49,11 +49,13 @@ public class PrivilegeAddOrReplacePrivilegeOnRoleService
PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler();
RoleRep role = privilegeHandler.addOrReplacePrivilegeOnRole(getCertificate(), arg.roleName, arg.privilegeRep);
privilegeHandler.persist(getCertificate());
try (StrolchTransaction tx = openArgOrUserTx(arg, PrivilegeHandler.PRIVILEGE_MODIFY_ROLE)) {
tx.setSuppressAudits(true);
Audit audit = tx.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.ROLE, role.getName());
Audit audit = tx
.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.ROLE,
role.getName());
tx.getAuditTrail().add(tx, audit);
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -47,11 +47,13 @@ public class PrivilegeAddRoleService extends AbstractService<PrivilegeRoleArgume
PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler();
RoleRep role = privilegeHandler.addRole(getCertificate(), arg.role);
privilegeHandler.persist(getCertificate());
try (StrolchTransaction tx = openArgOrUserTx(arg, PrivilegeHandler.PRIVILEGE_ADD_ROLE)) {
tx.setSuppressAudits(true);
Audit audit = tx.auditFrom(AccessType.CREATE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.ROLE, role.getName());
Audit audit = tx
.auditFrom(AccessType.CREATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.ROLE,
role.getName());
tx.getAuditTrail().add(tx, audit);
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -49,11 +49,13 @@ public class PrivilegeRemovePrivilegeFromRoleService
PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler();
RoleRep role = privilegeHandler.removePrivilegeFromRole(getCertificate(), arg.roleName, arg.privilegeName);
privilegeHandler.persist(getCertificate());
try (StrolchTransaction tx = openArgOrUserTx(arg, StrolchPrivilegeConstants.PRIVILEGE_MODIFY_ROLE)) {
tx.setSuppressAudits(true);
Audit audit = tx.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.ROLE, role.getName());
Audit audit = tx
.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.ROLE,
role.getName());
tx.getAuditTrail().add(tx, audit);
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -48,11 +48,13 @@ public class PrivilegeRemoveRoleService extends AbstractService<PrivilegeRoleNam
PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler();
RoleRep role = privilegeHandler.removeRole(getCertificate(), arg.roleName);
privilegeHandler.persist(getCertificate());
try (StrolchTransaction tx = openArgOrUserTx(arg, PrivilegeHandler.PRIVILEGE_REMOVE_ROLE)) {
tx.setSuppressAudits(true);
Audit audit = tx.auditFrom(AccessType.DELETE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.ROLE, role.getName());
Audit audit = tx
.auditFrom(AccessType.DELETE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.ROLE,
role.getName());
tx.getAuditTrail().add(tx, audit);
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -48,11 +48,13 @@ public class PrivilegeUpdateRoleService extends AbstractService<PrivilegeRoleArg
PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler();
RoleRep role = privilegeHandler.replaceRole(getCertificate(), arg.role);
privilegeHandler.persist(getCertificate());
try (StrolchTransaction tx = openArgOrUserTx(arg, PrivilegeHandler.PRIVILEGE_MODIFY_ROLE)) {
tx.setSuppressAudits(true);
Audit audit = tx.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.ROLE, role.getName());
Audit audit = tx
.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.ROLE,
role.getName());
tx.getAuditTrail().add(tx, audit);
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -49,11 +49,13 @@ public class PrivilegeAddRoleToUserService
PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler();
UserRep user = privilegeHandler.addRoleToUser(getCertificate(), arg.username, arg.rolename);
privilegeHandler.persist(getCertificate());
try (StrolchTransaction tx = openArgOrUserTx(arg, PrivilegeHandler.PRIVILEGE_ADD_ROLE_TO_USER)) {
tx.setSuppressAudits(true);
Audit audit = tx.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.USER, user.getUsername());
Audit audit = tx
.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.USER,
user.getUsername());
tx.getAuditTrail().add(tx, audit);
}

View File

@ -11,7 +11,6 @@ import li.strolch.service.api.Command;
import li.strolch.utils.dbc.DBC;
/**
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class PrivilegeAddUserCommand extends Command {
@ -48,11 +47,13 @@ public class PrivilegeAddUserCommand extends Command {
PrivilegeHandler privilegeHandler = getContainer().getPrivilegeHandler().getPrivilegeHandler();
this.userOut = privilegeHandler.addUser(tx().getCertificate(), this.userIn, null);
privilegeHandler.persist(tx().getCertificate());
tx().setSuppressAuditsForAudits(true);
this.audit = tx().auditFrom(AccessType.CREATE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.USER, this.userOut.getUsername());
this.audit = tx()
.auditFrom(AccessType.CREATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.USER,
this.userOut.getUsername());
tx().getAuditTrail().add(tx(), this.audit);
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -48,11 +48,13 @@ public class PrivilegeRemoveRoleFromUserService
PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler();
UserRep user = privilegeHandler.removeRoleFromUser(getCertificate(), arg.username, arg.rolename);
privilegeHandler.persist(getCertificate());
try (StrolchTransaction tx = openArgOrUserTx(arg, PrivilegeHandler.PRIVILEGE_REMOVE_ROLE_FROM_USER)) {
tx.setSuppressAudits(true);
Audit audit = tx.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.USER, user.getUsername());
Audit audit = tx
.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.USER,
user.getUsername());
tx.getAuditTrail().add(tx, audit);
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -48,11 +48,13 @@ public class PrivilegeRemoveUserService extends AbstractService<PrivilegeUserNam
PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler();
UserRep user = privilegeHandler.removeUser(getCertificate(), arg.username);
privilegeHandler.persist(getCertificate());
try (StrolchTransaction tx = openArgOrUserTx(arg, PrivilegeHandler.PRIVILEGE_REMOVE_USER)) {
tx.setSuppressAudits(true);
Audit audit = tx.auditFrom(AccessType.DELETE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.USER, user.getUsername());
Audit audit = tx
.auditFrom(AccessType.DELETE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.USER,
user.getUsername());
tx.getAuditTrail().add(tx, audit);
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -49,11 +49,13 @@ public class PrivilegeSetUserLocaleService
PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler();
UserRep user = privilegeHandler.setUserLocale(getCertificate(), arg.username, arg.locale);
privilegeHandler.persist(getCertificate());
try (StrolchTransaction tx = openArgOrUserTx(arg, PrivilegeHandler.PRIVILEGE_SET_USER_LOCALE)) {
tx.setSuppressAudits(true);
Audit audit = tx.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.USER, user.getUsername());
Audit audit = tx
.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.USER,
user.getUsername());
tx.getAuditTrail().add(tx, audit);
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -48,11 +48,13 @@ public class PrivilegeSetUserPasswordService extends AbstractService<PrivilegeSe
PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler();
privilegeHandler.setUserPassword(getCertificate(), arg.username, arg.password);
privilegeHandler.persist(getCertificate());
try (StrolchTransaction tx = openArgOrUserTx(arg, PrivilegeHandler.PRIVILEGE_SET_USER_PASSWORD)) {
tx.setSuppressAudits(true);
Audit audit = tx.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.USER, arg.username);
Audit audit = tx
.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.USER,
arg.username);
tx.getAuditTrail().add(tx, audit);
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -48,11 +48,13 @@ public class PrivilegeSetUserStateService extends AbstractService<PrivilegeSetUs
PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler();
UserRep user = privilegeHandler.setUserState(getCertificate(), arg.username, arg.userState);
privilegeHandler.persist(getCertificate());
try (StrolchTransaction tx = openArgOrUserTx(arg, PrivilegeHandler.PRIVILEGE_SET_USER_STATE)) {
tx.setSuppressAudits(true);
Audit audit = tx.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.USER, user.getUsername());
Audit audit = tx
.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.USER,
user.getUsername());
tx.getAuditTrail().add(tx, audit);
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -48,11 +48,13 @@ public class PrivilegeUpdateUserService extends AbstractService<PrivilegeUserArg
PrivilegeHandler privilegeHandler = strolchPrivilegeHandler.getPrivilegeHandler();
UserRep user = privilegeHandler.updateUser(getCertificate(), arg.user);
privilegeHandler.persist(getCertificate());
try (StrolchTransaction tx = openArgOrUserTx(arg, PrivilegeHandler.PRIVILEGE_MODIFY_USER)) {
tx.setSuppressAudits(true);
Audit audit = tx.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE,
StrolchPrivilegeConstants.USER, user.getUsername());
Audit audit = tx
.auditFrom(AccessType.UPDATE, StrolchPrivilegeConstants.PRIVILEGE, StrolchPrivilegeConstants.USER,
user.getUsername());
tx.getAuditTrail().add(tx, audit);
}