Skip to content
Snippets Groups Projects
Commit e4ac848c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

make sure tha we cannot persist user without password in the database

parent 346254c0
No related branches found
No related tags found
1 merge request!849Resolve "user db change"
......@@ -2,15 +2,14 @@ package lcsb.mapviewer.model.user;
import java.awt.Color;
import java.io.Serializable;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
import javax.persistence.*;
import lcsb.mapviewer.model.security.Privilege;
import org.hibernate.annotations.Cascade;
import lcsb.mapviewer.model.security.Privilege;
@Entity
public class User implements Serializable {
......@@ -22,6 +21,7 @@ public class User implements Serializable {
private String login;
@Column(nullable = false)
private String cryptedPassword;
private String name;
......@@ -32,25 +32,29 @@ public class User implements Serializable {
/**
* User defined color overriding system
* {@link ConfigurationElementType#MIN_COLOR_VAL}. Used for coloring minimum values in overlays.
* {@link ConfigurationElementType#MIN_COLOR_VAL}. Used for coloring minimum
* values in overlays.
*/
private Color minColor;
/**
* User defined color overriding system
* {@link ConfigurationElementType#MAX_COLOR_VAL}. Used for coloring maximum values in overlays.
* {@link ConfigurationElementType#MAX_COLOR_VAL}. Used for coloring maximum
* values in overlays.
*/
private Color maxColor;
/**
* User defined color overriding system
* {@link ConfigurationElementType#NEUTRAL_COLOR_VAL}. Used for coloring neutral values (0) in overlays.
* {@link ConfigurationElementType#NEUTRAL_COLOR_VAL}. Used for coloring neutral
* values (0) in overlays.
*/
private Color neutralColor;
/**
* User defined color overriding system
* {@link ConfigurationElementType#SIMPLE_COLOR_VAL}. Used for coloring overlays without values and colors.
* {@link ConfigurationElementType#SIMPLE_COLOR_VAL}. Used for coloring overlays
* without values and colors.
*/
private Color simpleColor;
......@@ -67,11 +71,7 @@ public class User implements Serializable {
private Set<Calendar> termsOfUseConsentDates = new HashSet<>();
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(
name = "user_privilege_map_table",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "privilege_id")
)
@JoinTable(name = "user_privilege_map_table", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "privilege_id"))
private Set<Privilege> privileges = new HashSet<>();
@OneToOne(cascade = CascadeType.ALL)
......
update user_table set crypted_password = '' where crypted_password is null;
ALTER TABLE user_table ALTER COLUMN crypted_password SET NOT NULL;
......@@ -9,6 +9,7 @@ import java.util.ArrayList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.PropertyValueException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -80,6 +81,19 @@ public class UserDaoTest extends PersistTestFunctions {
}
}
@Test(expected = PropertyValueException.class)
public void testTryUserWithNullPassword() {
try {
User user = new User();
user.setLogin(testLogin);
userDao.add(user);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAddDeleteAdd() {
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment