Database Namen pruefen

This commit is contained in:
Peter Hormanns 2011-05-20 14:25:45 +00:00
parent 32e231850e
commit 2cdb8a77ff
5 changed files with 56 additions and 5 deletions

View File

@ -21,6 +21,20 @@ public class MySqlDatabaseModuleImpl extends AbstractModuleImpl {
return super.search(entityClass, condition, orderBy);
}
@Override
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
MySqlDatabase database = (MySqlDatabase) newEntity;
String name = database.getName();
String pacname = database.getPac().getName();
if (!name.startsWith(pacname) || name.length() < 7) {
throw new AuthorisationException(getLoginUser(), "add", newEntity);
}
if (name.charAt(5) != '_') {
throw new AuthorisationException(getLoginUser(), "add", newEntity);
}
return super.add(newEntity);
}
@Override
public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException {
EntityManager em = getTransaction().getEntityManager();

View File

@ -12,7 +12,15 @@ public class MySqlUserModuleImpl extends AbstractModuleImpl {
@Override
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
MySqlUser user = (MySqlUser) newEntity;
if (user.getName().length() > 16) {
String name = user.getName();
if (name.length() > 16) {
throw new AuthorisationException(getLoginUser(), "add", newEntity);
}
String pacname = user.getPac().getName();
if (!name.startsWith(pacname) || name.length() < 7) {
throw new AuthorisationException(getLoginUser(), "add", newEntity);
}
if (name.charAt(5) != '_') {
throw new AuthorisationException(getLoginUser(), "add", newEntity);
}
return super.add(newEntity);

View File

@ -20,6 +20,20 @@ public class PgSqlDatabaseModuleImpl extends AbstractModuleImpl {
return super.search(entityClass, condition, orderBy);
}
@Override
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
PgSqlDatabase database = (PgSqlDatabase) newEntity;
String name = database.getName();
String pacname = database.getPac().getName();
if (!name.startsWith(pacname) || name.length() < 7) {
throw new AuthorisationException(getLoginUser(), "add", newEntity);
}
if (name.charAt(5) != '_') {
throw new AuthorisationException(getLoginUser(), "add", newEntity);
}
return super.add(newEntity);
}
@Override
public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException {
EntityManager em = getTransaction().getEntityManager();

View File

@ -4,10 +4,25 @@ import java.util.List;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.HSAdminException;
public class PgSqlUserModuleImpl extends AbstractModuleImpl {
@Override
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
PgSqlUser user = (PgSqlUser) newEntity;
String name = user.getName();
String pacname = user.getPac().getName();
if (!name.startsWith(pacname) || name.length() < 7) {
throw new AuthorisationException(getLoginUser(), "add", newEntity);
}
if (name.charAt(5) != '_') {
throw new AuthorisationException(getLoginUser(), "add", newEntity);
}
return super.add(newEntity);
}
@Override
public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass,
String condition, String orderBy) throws HSAdminException {

View File

@ -2,9 +2,9 @@ package de.hsadmin.mods.email;
import java.util.List;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AuthenticationException;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.HSAdminException;
public class EMailAliasModuleImpl extends AbstractModuleImpl {
@ -24,10 +24,10 @@ public class EMailAliasModuleImpl extends AbstractModuleImpl {
String name = alias.getName();
String pacname = alias.getPac().getName();
if (!name.startsWith(pacname)) {
throw new AuthenticationException("alias not allowed");
throw new AuthorisationException(getLoginUser(), "add", newEntity);
}
if (name.length() > 5 && (name.charAt(5) != '-') || name.length() == 6) {
throw new AuthenticationException("alias not allowed");
throw new AuthorisationException(getLoginUser(), "add", newEntity);
}
return super.add(newEntity);
}