net.sf.ahtutils.db.ejb.security.SecurityInitRoles Maven / Gradle / Ivy
package net.sf.ahtutils.db.ejb.security;
import net.sf.ahtutils.controller.interfaces.UtilsSecurityFacade;
import net.sf.ahtutils.db.ejb.AhtDbEjbUpdater;
import net.sf.ahtutils.exception.ejb.UtilsContraintViolationException;
import net.sf.ahtutils.exception.ejb.UtilsIntegrityException;
import net.sf.ahtutils.exception.ejb.UtilsLockingException;
import net.sf.ahtutils.exception.ejb.UtilsNotFoundException;
import net.sf.ahtutils.exception.processing.UtilsConfigurationException;
import net.sf.ahtutils.model.interfaces.idm.UtilsUser;
import net.sf.ahtutils.model.interfaces.security.UtilsSecurityAction;
import net.sf.ahtutils.model.interfaces.security.UtilsSecurityCategory;
import net.sf.ahtutils.model.interfaces.security.UtilsSecurityRole;
import net.sf.ahtutils.model.interfaces.security.UtilsSecurityUsecase;
import net.sf.ahtutils.model.interfaces.security.UtilsSecurityView;
import net.sf.ahtutils.model.interfaces.status.UtilsDescription;
import net.sf.ahtutils.model.interfaces.status.UtilsLang;
import net.sf.ahtutils.xml.access.Access;
import net.sf.ahtutils.xml.access.Category;
import net.sf.ahtutils.xml.access.Role;
import net.sf.ahtutils.xml.access.Usecase;
import net.sf.ahtutils.xml.access.Usecases;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SecurityInitRoles ,
R extends UtilsSecurityRole,
V extends UtilsSecurityView,
U extends UtilsSecurityUsecase,
A extends UtilsSecurityAction,
USER extends UtilsUser>
extends AbstractSecurityInit
{
final static Logger logger = LoggerFactory.getLogger(SecurityInitRoles.class);
private AhtDbEjbUpdater updateRole;
public SecurityInitRoles(final Class cL, final Class cD,final Class cC,final Class cR, final Class cV,final Class cU,final Class cA,final Class cUser,UtilsSecurityFacade fAcl)
{
super(cL,cD,cC,cR,cV,cU,cA,cUser,fAcl);
}
public void iuRoles(Access access) throws UtilsConfigurationException
{
updateRole = AhtDbEjbUpdater.createFactory(cR);
updateRole.dbEjbs(fSecurity.all(cR));
iuCategory(access, UtilsSecurityCategory.Type.role);
updateRole.remove(fSecurity);
logger.trace("iuRoles finished");
}
@Override protected void iuChilds(C aclCategory, Category category) throws UtilsConfigurationException
{
if(category.isSetRoles() && category.getRoles().isSetRole())
{
for(Role role : category.getRoles().getRole())
{
updateRole.actualAdd(role.getCode());
iuRole(aclCategory, role);
}
}
}
private void iuRole(C category, Role role) throws UtilsConfigurationException
{
R aclRole;
try
{
aclRole = fSecurity.fByCode(cR,role.getCode());
ejbLangFactory.rmLang(fSecurity,aclRole);
ejbDescriptionFactory.rmDescription(fSecurity,aclRole);
}
catch (UtilsNotFoundException e)
{
try
{
aclRole = cR.newInstance();
aclRole.setCategory(category);
aclRole.setCode(role.getCode());
aclRole = fSecurity.persist(aclRole);
}
catch (InstantiationException e2) {throw new UtilsConfigurationException(e2.getMessage());}
catch (IllegalAccessException e2) {throw new UtilsConfigurationException(e2.getMessage());}
catch (UtilsContraintViolationException e2) {throw new UtilsConfigurationException(e2.getMessage());}
}
try
{
aclRole.setName(ejbLangFactory.getLangMap(role.getLangs()));
aclRole.setDescription(ejbDescriptionFactory.create(role.getDescriptions()));
aclRole.setCategory(category);
aclRole=fSecurity.update(aclRole);
aclRole = iuListViews(aclRole, role.getViews());
aclRole = iuListActions(aclRole, role.getActions());
aclRole = iuUsecasesForRole(aclRole, role.getUsecases());
}
catch (UtilsContraintViolationException e) {logger.error("",e);}
catch (InstantiationException e) {logger.error("",e);}
catch (IllegalAccessException e) {logger.error("",e);}
catch (UtilsIntegrityException e) {logger.error("",e);}
catch (UtilsNotFoundException e) {throw new UtilsConfigurationException(e.getMessage());}
catch (UtilsLockingException e) {logger.error("",e);}
}
private R iuUsecasesForRole(R ejb, Usecases usecases) throws UtilsContraintViolationException, UtilsNotFoundException, UtilsLockingException
{
ejb.getUsecases().clear();
ejb = fSecurity.update(ejb);
if(usecases!=null)
{
for(Usecase usecase : usecases.getUsecase())
{
U ejbUsecase = fSecurity.fByCode(cU, usecase.getCode());
ejb.getUsecases().add(ejbUsecase);
}
ejb = fSecurity.update(ejb);
}
return ejb;
}
}