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
|
* This file is part of LibrePlan
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010-2011 Wireless Galicia, S.L.
|
* 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
|
* 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
|
||||||
|
|
@ -19,24 +20,29 @@
|
||||||
|
|
||||||
package org.libreplan.business.common;
|
package org.libreplan.business.common;
|
||||||
|
|
||||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
import org.apache.commons.lang.BooleanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It contains the compiling option to disable the warning changing default
|
* This is a singleton that contains the compilation options passed from Maven.
|
||||||
* password and implements of singleton pattern.
|
*
|
||||||
|
* 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 Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||||
|
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||||
*/
|
*/
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
|
|
||||||
private static final Configuration singleton = new Configuration();
|
private static final Configuration singleton = new Configuration();
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IConfigurationDAO configurationDAO;
|
|
||||||
|
|
||||||
private Boolean defaultPasswordsControl;
|
private Boolean defaultPasswordsControl;
|
||||||
|
|
||||||
|
private Boolean exampleUsersDisabled;
|
||||||
|
|
||||||
private Configuration() {
|
private Configuration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,4 +67,19 @@ public class Configuration {
|
||||||
return defaultPasswordsControl;
|
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"
|
factory-method="getInstance"
|
||||||
lazy-init="false">
|
lazy-init="false">
|
||||||
<property name="defaultPasswordsControl">
|
<property name="defaultPasswordsControl">
|
||||||
<value>${default.passwordsControl}</value>
|
<value>${default.passwordsControl}</value>
|
||||||
|
</property>
|
||||||
|
<property name="exampleUsersDisabled">
|
||||||
|
<value>${default.exampleUsersDisabled}</value>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,19 +28,25 @@ import java.util.EnumSet;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.libreplan.business.common.Configuration;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
import org.libreplan.business.common.entities.Configuration;
|
|
||||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||||
import org.libreplan.business.users.entities.UserRole;
|
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 Fernando Bellas Permuy <fbellas@udc.es>
|
||||||
|
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||||
*/
|
*/
|
||||||
public enum MandatoryUser {
|
public enum MandatoryUser {
|
||||||
|
|
||||||
USER(new ArrayList<UserRole>()) {
|
USER(new ArrayList<UserRole>(), Configuration.isExampleUsersDisabled()) {
|
||||||
@Override
|
@Override
|
||||||
public boolean hasChangedDefaultPassword() {
|
public boolean hasChangedDefaultPassword() {
|
||||||
return getConfiguration().getChangedDefaultUserPassword();
|
return getConfiguration().getChangedDefaultUserPassword();
|
||||||
|
|
@ -49,20 +55,22 @@ public enum MandatoryUser {
|
||||||
ADMIN(Arrays.asList(UserRole.ROLE_ADMINISTRATION,
|
ADMIN(Arrays.asList(UserRole.ROLE_ADMINISTRATION,
|
||||||
UserRole.ROLE_READ_ALL_ORDERS,
|
UserRole.ROLE_READ_ALL_ORDERS,
|
||||||
UserRole.ROLE_EDIT_ALL_ORDERS,
|
UserRole.ROLE_EDIT_ALL_ORDERS,
|
||||||
UserRole.ROLE_CREATE_ORDER)) {
|
UserRole.ROLE_CREATE_ORDER), false) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasChangedDefaultPassword() {
|
public boolean hasChangedDefaultPassword() {
|
||||||
return getConfiguration().getChangedDefaultAdminPassword();
|
return getConfiguration().getChangedDefaultAdminPassword();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
WSREADER(Arrays.asList(UserRole.ROLE_WS_READER)) {
|
WSREADER(Arrays.asList(UserRole.ROLE_WS_READER), Configuration
|
||||||
|
.isExampleUsersDisabled()) {
|
||||||
@Override
|
@Override
|
||||||
public boolean hasChangedDefaultPassword() {
|
public boolean hasChangedDefaultPassword() {
|
||||||
return getConfiguration().getChangedDefaultWsreaderPassword();
|
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
|
@Override
|
||||||
public boolean hasChangedDefaultPassword() {
|
public boolean hasChangedDefaultPassword() {
|
||||||
return getConfiguration().getChangedDefaultWswriterPassword();
|
return getConfiguration().getChangedDefaultWswriterPassword();
|
||||||
|
|
@ -84,15 +92,23 @@ public enum MandatoryUser {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Configuration getConfiguration() {
|
private static org.libreplan.business.common.entities.Configuration getConfiguration() {
|
||||||
return Registry.getConfigurationDAO()
|
return Registry.getConfigurationDAO()
|
||||||
.getConfigurationWithReadOnlyTransaction();
|
.getConfigurationWithReadOnlyTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<UserRole> initialRoles;
|
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.initialRoles = new HashSet<UserRole>(initialUserRoles);
|
||||||
|
this.userDisabled = userDisabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUserDisabled() {
|
||||||
|
return userDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasChangedDefaultPasswordOrDisabled() {
|
public boolean hasChangedDefaultPasswordOrDisabled() {
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -28,7 +28,10 @@ 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.
|
||||||
|
*
|
||||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||||
|
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||||
*/
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public class UsersBootstrapInDB implements IUsersBootstrapInDB {
|
public class UsersBootstrapInDB implements IUsersBootstrapInDB {
|
||||||
|
|
@ -57,10 +60,11 @@ public class UsersBootstrapInDB implements IUsersBootstrapInDB {
|
||||||
private void createUserIfNotExists(MandatoryUser u) {
|
private void createUserIfNotExists(MandatoryUser u) {
|
||||||
|
|
||||||
if (!userDAO.existsByLoginName(u.getLoginName())) {
|
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),
|
userDAO.save(user);
|
||||||
u.getInitialRoles()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
pom.xml
4
pom.xml
|
|
@ -36,6 +36,7 @@
|
||||||
<databasetable.prefix>public.</databasetable.prefix>
|
<databasetable.prefix>public.</databasetable.prefix>
|
||||||
|
|
||||||
<default.passwordsControl>true</default.passwordsControl>
|
<default.passwordsControl>true</default.passwordsControl>
|
||||||
|
<default.exampleUsersDisabled>true</default.exampleUsersDisabled>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
@ -83,6 +84,9 @@
|
||||||
<hibernate.format_sql>true</hibernate.format_sql>
|
<hibernate.format_sql>true</hibernate.format_sql>
|
||||||
<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) -->
|
||||||
|
<default.exampleUsersDisabled>false</default.exampleUsersDisabled>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue