Add new compilation option to disable default users (user, wsreader and wswriter)
A new Maven property has been added to disable the default users. This property is enabled by default except for the "dev" profile. You can manually specify the property with the following argument: -Ddefault.exampleUsersDisabled=false FEA: ItEr76S04BugFixing
This commit is contained in:
parent
41610cad2b
commit
b698d0fa1e
5 changed files with 68 additions and 20 deletions
|
|
@ -2,6 +2,7 @@
|
|||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2010-2011 Wireless Galicia, S.L.
|
||||
* Copyright (C) 2012 Igalia, S.L.
|
||||
*
|
||||
* 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
|
||||
|
|
@ -19,24 +20,29 @@
|
|||
|
||||
package org.libreplan.business.common;
|
||||
|
||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
|
||||
|
||||
/**
|
||||
* It contains the compiling option to disable the warning changing default
|
||||
* password and implements of singleton pattern.
|
||||
* This is a singleton that contains the compilation options passed from Maven.
|
||||
*
|
||||
* Currently we have two options:
|
||||
* <ul>
|
||||
* <li>Enable/Disable the warning changing default password</li>
|
||||
* <li>Enable/Disable default users (such as user, wsreader and wswriter)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public class Configuration {
|
||||
|
||||
private static final Configuration singleton = new Configuration();
|
||||
|
||||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
private Boolean defaultPasswordsControl;
|
||||
|
||||
private Boolean exampleUsersDisabled;
|
||||
|
||||
private Configuration() {
|
||||
}
|
||||
|
||||
|
|
@ -61,4 +67,19 @@ public class Configuration {
|
|||
return defaultPasswordsControl;
|
||||
}
|
||||
|
||||
public void setExampleUsersDisabled(Boolean exampleUsersDisabled) {
|
||||
this.exampleUsersDisabled = exampleUsersDisabled;
|
||||
}
|
||||
|
||||
public Boolean getExampleUsersDisabled() {
|
||||
return exampleUsersDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of example users disabled compilation option
|
||||
*/
|
||||
public static boolean isExampleUsersDisabled() {
|
||||
return BooleanUtils.isNotFalse(singleton.getExampleUsersDisabled());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,10 @@
|
|||
factory-method="getInstance"
|
||||
lazy-init="false">
|
||||
<property name="defaultPasswordsControl">
|
||||
<value>${default.passwordsControl}</value>
|
||||
<value>${default.passwordsControl}</value>
|
||||
</property>
|
||||
<property name="exampleUsersDisabled">
|
||||
<value>${default.exampleUsersDisabled}</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
|
|
|||
|
|
@ -28,19 +28,25 @@ import java.util.EnumSet;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.libreplan.business.common.Configuration;
|
||||
import org.libreplan.business.common.Registry;
|
||||
import org.libreplan.business.common.entities.Configuration;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.users.entities.UserRole;
|
||||
|
||||
/**
|
||||
* It enumerates the mandatory users (login names) for running the application.
|
||||
* It enumerates the mandatory users (login names) for running the application.<br />
|
||||
*
|
||||
* <code>ADMIN</code> user will be always enabled, however <code>USER</code>,
|
||||
* <code>WSREADER</code> and <code>WSWRITER</code> could be disabled in
|
||||
* copilation time with a Maven option specified via {@link Configuration}
|
||||
* class.
|
||||
*
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public enum MandatoryUser {
|
||||
|
||||
USER(new ArrayList<UserRole>()) {
|
||||
USER(new ArrayList<UserRole>(), Configuration.isExampleUsersDisabled()) {
|
||||
@Override
|
||||
public boolean hasChangedDefaultPassword() {
|
||||
return getConfiguration().getChangedDefaultUserPassword();
|
||||
|
|
@ -49,20 +55,22 @@ public enum MandatoryUser {
|
|||
ADMIN(Arrays.asList(UserRole.ROLE_ADMINISTRATION,
|
||||
UserRole.ROLE_READ_ALL_ORDERS,
|
||||
UserRole.ROLE_EDIT_ALL_ORDERS,
|
||||
UserRole.ROLE_CREATE_ORDER)) {
|
||||
UserRole.ROLE_CREATE_ORDER), false) {
|
||||
|
||||
@Override
|
||||
public boolean hasChangedDefaultPassword() {
|
||||
return getConfiguration().getChangedDefaultAdminPassword();
|
||||
}
|
||||
},
|
||||
WSREADER(Arrays.asList(UserRole.ROLE_WS_READER)) {
|
||||
WSREADER(Arrays.asList(UserRole.ROLE_WS_READER), Configuration
|
||||
.isExampleUsersDisabled()) {
|
||||
@Override
|
||||
public boolean hasChangedDefaultPassword() {
|
||||
return getConfiguration().getChangedDefaultWsreaderPassword();
|
||||
}
|
||||
},
|
||||
WSWRITER(Arrays.asList(UserRole.ROLE_WS_READER, UserRole.ROLE_WS_WRITER)) {
|
||||
WSWRITER(Arrays.asList(UserRole.ROLE_WS_READER, UserRole.ROLE_WS_WRITER),
|
||||
Configuration.isExampleUsersDisabled()) {
|
||||
@Override
|
||||
public boolean hasChangedDefaultPassword() {
|
||||
return getConfiguration().getChangedDefaultWswriterPassword();
|
||||
|
|
@ -84,15 +92,23 @@ public enum MandatoryUser {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static Configuration getConfiguration() {
|
||||
private static org.libreplan.business.common.entities.Configuration getConfiguration() {
|
||||
return Registry.getConfigurationDAO()
|
||||
.getConfigurationWithReadOnlyTransaction();
|
||||
}
|
||||
|
||||
private Set<UserRole> initialRoles;
|
||||
|
||||
private MandatoryUser(Collection<UserRole> initialUserRoles) {
|
||||
private final boolean userDisabled;
|
||||
|
||||
private MandatoryUser(Collection<UserRole> initialUserRoles,
|
||||
boolean userDisabled) {
|
||||
this.initialRoles = new HashSet<UserRole>(initialUserRoles);
|
||||
this.userDisabled = userDisabled;
|
||||
}
|
||||
|
||||
public boolean isUserDisabled() {
|
||||
return userDisabled;
|
||||
}
|
||||
|
||||
public boolean hasChangedDefaultPasswordOrDisabled() {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
|
||||
* 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
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
@ -28,7 +28,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Bootstrapt to create the default {@link User}s.
|
||||
*
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
@Transactional
|
||||
public class UsersBootstrapInDB implements IUsersBootstrapInDB {
|
||||
|
|
@ -57,10 +60,11 @@ public class UsersBootstrapInDB implements IUsersBootstrapInDB {
|
|||
private void createUserIfNotExists(MandatoryUser u) {
|
||||
|
||||
if (!userDAO.existsByLoginName(u.getLoginName())) {
|
||||
User user = User.create(u.getLoginName(), getEncodedPassword(u),
|
||||
u.getInitialRoles());
|
||||
user.setDisabled(u.isUserDisabled());
|
||||
|
||||
userDAO.save(User.create(u.getLoginName(), getEncodedPassword(u),
|
||||
u.getInitialRoles()));
|
||||
|
||||
userDAO.save(user);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
4
pom.xml
4
pom.xml
|
|
@ -36,6 +36,7 @@
|
|||
<databasetable.prefix>public.</databasetable.prefix>
|
||||
|
||||
<default.passwordsControl>true</default.passwordsControl>
|
||||
<default.exampleUsersDisabled>true</default.exampleUsersDisabled>
|
||||
</properties>
|
||||
|
||||
<!--
|
||||
|
|
@ -83,6 +84,9 @@
|
|||
<hibernate.format_sql>true</hibernate.format_sql>
|
||||
<hibernate.use_sql_comments>true</hibernate.use_sql_comments>
|
||||
<hibernate.hbm2ddl.auto>validate</hibernate.hbm2ddl.auto>
|
||||
|
||||
<!-- Enable example users (user, wsreader and wswriter) -->
|
||||
<default.exampleUsersDisabled>false</default.exampleUsersDisabled>
|
||||
</properties>
|
||||
</profile>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue