/*******************************************************************************
*******************************************************************************/
package at.gv.egiz.eaaf.core.impl.idp.process.spring.test.task;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import at.gv.egiz.eaaf.core.api.IRequest;
import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext;
import at.gv.egiz.eaaf.core.api.idp.process.Task;
import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
/**
* A dummy task simulating the creation of a SAML1 assertion.
*
* Requires context data:
*
* - {@code IdentityLink}
* - {@code isIdentityLinkValidated}
* - {@code SignedAuthBlock}
* - {@code isSignedAuthBlockValidated}
*
*
*
* Enriches context data with:
*
* - {@code SAML1Assertion}
*
*
*
* @author tknall
*
*/
@Service("CreateSAML1AssertionTask")
public class CreateSAML1AssertionTask implements Task {
private Logger log = LoggerFactory.getLogger(getClass());
@Override
public IRequest execute(IRequest penReq, ExecutionContext executionContext) throws TaskExecutionException {
Objects.requireNonNull(executionContext.get("IdentityLink"));
assert (Boolean.TRUE.equals(Objects.requireNonNull(executionContext.get("isIdentityLinkValidated"))));
Objects.requireNonNull(executionContext.get("SignedAuthBlock"));
assert (Boolean.TRUE.equals(Objects.requireNonNull(executionContext.get("isSignedAuthBlockValidated"))));
log.debug("Using IdentityLink and signed auth block in order to create SAML1 assertion.");
try (InputStream in = getClass().getResourceAsStream("/process/spring/test/task/SAML1Assertion.xml")) {
executionContext.put("SAML1Assertion", IOUtils.toString(in, "UTF-8"));
} catch (IOException e) {
throw new TaskExecutionException(null, "", e);
}
return null;
}
}