extend validation of user and database names

This commit is contained in:
Peter Hormanns 2015-12-28 20:07:00 +01:00
parent ab81cb8835
commit 3a704c322a
5 changed files with 26 additions and 6 deletions

View File

@ -48,7 +48,7 @@ public abstract class Database extends AbstractEntity implements Serializable {
@Column(name = "engine", columnDefinition = "character varying(12)", updatable=false)
private String instance;
@AnnFieldIO(validation="[a-z0-9\\_]*", rw=ReadWriteAccess.WRITEONCE)
@AnnFieldIO(validation="[a-z0-9]{5}_[a-z0-9_]{1,}", rw=ReadWriteAccess.WRITEONCE)
@Column(name = "name", columnDefinition = "character varying(24)", updatable=false)
private String name;

View File

@ -43,11 +43,11 @@ public abstract class DatabaseUser extends AbstractEntity implements Serializabl
@Column(name = "dbuser_id", columnDefinition = "integer", updatable=false, insertable=false)
private long id;
@AnnFieldIO(validation="[a-z0-9\\_]*", rw=ReadWriteAccess.WRITEONCE)
@AnnFieldIO(validation="[a-z0-9]{5}_[a-z0-9_]{1,}", rw=ReadWriteAccess.WRITEONCE)
@Column(name = "name", columnDefinition = "character varying(24)", updatable=false)
private String name;
@AnnFieldIO(validation="[^']*", rw=ReadWriteAccess.WRITEONLY)
@AnnFieldIO(validation="[^']{6,}", rw=ReadWriteAccess.WRITEONLY)
@Transient
private String password;

View File

@ -48,7 +48,7 @@ public class EMailAlias extends AbstractEntity implements Serializable {
@AnnFieldIO(validation="[a-z0-9]*", rw=ReadWriteAccess.READONLY)
private Pac pac;
@AnnFieldIO(validation="[a-z0-9\\_\\-\\.\\+]*", rw=ReadWriteAccess.WRITEONCE)
@AnnFieldIO(validation="[a-z0-9]{5}-[a-z0-9\\.\\_\\+]{1,}", rw=ReadWriteAccess.WRITEONCE)
@Column(updatable=false)
private String name;

View File

@ -40,11 +40,11 @@ public class UnixUser extends AbstractEntity implements Serializable {
@Column(name="userid", columnDefinition="integer", nullable=false, updatable=false)
private long userId;
@AnnFieldIO(validation="[a-z0-9\\_\\-\\.]*", rw=ReadWriteAccess.WRITEONCE)
@AnnFieldIO(validation="[a-z0-9]{5}-[a-z0-9\\.\\_]{1,}", rw=ReadWriteAccess.WRITEONCE)
@Column(name="name", columnDefinition = "character varying(24)", unique=true, updatable=false)
private String name;
@AnnFieldIO(validation="[^:]*", rw=ReadWriteAccess.WRITEONLY)
@AnnFieldIO(validation="[^:]{6,}", rw=ReadWriteAccess.WRITEONLY)
@Transient
private String password;

View File

@ -0,0 +1,20 @@
package de.hsadmin.validate;
import java.util.regex.Pattern;
public class PacName {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("[a-z0-9]{5}-[a-z0-9\\.\\_]{1,}");
System.out.println("xyz00-a.b " + pattern.matcher("xyz00-a.b").matches());
System.out.println("xyz00-a-b " + pattern.matcher("xyz00-a-b").matches());
System.out.println("xyz00-a.B " + pattern.matcher("xyz00-a.B").matches());
System.out.println("xyz00- " + pattern.matcher("xyz00-").matches());
System.out.println("xyz00 " + pattern.matcher("xyz00").matches());
System.out.println("xyz0 " + pattern.matcher("xyz0").matches());
System.out.println("xyz00_a " + pattern.matcher("xyz00_a").matches());
System.out.println("xyz00-a.b:c " + pattern.matcher("xyz00-a.b:c").matches());
}
}