Remove the warning of the need to change admin password.

FEA : ItEr69S06AutocompleteAndPasswords
This commit is contained in:
Susana Montes Pedreira 2011-01-27 16:13:07 +01:00
parent 4e75b89cd9
commit cb7edc2dfd
9 changed files with 89 additions and 13 deletions

View file

@ -23,10 +23,12 @@ package org.navalplanner.business.common.daos;
import java.util.List;
import org.hibernate.Query;
import org.navalplanner.business.common.entities.Configuration;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
@ -54,4 +56,13 @@ public class ConfigurationDAO extends GenericDAOHibernate<Configuration, Long>
return getConfiguration();
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void saveChangedDefaultAdminPassword(boolean change) {
Query query = getSession()
.createQuery(
"UPDATE Configuration e SET e.changedDefaultAdminPassword = :change");
query.setParameter("change", change);
query.executeUpdate();
}
}

View file

@ -40,4 +40,8 @@ public interface IConfigurationDAO extends IGenericDAO<Configuration, Long> {
*/
Configuration getConfigurationWithReadOnlyTransaction();
/**
* It changes the value in the field changedDefaultAdminPassword.
*/
void saveChangedDefaultAdminPassword(boolean change);
}

View file

@ -47,6 +47,8 @@
column="expand_resource_load_view_charts" />
<property name="monteCarloMethodTabVisible" not-null="true"
column="monte_carlo_method_tab_visible" />
<property name="changedDefaultAdminPassword" not-null="true"
column="changed_default_admin_password" />
<property name="progressType" column="progress_type">
<type name="org.hibernate.type.EnumType">

View file

@ -129,9 +129,9 @@ public class TemplateController extends GenericForwardComposer {
return (templateModel != null) && templateModel.isScenariosVisible();
}
public Boolean getDefaultPasswdVisible() {
return (templateModel != null) && (getIdAdminUser() != null)
&& (!templateModel.isChangedDefaultAdminPassword());
public String getDefaultPasswdVisible() {
return ((templateModel != null) && (getIdAdminUser() != null) && (!templateModel
.isChangedDefaultAdminPassword())) ? "inline" : "none";
}
public String getIdAdminUser() {

View file

@ -120,4 +120,6 @@ public interface IUserModel {
*/
void setPassword(String password);
String getClearNewPassword();
}

View file

@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.navalplanner.business.common.Registry;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.users.daos.IUserDAO;
@ -32,12 +33,14 @@ import org.navalplanner.business.users.entities.Profile;
import org.navalplanner.business.users.entities.User;
import org.navalplanner.business.users.entities.UserRole;
import org.navalplanner.web.common.concurrentdetection.OnConcurrentModification;
import org.navalplanner.web.users.bootstrap.MandatoryUser;
import org.navalplanner.web.users.services.IDBPasswordEncoderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.zkoss.zk.ui.util.Clients;
/**
* Model for UI operations related to {@link User}
@ -73,9 +76,19 @@ public class UserModel implements IUserModel {
//because it must exist to perform the encoding
Validate.notEmpty(user.getLoginName());
if (clearNewPassword != null) {
if (getClearNewPassword() != null) {
/**
* it ckecks if the admin password has changed and if so sets
* true in the field changedDefaultAdminPassword.
*/
if (user.getLoginName().equalsIgnoreCase(
MandatoryUser.ADMIN.getLoginName())) {
checkIfChangeDefaultAdminPasswd();
}
user.setPassword(dbPasswordEncoderService.
encodePassword(clearNewPassword, user.getLoginName()));
encodePassword(getClearNewPassword(), user.getLoginName()));
}
}
catch (IllegalArgumentException e) {}
@ -84,6 +97,25 @@ public class UserModel implements IUserModel {
userDAO.save(user);
}
private void checkIfChangeDefaultAdminPasswd() {
boolean changedPasswd = true;
if (getClearNewPassword().isEmpty()
|| getClearNewPassword().equals(MandatoryUser.ADMIN
.getClearPassword())) {
changedPasswd = false;
}
// save the field changedDefaultAdminPassword in configuration.
Registry.getConfigurationDAO().saveChangedDefaultAdminPassword(
changedPasswd);
// show or hide the warning
if (changedPasswd) {
Clients.evalJavaScript("hideWarningDefaultPasswd();");
} else {
Clients.evalJavaScript("showWarningDefaultPasswd();");
}
}
@Override
public User getUser() {
return user;
@ -176,10 +208,19 @@ public class UserModel implements IUserModel {
//user.getLoginName must exist to do that, and we're
//not sure at this point
if(password != "") {
clearNewPassword = password;
setClearNewPassword(password);
}
else{
clearNewPassword = null;
setClearNewPassword(null);
}
}
public void setClearNewPassword(String clearNewPassword) {
this.clearNewPassword = clearNewPassword;
}
@Override
public String getClearNewPassword() {
return clearNewPassword;
}
}

View file

@ -189,6 +189,6 @@ a.sub_menu:hover {
}
.footer-messages-area {
color: #ffa100;
color: #CC5013;
font-size: 11px;
}

View file

@ -126,11 +126,13 @@
<n:td height="40" align="left" valign="bottom">
<n:img height="40" src="${templateCtrl.companyLogoURL}" if="${templateCtrl.companyLogoURL!=''}" />
</n:td>
<n:td>
<div if="${templateCtrl.defaultPasswdVisible}">
<n:span id="footer-messages-area" class="footer-messages-area">${i18n:_('The admin account default password was not changed')}.</n:span>
<n:a href="${contextPath}/users/users.zul#edit%3D${idAdminUser}" class="footer-messages-area">[${i18n:_('Click here')}]</n:a>
</div>
<n:td valign="center">
<n:div id="warningDefaultPasswd" style="display:${templateCtrl.defaultPasswdVisible}">
<div>
<n:span id="footer-messages-area" class="footer-messages-area">${i18n:_('The admin account default password was not changed')}.</n:span>
<n:a href="${contextPath}/users/users.zul#edit%3D${idAdminUser}" class="footer-messages-area">[${i18n:_('Click here')}]</n:a>
</div>
</n:div>
</n:td>
<n:td height="40" align="right" valign="bottom">
<n:img width="110" height="40" src="${contextPath}/common/img/logos_footer_fundacion.png"/>

View file

@ -29,6 +29,20 @@
<?component name="list" inline="true" macroURI="_listUsers.zul"?>
<?component name="edition" inline="true" macroURI="_editUser.zul"?>
<zk>
<script type="text/JavaScript">
<![CDATA[
function showWarningDefaultPasswd() {
var warningDefaultPasswd = document.getElementById ("warningDefaultPasswd");
warningDefaultPasswd.style["display"] = "inline";
}
function hideWarningDefaultPasswd() {
var warningDefaultPasswd = document.getElementById ("warningDefaultPasswd");
warningDefaultPasswd.style["display"] = "none";
}
]]>
</script>
<window self="@{define(content)}"
apply="org.navalplanner.web.users.UserCRUDController">
<vbox id="messagesContainer"></vbox>