Modified behavior of UsersBootstrapInDB in order to create users only if there are no users yet
This will work like the rest of bootstraps. Accordingly to its behavior the class has been renamed from MandatoryUser to PredefinedUsers. FEA: ItEr76S30PermissionsEnhancements
This commit is contained in:
parent
26d5638b41
commit
bdf731d473
12 changed files with 88 additions and 89 deletions
|
|
@ -29,7 +29,8 @@ import org.apache.commons.lang.BooleanUtils;
|
||||||
* Currently we have two options:
|
* Currently we have two options:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Enable/Disable the warning changing default password</li>
|
* <li>Enable/Disable the warning changing default password</li>
|
||||||
* <li>Enable/Disable default users (such as user, wsreader and wswriter)</li>
|
* <li>Enable/Disable default users (such as wsreader, wswriter,
|
||||||
|
* wssubcontracting, manager, hresources, outsourcing and reports)</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ package org.libreplan.web.common;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.libreplan.business.scenarios.entities.Scenario;
|
import org.libreplan.business.scenarios.entities.Scenario;
|
||||||
import org.libreplan.web.users.bootstrap.MandatoryUser;
|
import org.libreplan.web.users.bootstrap.PredefinedUsers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contract for {@link TemplateModel}.
|
* Contract for {@link TemplateModel}.
|
||||||
|
|
@ -50,7 +50,7 @@ public interface ITemplateModel {
|
||||||
|
|
||||||
boolean isScenariosVisible();
|
boolean isScenariosVisible();
|
||||||
|
|
||||||
boolean hasChangedDefaultPassword(MandatoryUser user);
|
boolean hasChangedDefaultPassword(PredefinedUsers user);
|
||||||
|
|
||||||
boolean adminPasswordChangedAndSomeOtherNotChanged();
|
boolean adminPasswordChangedAndSomeOtherNotChanged();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ import org.libreplan.business.scenarios.entities.Scenario;
|
||||||
import org.libreplan.web.common.ITemplateModel.IOnFinished;
|
import org.libreplan.web.common.ITemplateModel.IOnFinished;
|
||||||
import org.libreplan.web.common.components.bandboxsearch.BandboxSearch;
|
import org.libreplan.web.common.components.bandboxsearch.BandboxSearch;
|
||||||
import org.libreplan.web.security.SecurityUtils;
|
import org.libreplan.web.security.SecurityUtils;
|
||||||
import org.libreplan.web.users.bootstrap.MandatoryUser;
|
import org.libreplan.web.users.bootstrap.PredefinedUsers;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
|
|
@ -132,39 +132,39 @@ public class TemplateController extends GenericForwardComposer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultPasswdAdminVisible() {
|
public String getDefaultPasswdAdminVisible() {
|
||||||
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.ADMIN);
|
return notChangedPasswordWarningDisplayPropertyFor(PredefinedUsers.ADMIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultPasswdWsreaderVisible() {
|
public String getDefaultPasswdWsreaderVisible() {
|
||||||
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.WSREADER);
|
return notChangedPasswordWarningDisplayPropertyFor(PredefinedUsers.WSREADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultPasswdWswriterVisible() {
|
public String getDefaultPasswdWswriterVisible() {
|
||||||
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.WSWRITER);
|
return notChangedPasswordWarningDisplayPropertyFor(PredefinedUsers.WSWRITER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultPasswdWssubcontractingVisible() {
|
public String getDefaultPasswdWssubcontractingVisible() {
|
||||||
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.WSSUBCONTRACTING);
|
return notChangedPasswordWarningDisplayPropertyFor(PredefinedUsers.WSSUBCONTRACTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultPasswdManagerVisible() {
|
public String getDefaultPasswdManagerVisible() {
|
||||||
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.MANAGER);
|
return notChangedPasswordWarningDisplayPropertyFor(PredefinedUsers.MANAGER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultPasswdHresourcesVisible() {
|
public String getDefaultPasswdHresourcesVisible() {
|
||||||
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.HRESOURCES);
|
return notChangedPasswordWarningDisplayPropertyFor(PredefinedUsers.HRESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultPasswdOutsourcingVisible() {
|
public String getDefaultPasswdOutsourcingVisible() {
|
||||||
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.OUTSOURCING);
|
return notChangedPasswordWarningDisplayPropertyFor(PredefinedUsers.OUTSOURCING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultPasswdReportsVisible() {
|
public String getDefaultPasswdReportsVisible() {
|
||||||
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.REPORTS);
|
return notChangedPasswordWarningDisplayPropertyFor(PredefinedUsers.REPORTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String notChangedPasswordWarningDisplayPropertyFor(
|
private String notChangedPasswordWarningDisplayPropertyFor(
|
||||||
MandatoryUser mandatoryUser) {
|
PredefinedUsers mandatoryUser) {
|
||||||
return asDisplayProperty(templateModel
|
return asDisplayProperty(templateModel
|
||||||
.hasChangedDefaultPassword(mandatoryUser));
|
.hasChangedDefaultPassword(mandatoryUser));
|
||||||
}
|
}
|
||||||
|
|
@ -180,37 +180,37 @@ public class TemplateController extends GenericForwardComposer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdAdminUser() {
|
public String getIdAdminUser() {
|
||||||
return templateModel.getIdUser(MandatoryUser.ADMIN.getLoginName());
|
return templateModel.getIdUser(PredefinedUsers.ADMIN.getLoginName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdWsreaderUser() {
|
public String getIdWsreaderUser() {
|
||||||
return templateModel.getIdUser(MandatoryUser.WSREADER.getLoginName());
|
return templateModel.getIdUser(PredefinedUsers.WSREADER.getLoginName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdWswriterUser() {
|
public String getIdWswriterUser() {
|
||||||
return templateModel.getIdUser(MandatoryUser.WSWRITER.getLoginName());
|
return templateModel.getIdUser(PredefinedUsers.WSWRITER.getLoginName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdWssubcontractingUser() {
|
public String getIdWssubcontractingUser() {
|
||||||
return templateModel.getIdUser(MandatoryUser.WSSUBCONTRACTING
|
return templateModel.getIdUser(PredefinedUsers.WSSUBCONTRACTING
|
||||||
.getLoginName());
|
.getLoginName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdManagerUser() {
|
public String getIdManagerUser() {
|
||||||
return templateModel.getIdUser(MandatoryUser.MANAGER.getLoginName());
|
return templateModel.getIdUser(PredefinedUsers.MANAGER.getLoginName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdHresourcesUser() {
|
public String getIdHresourcesUser() {
|
||||||
return templateModel.getIdUser(MandatoryUser.HRESOURCES.getLoginName());
|
return templateModel.getIdUser(PredefinedUsers.HRESOURCES.getLoginName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdOutsourcingUser() {
|
public String getIdOutsourcingUser() {
|
||||||
return templateModel
|
return templateModel
|
||||||
.getIdUser(MandatoryUser.OUTSOURCING.getLoginName());
|
.getIdUser(PredefinedUsers.OUTSOURCING.getLoginName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdReportsUser() {
|
public String getIdReportsUser() {
|
||||||
return templateModel.getIdUser(MandatoryUser.REPORTS.getLoginName());
|
return templateModel.getIdUser(PredefinedUsers.REPORTS.getLoginName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUserAdmin() {
|
public boolean isUserAdmin() {
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ import org.libreplan.business.users.entities.User;
|
||||||
import org.libreplan.web.UserUtil;
|
import org.libreplan.web.UserUtil;
|
||||||
import org.libreplan.web.planner.tabs.GanttDiagramBuilder;
|
import org.libreplan.web.planner.tabs.GanttDiagramBuilder;
|
||||||
import org.libreplan.web.security.SecurityUtils;
|
import org.libreplan.web.security.SecurityUtils;
|
||||||
import org.libreplan.web.users.bootstrap.MandatoryUser;
|
import org.libreplan.web.users.bootstrap.PredefinedUsers;
|
||||||
import org.libreplan.web.users.services.CustomUser;
|
import org.libreplan.web.users.services.CustomUser;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
|
|
@ -426,14 +426,14 @@ public class TemplateModel implements ITemplateModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public boolean hasChangedDefaultPassword(MandatoryUser user) {
|
public boolean hasChangedDefaultPassword(PredefinedUsers user) {
|
||||||
return user.hasChangedDefaultPasswordOrDisabled();
|
return user.hasChangedDefaultPasswordOrDisabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public boolean adminPasswordChangedAndSomeOtherNotChanged() {
|
public boolean adminPasswordChangedAndSomeOtherNotChanged() {
|
||||||
return MandatoryUser.adminChangedAndSomeOtherNotChanged();
|
return PredefinedUsers.adminChangedAndSomeOtherNotChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ package org.libreplan.web.users;
|
||||||
|
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
import org.libreplan.business.users.entities.User;
|
import org.libreplan.business.users.entities.User;
|
||||||
import org.libreplan.web.users.bootstrap.MandatoryUser;
|
import org.libreplan.web.users.bootstrap.PredefinedUsers;
|
||||||
import org.zkoss.zk.ui.util.Clients;
|
import org.zkoss.zk.ui.util.Clients;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -35,49 +35,49 @@ public class PasswordUtil {
|
||||||
public static void checkIfChangeDefaultPasswd(User user,
|
public static void checkIfChangeDefaultPasswd(User user,
|
||||||
String clearPassword) {
|
String clearPassword) {
|
||||||
if (user.getLoginName().equalsIgnoreCase(
|
if (user.getLoginName().equalsIgnoreCase(
|
||||||
MandatoryUser.ADMIN.getLoginName())) {
|
PredefinedUsers.ADMIN.getLoginName())) {
|
||||||
checkIfChangeDefaultPasswd(MandatoryUser.ADMIN, clearPassword);
|
checkIfChangeDefaultPasswd(PredefinedUsers.ADMIN, clearPassword);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (user.getLoginName().equalsIgnoreCase(
|
if (user.getLoginName().equalsIgnoreCase(
|
||||||
MandatoryUser.WSREADER.getLoginName())) {
|
PredefinedUsers.WSREADER.getLoginName())) {
|
||||||
checkIfChangeDefaultPasswd(MandatoryUser.WSREADER, clearPassword);
|
checkIfChangeDefaultPasswd(PredefinedUsers.WSREADER, clearPassword);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (user.getLoginName().equalsIgnoreCase(
|
if (user.getLoginName().equalsIgnoreCase(
|
||||||
MandatoryUser.WSWRITER.getLoginName())) {
|
PredefinedUsers.WSWRITER.getLoginName())) {
|
||||||
checkIfChangeDefaultPasswd(MandatoryUser.WSWRITER, clearPassword);
|
checkIfChangeDefaultPasswd(PredefinedUsers.WSWRITER, clearPassword);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (user.getLoginName().equalsIgnoreCase(
|
if (user.getLoginName().equalsIgnoreCase(
|
||||||
MandatoryUser.WSSUBCONTRACTING.getLoginName())) {
|
PredefinedUsers.WSSUBCONTRACTING.getLoginName())) {
|
||||||
checkIfChangeDefaultPasswd(MandatoryUser.WSSUBCONTRACTING,
|
checkIfChangeDefaultPasswd(PredefinedUsers.WSSUBCONTRACTING,
|
||||||
clearPassword);
|
clearPassword);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (user.getLoginName().equalsIgnoreCase(
|
if (user.getLoginName().equalsIgnoreCase(
|
||||||
MandatoryUser.MANAGER.getLoginName())) {
|
PredefinedUsers.MANAGER.getLoginName())) {
|
||||||
checkIfChangeDefaultPasswd(MandatoryUser.MANAGER, clearPassword);
|
checkIfChangeDefaultPasswd(PredefinedUsers.MANAGER, clearPassword);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (user.getLoginName().equalsIgnoreCase(
|
if (user.getLoginName().equalsIgnoreCase(
|
||||||
MandatoryUser.HRESOURCES.getLoginName())) {
|
PredefinedUsers.HRESOURCES.getLoginName())) {
|
||||||
checkIfChangeDefaultPasswd(MandatoryUser.HRESOURCES, clearPassword);
|
checkIfChangeDefaultPasswd(PredefinedUsers.HRESOURCES, clearPassword);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (user.getLoginName().equalsIgnoreCase(
|
if (user.getLoginName().equalsIgnoreCase(
|
||||||
MandatoryUser.OUTSOURCING.getLoginName())) {
|
PredefinedUsers.OUTSOURCING.getLoginName())) {
|
||||||
checkIfChangeDefaultPasswd(MandatoryUser.OUTSOURCING, clearPassword);
|
checkIfChangeDefaultPasswd(PredefinedUsers.OUTSOURCING, clearPassword);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (user.getLoginName().equalsIgnoreCase(
|
if (user.getLoginName().equalsIgnoreCase(
|
||||||
MandatoryUser.REPORTS.getLoginName())) {
|
PredefinedUsers.REPORTS.getLoginName())) {
|
||||||
checkIfChangeDefaultPasswd(MandatoryUser.REPORTS, clearPassword);
|
checkIfChangeDefaultPasswd(PredefinedUsers.REPORTS, clearPassword);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkIfChangeDefaultPasswd(MandatoryUser user,
|
private static void checkIfChangeDefaultPasswd(PredefinedUsers user,
|
||||||
String clearPassword) {
|
String clearPassword) {
|
||||||
boolean changedPasswd = true;
|
boolean changedPasswd = true;
|
||||||
if (clearPassword.isEmpty()
|
if (clearPassword.isEmpty()
|
||||||
|
|
@ -97,21 +97,21 @@ public class PasswordUtil {
|
||||||
* been disabled
|
* been disabled
|
||||||
*/
|
*/
|
||||||
public static void showOrHideDefaultPasswordWarnings() {
|
public static void showOrHideDefaultPasswordWarnings() {
|
||||||
boolean adminNotDefaultPassword = MandatoryUser.ADMIN
|
boolean adminNotDefaultPassword = PredefinedUsers.ADMIN
|
||||||
.hasChangedDefaultPasswordOrDisabled();
|
.hasChangedDefaultPasswordOrDisabled();
|
||||||
boolean wsreaderNotDefaultPassword = MandatoryUser.WSREADER
|
boolean wsreaderNotDefaultPassword = PredefinedUsers.WSREADER
|
||||||
.hasChangedDefaultPasswordOrDisabled();
|
.hasChangedDefaultPasswordOrDisabled();
|
||||||
boolean wswriterNotDefaultPassword = MandatoryUser.WSWRITER
|
boolean wswriterNotDefaultPassword = PredefinedUsers.WSWRITER
|
||||||
.hasChangedDefaultPasswordOrDisabled();
|
.hasChangedDefaultPasswordOrDisabled();
|
||||||
boolean wssubcontractingNotDefaultPassword = MandatoryUser.WSSUBCONTRACTING
|
boolean wssubcontractingNotDefaultPassword = PredefinedUsers.WSSUBCONTRACTING
|
||||||
.hasChangedDefaultPasswordOrDisabled();
|
.hasChangedDefaultPasswordOrDisabled();
|
||||||
boolean managerNotDefaultPassword = MandatoryUser.MANAGER
|
boolean managerNotDefaultPassword = PredefinedUsers.MANAGER
|
||||||
.hasChangedDefaultPasswordOrDisabled();
|
.hasChangedDefaultPasswordOrDisabled();
|
||||||
boolean hresourcesNotDefaultPassword = MandatoryUser.HRESOURCES
|
boolean hresourcesNotDefaultPassword = PredefinedUsers.HRESOURCES
|
||||||
.hasChangedDefaultPasswordOrDisabled();
|
.hasChangedDefaultPasswordOrDisabled();
|
||||||
boolean outsourcingNotDefaultPassword = MandatoryUser.OUTSOURCING
|
boolean outsourcingNotDefaultPassword = PredefinedUsers.OUTSOURCING
|
||||||
.hasChangedDefaultPasswordOrDisabled();
|
.hasChangedDefaultPasswordOrDisabled();
|
||||||
boolean reportsNotDefaultPassword = MandatoryUser.REPORTS
|
boolean reportsNotDefaultPassword = PredefinedUsers.REPORTS
|
||||||
.hasChangedDefaultPasswordOrDisabled();
|
.hasChangedDefaultPasswordOrDisabled();
|
||||||
|
|
||||||
Clients.evalJavaScript("showOrHideDefaultPasswordWarnings("
|
Clients.evalJavaScript("showOrHideDefaultPasswordWarnings("
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
|
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
|
||||||
* Desenvolvemento Tecnolóxico de Galicia
|
* Desenvolvemento Tecnolóxico de Galicia
|
||||||
* Copyright (C) 2010-2011 Igalia, S.L.
|
* Copyright (C) 2010-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
|
||||||
|
|
@ -35,17 +35,19 @@ import org.libreplan.business.users.entities.Profile;
|
||||||
import org.libreplan.business.users.entities.UserRole;
|
import org.libreplan.business.users.entities.UserRole;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It enumerates the mandatory users (usernames) for running the application.<br />
|
* It enumerates the default users (usernames) for the application.<br />
|
||||||
*
|
*
|
||||||
* <code>ADMIN</code> user will be always enabled, however <code>USER</code>,
|
* {@link PredefinedUsers#ADMIN} user will be always enabled, however
|
||||||
* <code>WSREADER</code> and <code>WSWRITER</code> could be disabled in
|
* {@link PredefinedUsers#WSREADER}, {@link PredefinedUsers#WSWRITER},
|
||||||
* copilation time with a Maven option specified via {@link Configuration}
|
* {@link PredefinedUsers#WSSUBCONTRACTING}, {@link PredefinedUsers#MANAGER},
|
||||||
* class.
|
* {@link PredefinedUsers#HRESOURCES}, {@link PredefinedUsers#OUTSOURCING} and
|
||||||
|
* {@link PredefinedUsers#REPORTS} users could be disabled in compilation time
|
||||||
|
* with a Maven option specified via {@link Configuration} class.
|
||||||
*
|
*
|
||||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||||
*/
|
*/
|
||||||
public enum MandatoryUser {
|
public enum PredefinedUsers {
|
||||||
|
|
||||||
ADMIN(Arrays.asList(UserRole.ROLE_SUPERUSER,
|
ADMIN(Arrays.asList(UserRole.ROLE_SUPERUSER,
|
||||||
UserRole.ROLE_READ_ALL_PROJECTS,
|
UserRole.ROLE_READ_ALL_PROJECTS,
|
||||||
|
|
@ -117,8 +119,8 @@ public enum MandatoryUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean someKeepsDefaultPassword(
|
public static boolean someKeepsDefaultPassword(
|
||||||
Collection<MandatoryUser> mandatoryUsers) {
|
Collection<PredefinedUsers> mandatoryUsers) {
|
||||||
for (MandatoryUser each : mandatoryUsers) {
|
for (PredefinedUsers each : mandatoryUsers) {
|
||||||
if (!each.hasChangedDefaultPasswordOrDisabled()) {
|
if (!each.hasChangedDefaultPasswordOrDisabled()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -137,12 +139,12 @@ public enum MandatoryUser {
|
||||||
|
|
||||||
private final boolean userDisabled;
|
private final boolean userDisabled;
|
||||||
|
|
||||||
private MandatoryUser(Collection<UserRole> initialUserRoles,
|
private PredefinedUsers(Collection<UserRole> initialUserRoles,
|
||||||
boolean userDisabled) {
|
boolean userDisabled) {
|
||||||
this(initialUserRoles, null, userDisabled);
|
this(initialUserRoles, null, userDisabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MandatoryUser(Collection<UserRole> initialUserRoles,
|
private PredefinedUsers(Collection<UserRole> initialUserRoles,
|
||||||
Collection<Profile> initialProfiles, boolean userDisabled) {
|
Collection<Profile> initialProfiles, boolean userDisabled) {
|
||||||
if (initialUserRoles != null) {
|
if (initialUserRoles != null) {
|
||||||
this.initialRoles = new HashSet<UserRole>(initialUserRoles);
|
this.initialRoles = new HashSet<UserRole>(initialUserRoles);
|
||||||
|
|
@ -179,7 +181,7 @@ public enum MandatoryUser {
|
||||||
return initialProfiles;
|
return initialProfiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnumSet<MandatoryUser> allExcept(MandatoryUser mandatoryUser) {
|
public static EnumSet<PredefinedUsers> allExcept(PredefinedUsers mandatoryUser) {
|
||||||
return EnumSet.complementOf(EnumSet.of(mandatoryUser));
|
return EnumSet.complementOf(EnumSet.of(mandatoryUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bootstrapt to create the default {@link User}s.
|
* Bootstrapt to create the default {@link User Users}.
|
||||||
*
|
*
|
||||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||||
|
|
@ -53,25 +53,20 @@ public class UsersBootstrapInDB implements IUsersBootstrapInDB {
|
||||||
@Override
|
@Override
|
||||||
public void loadRequiredData() {
|
public void loadRequiredData() {
|
||||||
|
|
||||||
for (MandatoryUser u : MandatoryUser.values()) {
|
if (userDAO.list(User.class).isEmpty()) {
|
||||||
createUserIfNotExists(u);
|
for (PredefinedUsers u : PredefinedUsers.values()) {
|
||||||
|
User user = User.create(u.getLoginName(),
|
||||||
|
getEncodedPassword(u), u.getInitialRoles(),
|
||||||
|
u.getInitialProfiles());
|
||||||
|
user.setDisabled(u.isUserDisabled());
|
||||||
|
|
||||||
|
userDAO.save(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createUserIfNotExists(MandatoryUser u) {
|
private String getEncodedPassword(PredefinedUsers u) {
|
||||||
|
|
||||||
if (!userDAO.existsByLoginName(u.getLoginName())) {
|
|
||||||
User user = User.create(u.getLoginName(), getEncodedPassword(u),
|
|
||||||
u.getInitialRoles(), u.getInitialProfiles());
|
|
||||||
user.setDisabled(u.isUserDisabled());
|
|
||||||
|
|
||||||
userDAO.save(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getEncodedPassword(MandatoryUser u) {
|
|
||||||
|
|
||||||
return dbPasswordEncoderService.encodePassword(u.getClearPassword(),
|
return dbPasswordEncoderService.encodePassword(u.getClearPassword(),
|
||||||
u.getLoginName());
|
u.getLoginName());
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ import org.libreplan.business.users.bootstrap.IProfileBootstrap;
|
||||||
import org.libreplan.business.users.daos.IUserDAO;
|
import org.libreplan.business.users.daos.IUserDAO;
|
||||||
import org.libreplan.business.users.entities.User;
|
import org.libreplan.business.users.entities.User;
|
||||||
import org.libreplan.web.users.bootstrap.IUsersBootstrapInDB;
|
import org.libreplan.web.users.bootstrap.IUsersBootstrapInDB;
|
||||||
import org.libreplan.web.users.bootstrap.MandatoryUser;
|
import org.libreplan.web.users.bootstrap.PredefinedUsers;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.annotation.Rollback;
|
import org.springframework.test.annotation.Rollback;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
@ -79,7 +79,7 @@ public class UsersBootstrapInDBTest {
|
||||||
|
|
||||||
usersBootstrap.loadRequiredData();
|
usersBootstrap.loadRequiredData();
|
||||||
|
|
||||||
for (MandatoryUser u : MandatoryUser.values()) {
|
for (PredefinedUsers u : PredefinedUsers.values()) {
|
||||||
|
|
||||||
User user = userDAO.findByLoginName(u.getLoginName());
|
User user = userDAO.findByLoginName(u.getLoginName());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||||
import org.libreplan.business.users.daos.IUserDAO;
|
import org.libreplan.business.users.daos.IUserDAO;
|
||||||
import org.libreplan.business.users.entities.User;
|
import org.libreplan.business.users.entities.User;
|
||||||
import org.libreplan.web.users.bootstrap.IUsersBootstrapInDB;
|
import org.libreplan.web.users.bootstrap.IUsersBootstrapInDB;
|
||||||
import org.libreplan.web.users.bootstrap.MandatoryUser;
|
import org.libreplan.web.users.bootstrap.PredefinedUsers;
|
||||||
import org.libreplan.web.users.services.IDBPasswordEncoderService;
|
import org.libreplan.web.users.services.IDBPasswordEncoderService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
@ -68,7 +68,7 @@ public class DBPasswordEncoderServiceTest {
|
||||||
|
|
||||||
usersBootstrap.loadRequiredData();
|
usersBootstrap.loadRequiredData();
|
||||||
|
|
||||||
for (MandatoryUser u : MandatoryUser.values()) {
|
for (PredefinedUsers u : PredefinedUsers.values()) {
|
||||||
|
|
||||||
String encodedPassword = dbPasswordEncoderService.encodePassword(
|
String encodedPassword = dbPasswordEncoderService.encodePassword(
|
||||||
u.getClearPassword(), u.getLoginName());
|
u.getClearPassword(), u.getLoginName());
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ import org.libreplan.business.scenarios.bootstrap.IScenariosBootstrap;
|
||||||
import org.libreplan.business.users.entities.Profile;
|
import org.libreplan.business.users.entities.Profile;
|
||||||
import org.libreplan.business.users.entities.UserRole;
|
import org.libreplan.business.users.entities.UserRole;
|
||||||
import org.libreplan.web.users.bootstrap.IUsersBootstrapInDB;
|
import org.libreplan.web.users.bootstrap.IUsersBootstrapInDB;
|
||||||
import org.libreplan.web.users.bootstrap.MandatoryUser;
|
import org.libreplan.web.users.bootstrap.PredefinedUsers;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.GrantedAuthority;
|
import org.springframework.security.GrantedAuthority;
|
||||||
import org.springframework.security.userdetails.UserDetails;
|
import org.springframework.security.userdetails.UserDetails;
|
||||||
|
|
@ -95,7 +95,7 @@ public class DBUserDetailsServiceTest {
|
||||||
public void testLoadUserByUsername() {
|
public void testLoadUserByUsername() {
|
||||||
usersBootstrap.loadRequiredData();
|
usersBootstrap.loadRequiredData();
|
||||||
|
|
||||||
for (MandatoryUser u : MandatoryUser.values()) {
|
for (PredefinedUsers u : PredefinedUsers.values()) {
|
||||||
|
|
||||||
UserDetails userDetails = userDetailsService.loadUserByUsername(u
|
UserDetails userDetails = userDetailsService.loadUserByUsername(u
|
||||||
.getLoginName());
|
.getLoginName());
|
||||||
|
|
@ -107,7 +107,7 @@ public class DBUserDetailsServiceTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getUserRoles(MandatoryUser u) {
|
private Object getUserRoles(PredefinedUsers u) {
|
||||||
Set<UserRole> userRoles = new HashSet<UserRole>();
|
Set<UserRole> userRoles = new HashSet<UserRole>();
|
||||||
|
|
||||||
userRoles.addAll(u.getInitialRoles());
|
userRoles.addAll(u.getInitialRoles());
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ import org.libreplan.business.scenarios.bootstrap.IScenariosBootstrap;
|
||||||
import org.libreplan.business.users.entities.Profile;
|
import org.libreplan.business.users.entities.Profile;
|
||||||
import org.libreplan.business.users.entities.UserRole;
|
import org.libreplan.business.users.entities.UserRole;
|
||||||
import org.libreplan.web.users.bootstrap.IUsersBootstrapInDB;
|
import org.libreplan.web.users.bootstrap.IUsersBootstrapInDB;
|
||||||
import org.libreplan.web.users.bootstrap.MandatoryUser;
|
import org.libreplan.web.users.bootstrap.PredefinedUsers;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.GrantedAuthority;
|
import org.springframework.security.GrantedAuthority;
|
||||||
import org.springframework.security.userdetails.UserDetails;
|
import org.springframework.security.userdetails.UserDetails;
|
||||||
|
|
@ -98,7 +98,7 @@ public class LDAPUserDetailsServiceTest {
|
||||||
public void testLoadUserByUsername() {
|
public void testLoadUserByUsername() {
|
||||||
usersBootstrap.loadRequiredData();
|
usersBootstrap.loadRequiredData();
|
||||||
|
|
||||||
for (MandatoryUser u : MandatoryUser.values()) {
|
for (PredefinedUsers u : PredefinedUsers.values()) {
|
||||||
|
|
||||||
UserDetails userDetails = userDetailsService.loadUserByUsername(u
|
UserDetails userDetails = userDetailsService.loadUserByUsername(u
|
||||||
.getLoginName());
|
.getLoginName());
|
||||||
|
|
@ -111,7 +111,7 @@ public class LDAPUserDetailsServiceTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getUserRoles(MandatoryUser u) {
|
private Object getUserRoles(PredefinedUsers u) {
|
||||||
Set<UserRole> userRoles = new HashSet<UserRole>();
|
Set<UserRole> userRoles = new HashSet<UserRole>();
|
||||||
|
|
||||||
userRoles.addAll(u.getInitialRoles());
|
userRoles.addAll(u.getInitialRoles());
|
||||||
|
|
|
||||||
3
pom.xml
3
pom.xml
|
|
@ -85,7 +85,8 @@
|
||||||
<hibernate.use_sql_comments>true</hibernate.use_sql_comments>
|
<hibernate.use_sql_comments>true</hibernate.use_sql_comments>
|
||||||
<hibernate.hbm2ddl.auto>validate</hibernate.hbm2ddl.auto>
|
<hibernate.hbm2ddl.auto>validate</hibernate.hbm2ddl.auto>
|
||||||
|
|
||||||
<!-- Enable example users (user, wsreader and wswriter) -->
|
<!-- Enable example users (wsreader, wswriter, wssubcontracting,
|
||||||
|
manager, hresources, outsourcing and reports) -->
|
||||||
<default.exampleUsersDisabled>false</default.exampleUsersDisabled>
|
<default.exampleUsersDisabled>false</default.exampleUsersDisabled>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue