alias pruefen

This commit is contained in:
Peter Hormanns 2011-05-20 15:25:11 +00:00
parent 835dbfaaab
commit 68f5d00edf

View File

@ -2,10 +2,14 @@ package de.hsadmin.mods.email;
import java.util.List; import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import de.hsadmin.core.model.AbstractEntity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl; import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException; import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.HSAdminException; import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.mods.pac.Pac;
public class EMailAliasModuleImpl extends AbstractModuleImpl { public class EMailAliasModuleImpl extends AbstractModuleImpl {
@ -22,11 +26,15 @@ public class EMailAliasModuleImpl extends AbstractModuleImpl {
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException { public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
EMailAlias alias = (EMailAlias) newEntity; EMailAlias alias = (EMailAlias) newEntity;
String name = alias.getName(); String name = alias.getName();
String pacname = alias.getPac().getName(); if (name.length() > 5 && (name.charAt(5) != '-') || name.length() == 6) {
if (!name.startsWith(pacname)) {
throw new AuthorisationException(getLoginUser(), "add", newEntity); throw new AuthorisationException(getLoginUser(), "add", newEntity);
} }
if (name.length() > 5 && (name.charAt(5) != '-') || name.length() == 6) { EntityManager em = getTransaction().getEntityManager();
Query qPac = em.createQuery("SELECT obj FROM Pacs obj WHERE obj.name = :pacName");
qPac.setParameter("pacName", name.substring(0, 5));
Object singleResult = qPac.getSingleResult();
Pac pac = (Pac) singleResult;
if (pac == null || !pac.isReadAllowedFor(getLoginUser())) {
throw new AuthorisationException(getLoginUser(), "add", newEntity); throw new AuthorisationException(getLoginUser(), "add", newEntity);
} }
return super.add(newEntity); return super.add(newEntity);