Commit 14b9adc6 authored by michael.simon's avatar michael.simon
Browse files

Attribute source updates in user update

parent 358d813b
......@@ -25,10 +25,13 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource
prop = new PropertyReader(asUserAttr.getAttributeSource().getAsProps());
}
protected void createOrUpdateValue(String key, Object o, ASUserAttrEntity asUserAttr, ASUserAttrValueDao asValueDao, AttributeSourceAuditor auditor) {
protected Boolean createOrUpdateValue(String key, Object o, ASUserAttrEntity asUserAttr, ASUserAttrValueDao asValueDao, AttributeSourceAuditor auditor) {
Boolean changed = false;
if (o == null || key == null) {
logger.warn("Null keys or values cannot be updated");
return;
return changed;
}
if (o instanceof String) {
......@@ -40,6 +43,7 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource
asValue.setKey(key);
asValue.setAsUserAttr(asUserAttr);
auditor.logAction("as-workflow", "CREATE VALUE (String)", key, "", AuditStatus.SUCCESS);
changed = true;
}
else if (! (asValue instanceof ASUserAttrValueStringEntity)) {
asValueDao.delete(asValue);
......@@ -48,11 +52,13 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource
asValue.setKey(key);
asValue.setAsUserAttr(asUserAttr);
auditor.logAction("as-workflow", "CREATE VALUE (String)", key, "", AuditStatus.SUCCESS);
changed = true;
}
ASUserAttrValueStringEntity asStringValue = (ASUserAttrValueStringEntity) asValue;
if (! value.equals(asStringValue.getValueString())) {
auditor.logAction("as-workflow", "UPDATE VALUE (String)", key, asStringValue.getValueString() + " -> " + value, AuditStatus.SUCCESS);
asStringValue.setValueString(value);
changed = true;
}
asValueDao.persist(asValue);
......@@ -60,5 +66,7 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource
else {
logger.warn("Cannot process value of type {}", o.getClass());
}
return changed;
}
}
......@@ -9,7 +9,7 @@ import edu.kit.scc.webreg.exc.RegisterException;
public interface AttributeSourceWorkflow extends Serializable {
void pollUserAttributes(ASUserAttrEntity asUserAttr,
Boolean pollUserAttributes(ASUserAttrEntity asUserAttr,
ASUserAttrValueDao asValueDao, AttributeSourceAuditor auditor)
throws RegisterException;
}
......@@ -39,7 +39,9 @@ public class HttpUrlSingleAttributeSource extends
private static final long serialVersionUID = 1L;
@Override
public void pollUserAttributes(ASUserAttrEntity asUserAttr, ASUserAttrValueDao asValueDao, AttributeSourceAuditor auditor) throws RegisterException {
public Boolean pollUserAttributes(ASUserAttrEntity asUserAttr, ASUserAttrValueDao asValueDao, AttributeSourceAuditor auditor) throws RegisterException {
Boolean changed = false;
init(asUserAttr);
......@@ -60,17 +62,17 @@ public class HttpUrlSingleAttributeSource extends
logger.warn("Velocity problem", e);
asUserAttr.setQueryStatus(AttributeSourceQueryStatus.FAIL);
asUserAttr.setQueryMessage(e.getMessage());
return;
return changed;
} catch (MethodInvocationException e) {
logger.warn("Velocity problem", e);
asUserAttr.setQueryStatus(AttributeSourceQueryStatus.FAIL);
asUserAttr.setQueryMessage(e.getMessage());
return;
return changed;
} catch (ResourceNotFoundException e) {
logger.warn("Velocity problem", e);
asUserAttr.setQueryStatus(AttributeSourceQueryStatus.FAIL);
asUserAttr.setQueryMessage(e.getMessage());
return;
return changed;
}
String url = out.toString();
......@@ -88,12 +90,12 @@ public class HttpUrlSingleAttributeSource extends
logger.info("Problem", e);
asUserAttr.setQueryStatus(AttributeSourceQueryStatus.FAIL);
asUserAttr.setQueryMessage(e.getMessage());
return;
return changed;
} catch (IOException e) {
logger.info("Problem", e);
asUserAttr.setQueryStatus(AttributeSourceQueryStatus.FAIL);
asUserAttr.setQueryMessage(e.getMessage());
return;
return changed;
}
HttpEntity entity = response.getEntity();
......@@ -104,13 +106,14 @@ public class HttpUrlSingleAttributeSource extends
ObjectMapper om = new ObjectMapper();
try {
@SuppressWarnings("unchecked")
Map<String, Object> map = om.readValue(r, Map.class);
logger.debug("Got {} values", map.size());
for (Entry<String, Object> entry : map.entrySet()) {
logger.debug("Processing entry {}, value {}", entry.getKey(), entry.getValue());
createOrUpdateValue(entry.getKey(), entry.getValue(), asUserAttr, asValueDao, auditor);
changed |= createOrUpdateValue(entry.getKey(), entry.getValue(), asUserAttr, asValueDao, auditor);
}
asUserAttr.setQueryStatus(AttributeSourceQueryStatus.SUCCESS);
......@@ -138,6 +141,8 @@ public class HttpUrlSingleAttributeSource extends
asUserAttr.setQueryStatus(AttributeSourceQueryStatus.USER_NOT_FOUND);
asUserAttr.setQueryMessage("Status HttpUrlSingleAS is " + response.getStatusLine().getStatusCode());
}
return changed;
}
}
......@@ -39,6 +39,7 @@ import edu.kit.scc.webreg.entity.SamlIdpMetadataEntity;
import edu.kit.scc.webreg.entity.SamlSpConfigurationEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserStatus;
import edu.kit.scc.webreg.entity.as.ASUserAttrEntity;
import edu.kit.scc.webreg.event.EventSubmitter;
import edu.kit.scc.webreg.event.UserEvent;
import edu.kit.scc.webreg.exc.EventSubmitException;
......@@ -46,11 +47,14 @@ import edu.kit.scc.webreg.exc.MetadataException;
import edu.kit.scc.webreg.exc.NoAssertionException;
import edu.kit.scc.webreg.exc.RegisterException;
import edu.kit.scc.webreg.exc.SamlAuthenticationException;
import edu.kit.scc.webreg.service.ASUserAttrService;
import edu.kit.scc.webreg.service.AttributeSourceService;
import edu.kit.scc.webreg.service.HomeOrgGroupService;
import edu.kit.scc.webreg.service.SamlIdpMetadataService;
import edu.kit.scc.webreg.service.SamlSpConfigurationService;
import edu.kit.scc.webreg.service.UserService;
import edu.kit.scc.webreg.service.UserUpdateService;
import edu.kit.scc.webreg.service.reg.AttributeSourceQueryService;
import edu.kit.scc.webreg.service.saml.AttributeQueryHelper;
import edu.kit.scc.webreg.service.saml.Saml2AssertionService;
import edu.kit.scc.webreg.service.saml.SamlHelper;
......@@ -88,6 +92,12 @@ public class UserUpdateServiceImpl implements UserUpdateService {
@Inject
private SamlSpConfigurationService spService;
@Inject
private ASUserAttrService asUserAttrService;
@Inject
private AttributeSourceQueryService attributeSourceQueryService;
@Inject
private AttributeMapHelper attrHelper;
......@@ -156,6 +166,11 @@ public class UserUpdateServiceImpl implements UserUpdateService {
}
}
List<ASUserAttrEntity> asUserAttrList = asUserAttrService.findForUser(user);
for (ASUserAttrEntity asUserAttr : asUserAttrList) {
changed |= attributeSourceQueryService.updateUserAttributes(user, asUserAttr.getAttributeSource(), executor);
}
user.setLastUpdate(new Date());
user.setLastFailedUpdate(null);
user.setGroups(null);
......
......@@ -8,7 +8,7 @@ import edu.kit.scc.webreg.exc.RegisterException;
public interface AttributeSourceQueryService extends Serializable {
void updateUserAttributes(UserEntity user,
Boolean updateUserAttributes(UserEntity user,
AttributeSourceEntity attributeSource, String executor)
throws RegisterException;
}
......@@ -54,9 +54,11 @@ public class AttributeSourceQueryServiceImpl implements AttributeSourceQueryServ
private ApplicationConfig appConfig;
@Override
public void updateUserAttributes(UserEntity user, AttributeSourceEntity attributeSource, String executor)
public Boolean updateUserAttributes(UserEntity user, AttributeSourceEntity attributeSource, String executor)
throws RegisterException {
Boolean changed = false;
attributeSource = attributeSourceDao.findByIdWithAttrs(attributeSource.getId(), "asProps");
user = userDao.findById(user.getId());
......@@ -72,7 +74,7 @@ public class AttributeSourceQueryServiceImpl implements AttributeSourceQueryServ
if (asUserAttr != null && asUserAttr.getLastQuery() != null &&
(System.currentTimeMillis() - asUserAttr.getLastQuery().getTime()) < expireTime) {
logger.info("Skipping attribute source query {} for user {}. Data not expired.", attributeSource.getName(), user.getEppn());
return;
return changed;
}
if (asUserAttr == null) {
......@@ -93,8 +95,8 @@ public class AttributeSourceQueryServiceImpl implements AttributeSourceQueryServ
auditor.setName(attributeSource.getName() + "-AttributeSource-Audit");
auditor.setDetail("Updating attributes for user " + user.getEppn());
auditor.setAsUserAttr(asUserAttr);
workflow.pollUserAttributes(asUserAttr, asValueDao, auditor);
changed = workflow.pollUserAttributes(asUserAttr, asValueDao, auditor);
if (AttributeSourceQueryStatus.SUCCESS.equals(asUserAttr.getQueryStatus())) {
asUserAttr.setLastSuccessfulQuery(new Date());
......@@ -102,7 +104,9 @@ public class AttributeSourceQueryServiceImpl implements AttributeSourceQueryServ
asUserAttr.setLastQuery(new Date());
asUserAttr = asUserAttrDao.persist(asUserAttr);
auditor.finishAuditTrail();
auditor.finishAuditTrail();
return changed;
}
public AttributeSourceWorkflow getWorkflowInstance(String className) {
......
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