/*******************************************************************************
*******************************************************************************/
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 signature of an auth block.
*
* Asynchonous
*
* Requires context data:
*
* - {@code IdentityLink}
* - {@code isIdentityLinkValidated}
* - {@code bkuURL}
*
*
*
* Enriches context data with:
*
* - {@code SignedAuthBlock}
*
*
*
* @author tknall
*
*/
@Service("SignAuthBlockTask")
public class SignAuthBlockTask 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("bkuURL"));
log.debug("Using validated IdentityLink and bkuURL in order to sign auth block.");
try (InputStream in = getClass().getResourceAsStream("/process/spring/test/task/SignedAuthBlock.xml")) {
executionContext.put("SignedAuthBlock", IOUtils.toString(in, "UTF-8"));
} catch (IOException e) {
throw new TaskExecutionException(null, "", e);
}
return null;
}
}