allow customer to read, add and update pacs

This commit is contained in:
Peter Hormanns 2016-09-09 12:56:05 +02:00
parent b329e2f7fe
commit 774f030e01
4 changed files with 11 additions and 7 deletions

View File

@ -2,6 +2,6 @@ package de.hsadmin.login;
public enum Role { public enum Role {
SYSTEM, CUSTOMER, HIVE, PACKET, DOMAIN, USER, NONE, ANY SYSTEM, CUSTOMER, PACKET, DOMAIN, USER, NONE, ANY
} }

View File

@ -51,7 +51,7 @@ public class HiveService extends AbstractModule<HiveVO> implements HiveServiceLo
} }
@Override @Override
@RequiredScope({@ScopePolicy(Role.SYSTEM), @ScopePolicy(value=Role.HIVE, property="name")}) @RequiredScope({@ScopePolicy(Role.SYSTEM)})
public List<HiveVO> read(final RequestContext requestContext, final HiveVO criteria) public List<HiveVO> read(final RequestContext requestContext, final HiveVO criteria)
throws UserException, TechnicalException { throws UserException, TechnicalException {
final List<HiveVO> emptyList = super.read(requestContext, criteria); final List<HiveVO> emptyList = super.read(requestContext, criteria);

View File

@ -39,7 +39,7 @@ public class PacService extends AbstractModule<PacVO> implements PacServiceLocal
} }
@Override @Override
@RequiredScope({@ScopePolicy(Role.SYSTEM)}) @RequiredScope({@ScopePolicy(Role.SYSTEM), @ScopePolicy(Role.CUSTOMER)})
public PacVO create(final RequestContext requestContext, final PacVO prototype) public PacVO create(final RequestContext requestContext, final PacVO prototype)
throws UserException, TechnicalException { throws UserException, TechnicalException {
final PacVO vo = super.create(requestContext, prototype); final PacVO vo = super.create(requestContext, prototype);
@ -59,6 +59,11 @@ public class PacService extends AbstractModule<PacVO> implements PacServiceLocal
bo.setBasePac(findBasePacByName(basePacProperty)); bo.setBasePac(findBasePacByName(basePacProperty));
final String customerProperty = prototype.getCustomer(); final String customerProperty = prototype.getCustomer();
assert customerProperty != null; assert customerProperty != null;
if (Role.CUSTOMER.equals(requestContext.getLoginRole())) {
if (!customerProperty.equals(requestContext.getLoginUser())) {
throw new UserException(new UserError(UserError.MSG_MISSING_AUTHORIZATION, "add"));
}
}
bo.setCustomer(findCustomerByName(customerProperty)); bo.setCustomer(findCustomerByName(customerProperty));
vo.copyPropertiesToPersistentObject(bo); vo.copyPropertiesToPersistentObject(bo);
if (bo.getCreated() == null) { if (bo.getCreated() == null) {
@ -73,7 +78,7 @@ public class PacService extends AbstractModule<PacVO> implements PacServiceLocal
} }
@Override @Override
@RequiredScope({@ScopePolicy(Role.SYSTEM), @ScopePolicy(value=Role.HIVE, property="name"), @ScopePolicy(value=Role.PACKET, property="name")}) @RequiredScope({@ScopePolicy(Role.SYSTEM), @ScopePolicy(Role.CUSTOMER), @ScopePolicy(value=Role.PACKET, property="name")})
public List<PacVO> read(final RequestContext requestContext, final PacVO criteria) public List<PacVO> read(final RequestContext requestContext, final PacVO criteria)
throws UserException, TechnicalException { throws UserException, TechnicalException {
final List<PacVO> emptyList = super.read(requestContext, criteria); final List<PacVO> emptyList = super.read(requestContext, criteria);
@ -87,7 +92,7 @@ public class PacService extends AbstractModule<PacVO> implements PacServiceLocal
} }
@Override @Override
@RequiredScope({@ScopePolicy(Role.SYSTEM)}) @RequiredScope({@ScopePolicy(Role.SYSTEM), @ScopePolicy(Role.CUSTOMER)})
public List<PacVO> update(final RequestContext requestContext, final PacVO criteria, final PacVO prototype) public List<PacVO> update(final RequestContext requestContext, final PacVO criteria, final PacVO prototype)
throws UserException, TechnicalException { throws UserException, TechnicalException {
final List<PacVO> pacsForUpdate = super.update(requestContext, criteria, prototype); final List<PacVO> pacsForUpdate = super.update(requestContext, criteria, prototype);
@ -95,7 +100,7 @@ public class PacService extends AbstractModule<PacVO> implements PacServiceLocal
final Pac bo = findPacByName(vo.getName()); final Pac bo = findPacByName(vo.getName());
final String customerName = prototype.getCustomer(); final String customerName = prototype.getCustomer();
if (customerName != null && !customerName.isEmpty()) { if (customerName != null && !customerName.isEmpty()) {
Customer customer = findCustomerByName(customerName); final Customer customer = findCustomerByName(customerName);
bo.setCustomer(customer); bo.setCustomer(customer);
} }
prototype.copyPropertiesToPersistentObject(bo); prototype.copyPropertiesToPersistentObject(bo);

View File

@ -71,7 +71,6 @@ public class PacVO extends AbstractVO implements ValueObject {
@Search(SearchPolicy.EQUALS) @Search(SearchPolicy.EQUALS)
private Boolean free; private Boolean free;
@Required(true)
@ReadWrite(ReadWritePolicy.WRITEONCE) @ReadWrite(ReadWritePolicy.WRITEONCE)
@Mapping( @Mapping(
boMapping=ReferredStringPersistentObjectMapper.class, boMapping=ReferredStringPersistentObjectMapper.class,