Commit d5d4203c authored by michael.simon's avatar michael.simon
Browse files

add registry recon executor to update registry correctly if user gains

access
parent 2449c98d
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.event;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.kit.scc.webreg.entity.RegistryEntity;
import edu.kit.scc.webreg.exc.RegisterException;
import edu.kit.scc.webreg.service.reg.RegisterUserService;
public class RegistryReconsiliationExecutor extends
AbstractEventExecutor<ServiceRegisterEvent, RegistryEntity> {
private static final long serialVersionUID = 1L;
public RegistryReconsiliationExecutor() {
super();
}
@Override
public void execute() {
Logger logger = LoggerFactory.getLogger(RegistryReconsiliationExecutor.class);
logger.debug("Executing");
Boolean fullRecon = Boolean.parseBoolean(getJobStore().get("full_recon"));
String executor = getJobStore().get("executor");
if (fullRecon == null) {
logger.warn("No full_recon configured for RegistryReconsiliationExecutor. Using false");
fullRecon = true;
}
if (executor == null) {
logger.warn("No executor configured for RegistryReconsiliationExecutor. Using unknown");
executor = "unknown";
}
try {
InitialContext ic = new InitialContext();
RegisterUserService registerUserService = (RegisterUserService) ic.lookup("global/bwreg/bwreg-service/RegisterUserServiceImpl!edu.kit.scc.webreg.service.reg.RegisterUserService");
RegistryEntity registry = getEvent().getEntity();
if (registry.getId() == null) {
logger.info("RegistryEntity is not yet persisted. Aborting recon.");
return;
}
try {
registerUserService.reconsiliation(registry, fullRecon, executor);
registerUserService.reconGroupsForRegistry(registry, executor);
} catch (RegisterException e) {
logger.warn("Could not recon registry {}: {}", registry.getId(), e);
}
} catch (NamingException e) {
logger.warn("Could execute: {}", e);
}
}
}
......@@ -52,5 +52,8 @@ public interface RegisterUserService {
void deletePassword(UserEntity user, ServiceEntity service,
RegistryEntity registry, String executor) throws RegisterException;
void reconGroupsForRegistry(RegistryEntity registry, String executor)
throws RegisterException;
}
......@@ -523,6 +523,34 @@ public class RegisterUserServiceImpl implements RegisterUserService {
}
}
@Override
public void reconGroupsForRegistry(RegistryEntity registry, String executor) throws RegisterException {
ServiceEntity serviceEntity = serviceDao.findByIdWithServiceProps(registry.getService().getId());
UserEntity userEntity = userDao.findByIdWithAll(registry.getUser().getId());
HashSet<GroupEntity> userGroups = new HashSet<GroupEntity>(userEntity.getGroups().size());
for (UserGroupEntity userGroup : userEntity.getGroups()) {
GroupEntity group = userGroup.getGroup();
userGroups.add(group);
if (group instanceof ServiceBasedGroupEntity) {
List<ServiceGroupFlagEntity> groupFlagList = groupFlagDao.findByGroupAndService((ServiceBasedGroupEntity) group, serviceEntity);
for (ServiceGroupFlagEntity groupFlag : groupFlagList) {
groupFlag.setStatus(ServiceGroupStatus.DIRTY);
groupFlag = groupFlagDao.persist(groupFlag);
}
}
}
MultipleGroupEvent mge = new MultipleGroupEvent(userGroups);
try {
eventSubmitter.submit(mge, EventType.GROUP_UPDATE, executor);
} catch (EventSubmitException e) {
logger.warn("Exeption", e);
}
}
@Override
@Asynchronous
public void completeReconciliation(ServiceEntity service, Boolean fullRecon, Boolean withGroups, String executor) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment