HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2012-07-27 d596fcbf58417ff16b3a90fa564493e0acf470f5
annotate read-write-mode
11 files modified
1 files added
1 files renamed
200 ■■■■■ changed files
hsarback/database/database_update.sql 11 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/core/model/AnnFieldIO.java 5 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/core/model/GenericModuleImpl.java 6 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/core/model/ReadWriteAccess.java 7 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/db/Database.java 12 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/db/DatabaseUser.java 10 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/Domain.java 96 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java 5 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainOption.java 5 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/email/EMailAddress.java 10 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/email/EMailAlias.java 8 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/user/UnixUser.java 23 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/remote/DomainRemote.java 2 ●●● patch | view | raw | blame | history
hsarback/database/database_update.sql
@@ -28,3 +28,14 @@
ALTER TABLE ONLY domain__domain_option
    ADD CONSTRAINT domain_id_fkey FOREIGN KEY (domain_id) 
        REFERENCES domain(domain_id) DEFERRABLE;
update domain set domain_since=domain_filed;
alter table domain drop column domain_free;
alter table domain drop column domain_until;
alter table domain drop column domain_filed;
alter table domain drop column domain_reminder;
alter table domain drop column domain_template;
hsarback/src/de/hsadmin/core/model/AnnFieldIO.java
File was renamed from hsarback/src/de/hsadmin/core/model/AnnFieldValidation.java
@@ -7,6 +7,7 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface AnnFieldValidation {
    String value();
public @interface AnnFieldIO {
    String validation() default "[A-Za-z0-9\\_\\-]";
    ReadWriteAccess rw() default ReadWriteAccess.WRITEONCE;
}
hsarback/src/de/hsadmin/core/model/GenericModuleImpl.java
@@ -81,14 +81,14 @@
    private void validateAllFields(Class<?> clasz, AbstractEntity anEntity)
            throws HSAdminException {
        for (Field f : clasz.getDeclaredFields()) {
            AnnFieldValidation fieldValidation = f.getAnnotation(AnnFieldValidation.class);
            AnnFieldIO fieldValidation = f.getAnnotation(AnnFieldIO.class);
            if (fieldValidation != null) {
                try {
                    Method method = clasz.getMethod(getterName(f));
                    Object valueObject = method.invoke(anEntity);
                    if (valueObject instanceof String) {
                        if (!Pattern.matches(fieldValidation.value(), (String) valueObject)) {
                            throw new HSAdminException("validation of field " + f.getName() + " failed, pattern: " + fieldValidation.value());
                        if (!Pattern.matches(fieldValidation.validation(), (String) valueObject)) {
                            throw new HSAdminException("validation of field " + f.getName() + " failed, pattern: " + fieldValidation.validation());
                        }
                    }
                } catch (Exception e) {
hsarback/src/de/hsadmin/core/model/ReadWriteAccess.java
New file
@@ -0,0 +1,7 @@
package de.hsadmin.core.model;
public enum ReadWriteAccess {
    READONLY, READWRITE, WRITEONLY, WRITEONCE;
}
hsarback/src/de/hsadmin/mods/db/Database.java
@@ -23,7 +23,8 @@
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.core.model.SearchFilter;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
@@ -43,23 +44,24 @@
    @Column(name = "database_id", columnDefinition = "integer", updatable=false, insertable=false)
    private long id;
    @AnnFieldValidation("[a-zA-Z]*")
    @AnnFieldIO(validation="[a-zA-Z]*", rw=ReadWriteAccess.WRITEONCE)
    @Column(name = "engine", columnDefinition = "character varying(12)", updatable=false)
    private String instance;
    @AnnFieldValidation("[a-z0-9\\_]*")
    @AnnFieldIO(validation="[a-z0-9\\_]*", rw=ReadWriteAccess.WRITEONCE)
    @Column(name = "name", columnDefinition = "character varying(24)", updatable=false)
    private String name;
    @AnnFieldValidation("[a-z0-9\\_]*")
    @AnnFieldIO(validation="[a-z0-9\\_]*", rw=ReadWriteAccess.READWRITE)
    @Column(name = "owner", columnDefinition = "character varying(24)")
    private String owner;
    @JoinColumn(name = "packet_id", columnDefinition = "integer", updatable=false)
    @ManyToOne(fetch = EAGER)
    @AnnFieldIO(validation="[a-z0-9]*", rw=ReadWriteAccess.WRITEONCE)
    private Pac pac;
    @AnnFieldValidation("[A-Za-z0-9\\_\\-]*")
    @AnnFieldIO(validation="[A-Za-z0-9\\_\\-]*", rw=ReadWriteAccess.WRITEONCE)
    @Column(name = "encoding", columnDefinition = "character varying(24)", updatable=false)
    private String encoding;
hsarback/src/de/hsadmin/mods/db/DatabaseUser.java
@@ -24,7 +24,8 @@
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
@@ -42,20 +43,21 @@
    @Column(name = "dbuser_id", columnDefinition = "integer", updatable=false, insertable=false)
    private long id;
    @AnnFieldValidation("[a-z0-9\\_]*")
    @AnnFieldIO(validation="[a-z0-9\\_]*", rw=ReadWriteAccess.WRITEONCE)
    @Column(name = "name", columnDefinition = "character varying(24)", updatable=false)
    private String name;
    @AnnFieldValidation("[^']*")
    @AnnFieldIO(validation="[^']*", rw=ReadWriteAccess.WRITEONLY)
    @Transient
    private String password;
    @AnnFieldValidation("[a-zA-Z]*")
    @AnnFieldIO(validation="[a-zA-Z]*", rw=ReadWriteAccess.WRITEONCE)
    @Column(name = "engine", columnDefinition = "character varying(12)", updatable=false)
    protected String instance;
    @JoinColumn(name = "packet_id", columnDefinition = "integer", updatable=false)
    @ManyToOne(fetch = EAGER)
    @AnnFieldIO(validation="[a-z0-9]*", rw=ReadWriteAccess.WRITEONCE)
    protected Pac pac;
    protected DatabaseUser() {
hsarback/src/de/hsadmin/mods/dom/Domain.java
@@ -22,8 +22,9 @@
import javax.persistence.Temporal;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.AnnModuleImpl;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.mods.user.UnixUser;
@Entity(name = "Domains")
@@ -37,38 +38,25 @@
    @GeneratedValue(strategy = SEQUENCE, generator = "DomainsSeqGen")
    private long id;
    @AnnFieldValidation("([-a-z0-9]+\\.)+[a-z]{2,}")
    @AnnFieldIO(validation="([-a-z0-9]+\\.)+[a-z]{2,}", rw=ReadWriteAccess.WRITEONCE)
    @Column(name = "domain_name", columnDefinition = "character varying(256)", nullable = false)
    private String name;
    @AnnFieldIO(rw=ReadWriteAccess.WRITEONCE)
    @JoinColumn(name = "domain_owner", columnDefinition = "integer", nullable = false)
    @ManyToOne(fetch = EAGER)
    private UnixUser user;
    @AnnFieldValidation("[a-z]*")
    @Column(name = "domain_status", columnDefinition = "character varying(12)", nullable = false)
    private String status;
    @Column(name = "domain_status_changed", columnDefinition = "date", nullable = false)
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date statusChanged;
    @Column(name = "domain_filed", columnDefinition = "date")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date filed;
    @AnnFieldIO(validation="[0-9\\.\\/\\-]*", rw=ReadWriteAccess.READONLY)
    @Column(name = "domain_since", columnDefinition = "date")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date since;
    @Column(name = "domain_until", columnDefinition = "date")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date until;
    @AnnFieldValidation("[a-z0-9\\-\\.]*")
    @AnnFieldIO(validation="[a-z0-9\\-\\.]*", rw=ReadWriteAccess.WRITEONCE)
    @Column(name = "domain_dns_master", columnDefinition = "character varying(64)")
    private String dnsMaster;
    @AnnFieldIO(validation="[a-zA-Z0-9\\-\\.]*", rw=ReadWriteAccess.READWRITE)
    @ManyToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
    @JoinTable(name="domain__domain_option", 
        joinColumns={@JoinColumn(name="domain_id", referencedColumnName="domain_id")},
@@ -81,8 +69,6 @@
    public Domain(String name, UnixUser user) {
        this.name = name;
        this.user = user;
        this.statusChanged = new java.util.Date();
        this.status = Status.FILED.toString();
    }
    public static String createQueryFromStringKey(String humanKey) {
@@ -123,44 +109,12 @@
        this.user = user;
    }
    public Status getStatus() {
        return Status.valueFor(status);
    }
    public void setStatus(Status status) {
        this.status = status.toString();
    }
    public Date getStatusChanged() {
        return statusChanged;
    }
    public void setStatusChanged(Date statusChanged) {
        this.statusChanged = statusChanged;
    }
    public Date getFiled() {
        return filed;
    }
    public void setFiled(Date filed) {
        this.filed = filed;
    }
    public Date getSince() {
        return since;
    }
    public void setSince(Date since) {
        this.since = since;
    }
    public Date getUntil() {
        return until;
    }
    public void setUntil(Date until) {
        this.until = until;
    }
    public String getDnsMaster() {
@@ -224,42 +178,6 @@
    public void setDomainOptions(Set<DomainOption> domainOptions) {
        this.domainOptions = domainOptions;
    }
    public static enum Status {
        NONE(""),
        ERROR("error"),
        FILED("filed"),
        SELF("self"),
        REGISTERING("registering"),
        REGISTERED("registered"),
        TRANSFERRING("transferring"),
        NACK_RECEIVED("KK-NACK"),
        ACK_RECEIVED("KK-ACK"),
        MANAGED("connected"),
        LEAVE_SIGNALLED("KK-sig"),
        LEAVING("leaving"),
        GONE("gone"),
        CLOSE_REQUESTED("CLO-req"),
        CLOSING("closing"),
        CLOSED("closed");
        private Status(String aValue) {
            this.aValue = aValue;
        }
        public String toString() {
            return aValue;
        }
        private String aValue;
        public static Status valueFor(String str) {
            for (Status val : Status.values())
                if (val.toString().equals(str))
                    return val;
            return null;
        }
    }
}
hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
@@ -12,7 +12,6 @@
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.mods.dom.Domain.Status;
import de.hsadmin.mods.email.EMailAddress;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
@@ -81,9 +80,7 @@
    public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
        Domain dom = (Domain) newEntity;
        Date now = new Date();
        dom.setFiled(now);
        dom.setStatus(Status.SELF);
        dom.setStatusChanged(now);
        dom.setSince(now);
        dom.setDnsMaster("dns.hostsharing.net");
        if (dom.getName() == null || dom.getName().length() == 0) {
            throw new HSAdminException("domain name required");
hsarback/src/de/hsadmin/mods/dom/DomainOption.java
@@ -15,7 +15,8 @@
import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.mods.user.UnixUser;
@Table(name="domain_option")
@@ -28,7 +29,7 @@
    @GeneratedValue(strategy = SEQUENCE, generator = "DomainOptionSeqGen")
    private long id;
    @AnnFieldValidation("[a-z0-9]+")
    @AnnFieldIO(validation="[a-z0-9]+", rw=ReadWriteAccess.READONLY)
    @Column(name = "domain_option_name", columnDefinition = "character varying(256)", nullable = false)
    private String name;
hsarback/src/de/hsadmin/mods/email/EMailAddress.java
@@ -17,9 +17,10 @@
import javax.persistence.Transient;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.model.AnnModuleImpl;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.core.model.SearchFilter;
import de.hsadmin.mods.dom.Domain;
import de.hsadmin.mods.user.UnixUser;
@@ -43,19 +44,20 @@
    @Column(name = "emailaddr_id", columnDefinition = "integer")
    private long id;
    
    @AnnFieldValidation("[A-Za-z0-9\\_\\-\\.\\+]*")
    @AnnFieldIO(validation="[A-Za-z0-9\\_\\-\\.\\+]*", rw=ReadWriteAccess.WRITEONCE)
    @Column(name = "localpart", updatable = false, nullable= false)
    private String localpart = "";
    
    @AnnFieldValidation("[a-z0-9\\-\\.]*")
    @AnnFieldIO(validation="[a-z0-9\\-\\.]*", rw=ReadWriteAccess.WRITEONCE)
    @Column(name = "subdomain")
    private String subdomain;
    
    @AnnFieldIO(validation="[a-z0-9\\-\\.]*", rw=ReadWriteAccess.WRITEONCE)
    @ManyToOne(fetch = EAGER)
    @JoinColumn(name = "domain_id", columnDefinition = "integer", updatable = false)
    private Domain domain;
    
    @AnnFieldValidation("[\\x20-\\x7E]*")
    @AnnFieldIO(validation="[\\x20-\\x7E]*", rw=ReadWriteAccess.READWRITE)
    @Column(name = "target", nullable= false)
    private String target;
hsarback/src/de/hsadmin/mods/email/EMailAlias.java
@@ -18,8 +18,9 @@
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.AnnModuleImpl;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.core.model.SearchFilter;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
@@ -44,13 +45,14 @@
    @ManyToOne()
    @JoinColumn(name = "pac_id", columnDefinition = "integer")
    @AnnFieldIO(validation="[a-z0-9]*", rw=ReadWriteAccess.WRITEONCE)
    private Pac pac;
    @AnnFieldValidation("[a-z0-9\\_\\-\\.\\+]*")
    @AnnFieldIO(validation="[a-z0-9\\_\\-\\.\\+]*", rw=ReadWriteAccess.WRITEONCE)
    @Column(updatable=false)
    private String name;
    @AnnFieldValidation("[\\x20-\\x7E]*")
    @AnnFieldIO(validation="[\\x20-\\x7E]*", rw=ReadWriteAccess.READWRITE)
    @Column
    private String target;
hsarback/src/de/hsadmin/mods/user/UnixUser.java
@@ -17,8 +17,9 @@
import javax.persistence.Transient;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.AnnModuleImpl;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.core.util.Config;
import de.hsadmin.mods.pac.Pac;
@@ -32,43 +33,47 @@
    @Id
    @GeneratedValue(strategy = SEQUENCE, generator = "UnixUsersSeqGen")
    @Column(name = "unixuser_id", columnDefinition = "integer", updatable=false, insertable=false)
    @Column(name="unixuser_id", columnDefinition="integer", updatable=false, insertable=false)
    private long id;
    // attribute userid - really NOT unique!
    @Column(name = "userid", columnDefinition = "integer", nullable = false, updatable=false)
    @Column(name="userid", columnDefinition="integer", nullable=false, updatable=false)
    private long userId;
    @AnnFieldValidation("[a-z0-9\\_\\-\\.]*")
    @Column(name = "name", columnDefinition = "character varying(24)", unique = true, updatable=false)
    @AnnFieldIO(validation="[a-z0-9\\_\\-\\.]*", rw=ReadWriteAccess.WRITEONCE)
    @Column(name="name", columnDefinition = "character varying(24)", unique=true, updatable=false)
    private String name;
    @AnnFieldValidation("[^:]*")
    @AnnFieldIO(validation="[^:]*", rw=ReadWriteAccess.WRITEONLY)
    @Transient
    private String password;
    @AnnFieldIO(validation="[a-z0-9]*", rw=ReadWriteAccess.WRITEONCE)
    @JoinColumn(name = "packet_id", columnDefinition = "integer", updatable=false)
    @ManyToOne(fetch = EAGER)
    private Pac pac;
    @AnnFieldValidation("[a-zA-Z0-9\\_\\-\\.\\,\\ ]*")
    @AnnFieldIO(validation="[a-zA-Z0-9\\_\\-\\.\\,\\ ]*", rw=ReadWriteAccess.READWRITE)
    @Column(name = "comment", columnDefinition = "character varying(128)")
    private String comment;
    @AnnFieldValidation("[a-z\\/]*")
    @AnnFieldIO(validation="[a-z\\/]*", rw=ReadWriteAccess.READWRITE)
    @Column(name = "shell", columnDefinition = "character varying(32)")
    private String shell;
    @AnnFieldValidation("[a-z0-9\\/\\_\\-\\.]*")
    @AnnFieldIO(validation="[a-z0-9\\/\\_\\-\\.]*", rw=ReadWriteAccess.WRITEONCE)
    @Column(name = "homedir", columnDefinition = "character varying(48)", updatable=false)
    private String homedir;
    @AnnFieldIO(rw=ReadWriteAccess.READWRITE)
    @Column(name = "locked", columnDefinition = "boolean")
    private boolean locked;
    @AnnFieldIO(validation="[0-9]*", rw=ReadWriteAccess.READWRITE)
    @Column(name = "quota_softlimit", columnDefinition = "integer")
    private Integer quotaSoftlimit;
    @AnnFieldIO(validation="[0-9]*", rw=ReadWriteAccess.READWRITE)
    @Column(name = "quota_hardlimit", columnDefinition = "integer")
    private Integer quotaHardlimit;
hsarback/src/de/hsadmin/remote/DomainRemote.java
@@ -36,7 +36,7 @@
        resultMap.put("hive", hive);
        String pac = dom.getUser().getPac().getName();
        resultMap.put("pac", pac);
        Date sDate = dom.getFiled();
        Date sDate = dom.getSince();
        if (assertNotNull(sDate)) {
            String since = df.format(sDate);
            resultMap.put("since", since);