Remove default user with login user and password user

FEA: ItEr76S30PermissionsEnhancements
This commit is contained in:
Manuel Rego Casasnovas 2012-06-20 12:47:49 +02:00
parent 7907c12a91
commit c3b5232d16
9 changed files with 22 additions and 51 deletions

View file

@ -73,8 +73,6 @@ public class Configuration extends BaseEntity {
private Boolean changedDefaultAdminPassword = false; private Boolean changedDefaultAdminPassword = false;
private Boolean changedDefaultUserPassword = false;
private Boolean changedDefaultWsreaderPassword = false; private Boolean changedDefaultWsreaderPassword = false;
private Boolean changedDefaultWswriterPassword = false; private Boolean changedDefaultWswriterPassword = false;
@ -323,15 +321,6 @@ public class Configuration extends BaseEntity {
: changedDefaultAdminPassword; : changedDefaultAdminPassword;
} }
public void setChangedDefaultUserPassword(Boolean changedDefaultUserPassword) {
this.changedDefaultUserPassword = changedDefaultUserPassword;
}
public Boolean getChangedDefaultUserPassword() {
return changedDefaultUserPassword != null ? changedDefaultUserPassword
: false;
}
public void setChangedDefaultWsreaderPassword( public void setChangedDefaultWsreaderPassword(
Boolean changedDefaultWsreaderPassword) { Boolean changedDefaultWsreaderPassword) {
this.changedDefaultWsreaderPassword = changedDefaultWsreaderPassword; this.changedDefaultWsreaderPassword = changedDefaultWsreaderPassword;

View file

@ -571,4 +571,11 @@
</update> </update>
</changeSet> </changeSet>
<changeSet id="drop-column-changed_default_user_password-in-configuration"
author="mrego">
<comment>Drop column code in configuration table</comment>
<dropColumn tableName="configuration"
columnName="changed_default_user_password" />
</changeSet>
</databaseChangeLog> </databaseChangeLog>

View file

@ -45,8 +45,6 @@
column="monte_carlo_method_tab_visible" /> column="monte_carlo_method_tab_visible" />
<property name="changedDefaultAdminPassword" not-null="true" <property name="changedDefaultAdminPassword" not-null="true"
column="changed_default_admin_password" /> column="changed_default_admin_password" />
<property name="changedDefaultUserPassword" not-null="true"
column="changed_default_user_password" />
<property name="changedDefaultWsreaderPassword" not-null="true" <property name="changedDefaultWsreaderPassword" not-null="true"
column="changed_default_wsreader_password" /> column="changed_default_wsreader_password" />
<property name="changedDefaultWswriterPassword" not-null="true" <property name="changedDefaultWswriterPassword" not-null="true"

View file

@ -135,10 +135,6 @@ public class TemplateController extends GenericForwardComposer {
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.ADMIN); return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.ADMIN);
} }
public String getDefaultPasswdUserVisible() {
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.USER);
}
public String getDefaultPasswdWsreaderVisible() { public String getDefaultPasswdWsreaderVisible() {
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.WSREADER); return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.WSREADER);
} }
@ -171,10 +167,6 @@ public class TemplateController extends GenericForwardComposer {
return templateModel.getIdUser(MandatoryUser.ADMIN.getLoginName()); return templateModel.getIdUser(MandatoryUser.ADMIN.getLoginName());
} }
public String getIdUser() {
return templateModel.getIdUser(MandatoryUser.USER.getLoginName());
}
public String getIdWsreaderUser() { public String getIdWsreaderUser() {
return templateModel.getIdUser(MandatoryUser.WSREADER.getLoginName()); return templateModel.getIdUser(MandatoryUser.WSREADER.getLoginName());
} }
@ -201,4 +193,8 @@ public class TemplateController extends GenericForwardComposer {
.isAllowToGatherUsageStatsEnabled()); .isAllowToGatherUsageStatsEnabled());
} }
public String getUsername() {
return SecurityUtils.getLoggedUser().getUsername();
}
} }

View file

