[New] implemented auto persist on password change

Through configuration option it is now possible to enable automatic
persisting after password change, no matter who the user is.
This commit is contained in:
Robert von Burg 2012-12-01 00:06:54 +01:00
parent f73d829822
commit 28a60b52f7
2 changed files with 28 additions and 1 deletions

View File

@ -28,6 +28,7 @@ along with Privilege. If not, see <http://www.gnu.org/licenses/>.
<Parameters>
<!-- parameters for the container itself -->
<Parameter name="autoPersistOnPasswordChange" value="true" />
</Parameters>
<EncryptionHandler class="ch.eitchnet.privilege.handler.DefaultEncryptionHandler">
@ -38,7 +39,7 @@ along with Privilege. If not, see <http://www.gnu.org/licenses/>.
<PersistenceHandler class="ch.eitchnet.privilege.handler.XmlPersistenceHandler">
<Parameters>
<Parameter name="basePath" value="./config" />
<Parameter name="basePath" value="./target/test" />
<Parameter name="modelXmlFile" value="PrivilegeModel.xml" />
</Parameters>
</PersistenceHandler>

View File

@ -67,6 +67,11 @@ import ch.eitchnet.privilege.policy.PrivilegePolicy;
*/
public class DefaultPrivilegeHandler implements PrivilegeHandler {
/**
* configuration parameter to define automatic persisting on password change
*/
private static final String PARAM_AUTO_PERSIST_ON_PASSWORD_CHANGE = "autoPersistOnPasswordChange";
/**
* log4j logger
*/
@ -107,6 +112,11 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
*/
private boolean initialized;
/**
* flag to define if a persist should be performed after a user changes their password
*/
private boolean autoPersistOnPasswordChange;
/**
* @see ch.eitchnet.privilege.handler.PrivilegeHandler#getRole(java.lang.String)
*/
@ -624,6 +634,11 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
// delegate user replacement to persistence handler
this.persistenceHandler.addOrReplaceUser(newUser);
// perform automatic persisting, if enabled
if (this.autoPersistOnPasswordChange) {
this.persistenceHandler.persist();
}
} finally {
clearPassword(password);
}
@ -997,6 +1012,17 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
this.encryptionHandler = encryptionHandler;
this.persistenceHandler = persistenceHandler;
String autoPersistS = parameterMap.get(PARAM_AUTO_PERSIST_ON_PASSWORD_CHANGE);
if (autoPersistS == null || autoPersistS.equals(Boolean.FALSE.toString())) {
this.autoPersistOnPasswordChange = false;
} else if (autoPersistS.equals(Boolean.TRUE.toString())) {
this.autoPersistOnPasswordChange = true;
logger.info("Enabling automatic persistence on password change.");
} else {
logger.error("Parameter " + PARAM_AUTO_PERSIST_ON_PASSWORD_CHANGE + " has illegal value " + autoPersistS
+ ". Overriding with " + Boolean.FALSE.toString());
}
// validate policies on privileges of Roles
for (Role role : persistenceHandler.getAllRoles()) {
validatePolicies(role);