@ -30,7 +30,6 @@ import org.libreplan.business.common.Registry;
import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.users.entities.OrderAuthorization; import org.libreplan.business.users.entities.OrderAuthorization;
import org.libreplan.business.users.entities.UserRole; import org.libreplan.business.users.entities.UserRole;
import org.libreplan.web.users.bootstrap.MandatoryUser;
import org.libreplan.web.users.services.CustomUser; import org.libreplan.web.users.services.CustomUser;
import org.springframework.security.Authentication; import org.springframework.security.Authentication;
import org.springframework.security.context.SecurityContextHolder; import org.springframework.security.context.SecurityContextHolder;
@ -76,7 +75,7 @@ public final class SecurityUtils {
.getCurrent().getNativeRequest(); .getCurrent().getNativeRequest();
Principal principal = request.getUserPrincipal(); Principal principal = request.getUserPrincipal();
if (principal == null) { if (principal == null) {
return MandatoryUser.USER.getLoginName(); return null;
} }
return principal.getName(); return principal.getName();
} }
@ -119,12 +118,13 @@ public final class SecurityUtils {
@Override @Override
public Boolean execute() { public Boolean execute() {
try { try {
String username = getLoggedUser().getUsername();
return Registry return Registry
.getOrderAuthorizationDAO() .getOrderAuthorizationDAO()
.userOrItsProfilesHaveAnyAuthorization( .userOrItsProfilesHaveAnyAuthorization(
Registry.getUserDAO() Registry.getUserDAO()
.findByLoginName( .findByLoginName(
getSessionUserLoginName())); username));
} catch (InstanceNotFoundException e) { } catch (InstanceNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View file

@ -39,11 +39,6 @@ public class PasswordUtil {
checkIfChangeDefaultPasswd(MandatoryUser.ADMIN, clearPassword); checkIfChangeDefaultPasswd(MandatoryUser.ADMIN, clearPassword);
return; return;
} }
if (user.getLoginName().equalsIgnoreCase(
MandatoryUser.USER.getLoginName())) {
checkIfChangeDefaultPasswd(MandatoryUser.USER, clearPassword);
return;
}
if (user.getLoginName().equalsIgnoreCase( if (user.getLoginName().equalsIgnoreCase(
MandatoryUser.WSREADER.getLoginName())) { MandatoryUser.WSREADER.getLoginName())) {
checkIfChangeDefaultPasswd(MandatoryUser.WSREADER, clearPassword); checkIfChangeDefaultPasswd(MandatoryUser.WSREADER, clearPassword);
@ -84,8 +79,6 @@ public class PasswordUtil {
public static void showOrHideDefaultPasswordWarnings() { public static void showOrHideDefaultPasswordWarnings() {
boolean adminNotDefaultPassword = MandatoryUser.ADMIN boolean adminNotDefaultPassword = MandatoryUser.ADMIN
.hasChangedDefaultPasswordOrDisabled(); .hasChangedDefaultPasswordOrDisabled();
boolean userNotDefaultPassword = MandatoryUser.USER
.hasChangedDefaultPasswordOrDisabled();
boolean wsreaderNotDefaultPassword = MandatoryUser.WSREADER boolean wsreaderNotDefaultPassword = MandatoryUser.WSREADER
.hasChangedDefaultPasswordOrDisabled(); .hasChangedDefaultPasswordOrDisabled();
boolean wswriterNotDefaultPassword = MandatoryUser.WSWRITER boolean wswriterNotDefaultPassword = MandatoryUser.WSWRITER
@ -95,7 +88,6 @@ public class PasswordUtil {
Clients.evalJavaScript("showOrHideDefaultPasswordWarnings(" Clients.evalJavaScript("showOrHideDefaultPasswordWarnings("
+ adminNotDefaultPassword + ", " + adminNotDefaultPassword + ", "
+ userNotDefaultPassword + ", "
+ wsreaderNotDefaultPassword + ", " + wsreaderNotDefaultPassword + ", "
+ wswriterNotDefaultPassword + ", " + wswriterNotDefaultPassword + ", "
+ wssubcontractingNotDefaultPassword + ");"); + wssubcontractingNotDefaultPassword + ");");

View file

@ -21,7 +21,6 @@
package org.libreplan.web.users.bootstrap; package org.libreplan.web.users.bootstrap;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.EnumSet; import java.util.EnumSet;
@ -46,12 +45,6 @@ import org.libreplan.business.users.entities.UserRole;
*/ */
public enum MandatoryUser { public enum MandatoryUser {
USER(new ArrayList<UserRole>(), Configuration.isExampleUsersDisabled()) {
@Override
public boolean hasChangedDefaultPassword() {
return getConfiguration().getChangedDefaultUserPassword();
}
},
ADMIN(Arrays.asList(UserRole.ROLE_SUPERUSER, ADMIN(Arrays.asList(UserRole.ROLE_SUPERUSER,
UserRole.ROLE_READ_ALL_PROJECTS, UserRole.ROLE_READ_ALL_PROJECTS,
UserRole.ROLE_EDIT_ALL_PROJECTS, UserRole.ROLE_EDIT_ALL_PROJECTS,

View file

@ -36,7 +36,6 @@ signature="java.lang.Boolean isDefaultPasswordsControl()"?>
contextPath = Executions.getCurrent().getContextPath(); contextPath = Executions.getCurrent().getContextPath();
templateCtrl = templateController; templateCtrl = templateController;
idAdminUser = templateController.getIdAdminUser(); idAdminUser = templateController.getIdAdminUser();
idUser = templateController.getIdUser();
idWsreader = templateController.getIdWsreaderUser(); idWsreader = templateController.getIdWsreaderUser();
idWswriter = templateController.getIdWswriterUser(); idWswriter = templateController.getIdWswriterUser();
idWssubcontracting = templateController.getIdWssubcontractingUser(); idWssubcontracting = templateController.getIdWssubcontractingUser();
@ -102,7 +101,7 @@ signature="java.lang.Boolean isDefaultPasswordsControl()"?>
</window> </window>
</div> </div>
</n:td> </n:td>
<n:td class="usuario">${i18n:_('user')}: ${desktop.execution.userPrincipal.name}</n:td> <n:td class="usuario">${i18n:_('user')}: ${templateController.username}</n:td>
<n:td><n:a href="${contextPath}/j_spring_security_logout" class="cerrar_sesion">[${i18n:_('Log out')}]</n:a></n:td> <n:td><n:a href="${contextPath}/j_spring_security_logout" class="cerrar_sesion">[${i18n:_('Log out')}]</n:a></n:td>
</n:tr> </n:tr>
</n:table> </n:table>
@ -143,9 +142,6 @@ signature="java.lang.Boolean isDefaultPasswordsControl()"?>
class="footer-messages-area" class="footer-messages-area"
style="display:${templateCtrl.defaultPasswdVisible}"> style="display:${templateCtrl.defaultPasswdVisible}">
<div> <div>
<n:a href="${contextPath}/users/users.zul#edit%3D${idUser}"
id="warningDefaultPasswduser"
style="display:${templateCtrl.defaultPasswdUserVisible}">[user]</n:a>
<n:a href="${contextPath}/users/users.zul#edit%3D${idWsreader}" <n:a href="${contextPath}/users/users.zul#edit%3D${idWsreader}"
id="warningDefaultPasswdwsreader" id="warningDefaultPasswdwsreader"
style="display:${templateCtrl.defaultPasswdWsreaderVisible}">[wsreader]</n:a> style="display:${templateCtrl.defaultPasswdWsreaderVisible}">[wsreader]</n:a>

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of LibrePlan * This file is part of LibrePlan
* *
* Copyright (C) 2011 Igalia, S.L. * Copyright (C) 2011-2012 Igalia, S.L.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by * it under the terms of the GNU Affero General Public License as published by
@ -17,22 +17,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
function showOrHideDefaultPasswordWarnings(adminNotDefaultPassword, function showOrHideDefaultPasswordWarnings(
userNotDefaultPassword, wsreaderNotDefaultPassword, adminNotDefaultPassword,
wswriterNotDefaultPassword, wssubcontractingNotDefaultPassword) { wsreaderNotDefaultPassword,
wswriterNotDefaultPassword,
wssubcontractingNotDefaultPassword) {
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdadmin"), setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdadmin"),
adminNotDefaultPassword); adminNotDefaultPassword);
var otherDefaultPassword = adminNotDefaultPassword && var otherDefaultPassword = adminNotDefaultPassword &&
(!userNotDefaultPassword || !wsreaderNotDefaultPassword || (!wsreaderNotDefaultPassword ||
!wswriterNotDefaultPassword || !wssubcontractingNotDefaultPassword); !wswriterNotDefaultPassword || !wssubcontractingNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdOthers"), setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdOthers"),
!otherDefaultPassword); !otherDefaultPassword);
if (otherDefaultPassword) { if (otherDefaultPassword) {
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswduser"),
userNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdwsreader"), setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdwsreader"),
wsreaderNotDefaultPassword); wsreaderNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdwswriter"), setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdwswriter"),