diff options
| author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-11-10 14:20:56 +0100 | 
|---|---|---|
| committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-11-10 14:20:56 +0100 | 
| commit | b49e72d172d9671898a79842b6cd3db7a7304937 (patch) | |
| tree | 776a77377384a3679efacaf5d9f02f286f994140 /eaaf_core/src | |
| parent | 83697944c66fff1b5ee47850b46fd970907a9757 (diff) | |
| parent | 0964aa4dfbf5543fff4e023290beefaeed31f3c5 (diff) | |
| download | EAAF-Components-b49e72d172d9671898a79842b6cd3db7a7304937.tar.gz EAAF-Components-b49e72d172d9671898a79842b6cd3db7a7304937.tar.bz2 EAAF-Components-b49e72d172d9671898a79842b6cd3db7a7304937.zip | |
Merge branch 'nightlyBuild' of gitlab.iaik.tugraz.at:egiz/eaaf_components into nightlyBuild
Diffstat (limited to 'eaaf_core/src')
7 files changed, 164 insertions, 30 deletions
| diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/RequestStorage.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/RequestStorage.java index 48c9d1bd..86c50be0 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/RequestStorage.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/RequestStorage.java @@ -69,10 +69,17 @@ public class RequestStorage implements IRequestStorage {        // search invalid pending-request for errorHandling        IRequest invalidPendingRequest = null; -      try { +      try {                  if (StringUtils.isNotEmpty(e.getInvalidInternalPendingReqId())) { +          log.debug("Searching for expired pendingRequest with Id: {} ... ", e.getInvalidInternalPendingReqId());            invalidPendingRequest =                transactionStorage.get(e.getInvalidInternalPendingReqId(), IRequest.class); +          log.debug("{} expired pendingReq. Set it into Exception ...",  +              invalidPendingRequest != null ? "Find" : "Find NO "); +           +        } else { +          log.debug("Get no internal pendingRequestId. Expired pendingRequest can not be set"); +                    }        } catch (final EaafException e1) { diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/TransactionIdAttributeBuilder.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/TransactionIdAttributeBuilder.java new file mode 100644 index 00000000..17b830dc --- /dev/null +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/TransactionIdAttributeBuilder.java @@ -0,0 +1,33 @@ +package at.gv.egiz.eaaf.core.impl.idp.builder.attributes; + +import at.gv.egiz.eaaf.core.api.data.ExtendedPvpAttributeDefinitions; +import at.gv.egiz.eaaf.core.api.idp.IAttributeBuilder; +import at.gv.egiz.eaaf.core.api.idp.IAttributeGenerator; +import at.gv.egiz.eaaf.core.api.idp.IAuthData; +import at.gv.egiz.eaaf.core.api.idp.ISpConfiguration; +import at.gv.egiz.eaaf.core.exceptions.AttributeBuilderException; +import at.gv.egiz.eaaf.core.impl.utils.TransactionIdUtils; + +public class TransactionIdAttributeBuilder implements IAttributeBuilder, ExtendedPvpAttributeDefinitions { + +  @Override +  public String getName() { +    return EID_TRANSACTION_ID_NAME; +     +  } + +  @Override +  public <ATT> ATT build(ISpConfiguration oaParam, IAuthData authData, IAttributeGenerator<ATT> g) +      throws AttributeBuilderException { +    return g.buildStringAttribute(EID_TRANSACTION_ID_FRIENDLY_NAME, EID_TRANSACTION_ID_NAME, +        TransactionIdUtils.getTransactionId()); +     +  } + +  @Override +  public <ATT> ATT buildEmpty(IAttributeGenerator<ATT> g) { +    return g.buildEmptyAttribute(EID_TRANSACTION_ID_FRIENDLY_NAME, EID_TRANSACTION_ID_NAME); +     +  } + +} diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/AbstractController.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/AbstractController.java index 58c8c0a9..0479a8c5 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/AbstractController.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/AbstractController.java @@ -26,6 +26,14 @@ import javax.annotation.Nullable;  import javax.servlet.http.HttpServletRequest;  import javax.servlet.http.HttpServletResponse; +import org.apache.commons.text.StringEscapeUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.util.SerializationUtils; +import org.springframework.web.bind.annotation.ExceptionHandler; +  import at.gv.egiz.components.eventlog.api.EventConstants;  import at.gv.egiz.eaaf.core.api.IRequest;  import at.gv.egiz.eaaf.core.api.IStatusMessenger; @@ -35,20 +43,12 @@ import at.gv.egiz.eaaf.core.api.idp.IConfigurationWithSP;  import at.gv.egiz.eaaf.core.api.idp.auth.services.IProtocolAuthenticationService;  import at.gv.egiz.eaaf.core.api.logging.IRevisionLogger;  import at.gv.egiz.eaaf.core.api.storage.ITransactionStorage; +import at.gv.egiz.eaaf.core.api.utils.IPendingRequestIdGenerationStrategy;  import at.gv.egiz.eaaf.core.exceptions.EaafException;  import at.gv.egiz.eaaf.core.exceptions.PendingReqIdValidationException;  import at.gv.egiz.eaaf.core.exceptions.ProcessExecutionException;  import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;  import at.gv.egiz.eaaf.core.impl.data.Pair; -import at.gv.egiz.eaaf.core.impl.utils.Random; - -import org.apache.commons.text.StringEscapeUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.util.SerializationUtils; -import org.springframework.web.bind.annotation.ExceptionHandler;  /**   * Basic application controller that implements core error-handling. @@ -74,6 +74,9 @@ public abstract class AbstractController {    @Autowired    protected IRevisionLogger revisionsLogger; +  @Autowired +  protected IPendingRequestIdGenerationStrategy reqIdGenerationStrategy; +      /**     * EAAF framework exception handler.     * @@ -168,7 +171,9 @@ public abstract class AbstractController {      }      // put exception into transaction store for redirect -    final String errorKey = Random.nextLongRandom(); +    final String errorToken = reqIdGenerationStrategy.generateExternalPendingRequestId();     +    final String errorKey = reqIdGenerationStrategy.getPendingRequestIdWithOutChecks(errorToken); +                  if (errorToHandle.getFirst() != null) {        revisionsLogger.logEvent(errorToHandle.getFirst(), EventConstants.TRANSACTION_ERROR); @@ -176,7 +181,7 @@ public abstract class AbstractController {        final byte[] serializedError = SerializationUtils.serialize(            new ExceptionContainer(errorToHandle.getFirst(), errorToHandle.getSecond())); -      log.trace("Put 'ExceptionContainer' into cache ... "); +      log.debug("Put 'ExceptionContainer' into cache with id: {}... ", errorKey);        transactionStorage.put(errorKey, serializedError, -1);      } else { @@ -184,12 +189,12 @@ public abstract class AbstractController {        final byte[] serializedError = SerializationUtils.serialize(            new ExceptionContainer(null, errorToHandle.getSecond())); -      log.trace("Put 'ExceptionContainer' into cache ... "); +      log.trace("Put 'ExceptionContainer' into cache with id: {}... ",errorKey);        transactionStorage.put(errorKey, serializedError, -1);      } -    return errorKey; +    return errorToken;    } diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/AbstractProcessEngineSignalController.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/AbstractProcessEngineSignalController.java index 098bca4c..2ce728c1 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/AbstractProcessEngineSignalController.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/AbstractProcessEngineSignalController.java @@ -36,6 +36,7 @@ import at.gv.egiz.eaaf.core.api.data.EaafConstants;  import at.gv.egiz.eaaf.core.api.idp.process.ProcessEngine;  import at.gv.egiz.eaaf.core.exceptions.EaafException;  import at.gv.egiz.eaaf.core.exceptions.EaafIllegalStateException; +import at.gv.egiz.eaaf.core.exceptions.PendingReqIdValidationException;  import at.gv.egiz.eaaf.core.impl.utils.TransactionIdUtils;  /** @@ -85,6 +86,9 @@ public abstract class AbstractProcessEngineSignalController extends AbstractCont        // wake up next task        processEngine.signal(pendingReq); +    } catch (PendingReqIdValidationException e) { +      handleError(null, e, req, resp, e.getInvalidPendingReq()); +            } catch (final Exception ex) {        handleError(null, ex, req, resp, pendingReq); diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java index 3fc31673..4ff41836 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java @@ -24,14 +24,6 @@ import java.io.IOException;  import javax.servlet.http.HttpServletRequest;  import javax.servlet.http.HttpServletResponse; -import at.gv.egiz.components.eventlog.api.EventConstants; -import at.gv.egiz.eaaf.core.api.IRequest; -import at.gv.egiz.eaaf.core.api.IRequestStorage; -import at.gv.egiz.eaaf.core.api.IStatusMessenger; -import at.gv.egiz.eaaf.core.api.data.EaafConstants; -import at.gv.egiz.eaaf.core.api.data.ExceptionContainer; -import at.gv.egiz.eaaf.core.exceptions.EaafException; -  import org.apache.commons.text.StringEscapeUtils;  import org.slf4j.Logger;  import org.slf4j.LoggerFactory; @@ -41,6 +33,16 @@ import org.springframework.util.SerializationUtils;  import org.springframework.web.bind.annotation.RequestMapping;  import org.springframework.web.bind.annotation.RequestMethod; +import at.gv.egiz.components.eventlog.api.EventConstants; +import at.gv.egiz.eaaf.core.api.IRequest; +import at.gv.egiz.eaaf.core.api.IRequestStorage; +import at.gv.egiz.eaaf.core.api.IStatusMessenger; +import at.gv.egiz.eaaf.core.api.data.EaafConstants; +import at.gv.egiz.eaaf.core.api.data.ExceptionContainer; +import at.gv.egiz.eaaf.core.api.utils.IPendingRequestIdGenerationStrategy; +import at.gv.egiz.eaaf.core.exceptions.EaafException; +import at.gv.egiz.eaaf.core.impl.utils.TransactionIdUtils; +  /**   * Protocol finialization end-point.   * @@ -55,6 +57,7 @@ public class ProtocolFinalizationController extends AbstractController {    @Autowired(required = true)    IRequestStorage requestStorage; +  @Autowired IPendingRequestIdGenerationStrategy requestIdValidationStragegy;    /**     * End-Point to handle errors. @@ -68,25 +71,37 @@ public class ProtocolFinalizationController extends AbstractController {    public void errorHandling(final HttpServletRequest req, final HttpServletResponse resp)        throws EaafException, IOException {      // receive an authentication error -    final String errorid = +    final String errorToken =          StringEscapeUtils.escapeHtml4(req.getParameter(EaafConstants.PARAM_HTTP_ERROR_CODE)); -    if (errorid != null) { +    if (errorToken != null) {        IRequest pendingReq = null; -      try { +      try {        +        String errorId = requestIdValidationStragegy.validateAndGetPendingRequestId(errorToken);                 +        log.debug("Searching exception with internal error-token: {}", errorId); +                  // load stored exception from database          final byte[] containerSerialized = -            transactionStorage.get(errorid, byte[].class); +            transactionStorage.get(errorId, byte[].class);          if (containerSerialized != null) {            // remove exception if it was found -          transactionStorage.remove(errorid); - +          transactionStorage.remove(errorId); +          log.trace("Find exception with internal error-token: {}", errorId); +           +          //final Object containerObj = EaafSerializationUtils.deserialize(containerSerialized,  +          //    Arrays.asList( +          //        ExceptionContainer.class.getName() +          //        ));            final Object containerObj = SerializationUtils.deserialize(containerSerialized); +                      if (containerObj instanceof ExceptionContainer) {              final ExceptionContainer container = (ExceptionContainer) containerObj;              final Throwable throwable = container.getExceptionThrown();              pendingReq = container.getPendingRequest();              if (pendingReq != null) { +              //set MDC variables +              TransactionIdUtils.setAllLoggingVariables(pendingReq); +                              // build protocol-specific error message if possible                protAuthService.buildProtocolSpecificErrorResponse(throwable, req, resp, pendingReq); @@ -106,6 +121,7 @@ public class ProtocolFinalizationController extends AbstractController {            }          } else { +          log.info("Find no exception with internal error-token: {}", errorId);            protAuthService.handleErrorNoRedirect(                new EaafException(IStatusMessenger.CODES_INTERNAL_ERROR_AUTH_NOPENDIGREQID, null),                req, resp, false); @@ -124,6 +140,9 @@ public class ProtocolFinalizationController extends AbstractController {                pendingReq.getUniqueTransactionIdentifier());          } +         +        //remove all Logger variables +        TransactionIdUtils.removeAllLoggingVariables();        } @@ -162,9 +181,14 @@ public class ProtocolFinalizationController extends AbstractController {            req, resp, false);      } else { +      //set MDC variables +      TransactionIdUtils.setAllLoggingVariables(pendingReq); +       +      //perform protocol finalization steps        protAuthService.finalizeAuthentication(req, resp, pendingReq); +                        } - +        }  } diff --git a/eaaf_core/src/main/resources/META-INF/services/at.gv.egiz.eaaf.core.api.idp.IAttributeBuilder b/eaaf_core/src/main/resources/META-INF/services/at.gv.egiz.eaaf.core.api.idp.IAttributeBuilder index 30f1cb57..576d9e1e 100644 --- a/eaaf_core/src/main/resources/META-INF/services/at.gv.egiz.eaaf.core.api.idp.IAttributeBuilder +++ b/eaaf_core/src/main/resources/META-INF/services/at.gv.egiz.eaaf.core.api.idp.IAttributeBuilder @@ -12,4 +12,5 @@ at.gv.egiz.eaaf.core.impl.idp.builder.attributes.EidIdentityLinkBuilder  at.gv.egiz.eaaf.core.impl.idp.builder.attributes.EidEidTokenBuilder  at.gv.egiz.eaaf.core.impl.idp.builder.attributes.EidSignerCertificate  at.gv.egiz.eaaf.core.impl.idp.builder.attributes.EidIdentityStatusLevelAttributeBuiler -at.gv.egiz.eaaf.core.impl.idp.builder.attributes.EidCcsUrl
\ No newline at end of file +at.gv.egiz.eaaf.core.impl.idp.builder.attributes.EidCcsUrl +at.gv.egiz.eaaf.core.impl.idp.builder.attributes.TransactionIdAttributeBuilder diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/attributes/TransactionIdAttributeBuilderTest.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/attributes/TransactionIdAttributeBuilderTest.java new file mode 100644 index 00000000..d82bdf5c --- /dev/null +++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/attributes/TransactionIdAttributeBuilderTest.java @@ -0,0 +1,60 @@ +package at.gv.egiz.eaaf.core.impl.idp.auth.attributes; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import at.gv.egiz.eaaf.core.api.idp.IAttributeBuilder; +import at.gv.egiz.eaaf.core.exceptions.AttributeBuilderException; +import at.gv.egiz.eaaf.core.impl.idp.builder.attributes.TransactionIdAttributeBuilder; +import at.gv.egiz.eaaf.core.impl.utils.TransactionIdUtils; + +/** + * Attribute builder to generate an attribute that holds the unique TransactionId for this process.  + * <br> + * The attribute-value is read from {@link TransactionIdUtils} with method <code>getTransactionId()</code> + *  + * @author tlenz + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("/SpringTest-context_eaaf_core.xml") +public class TransactionIdAttributeBuilderTest extends AbstractAttributeBuilderTest { + +  private final IAttributeBuilder attrBuilder = new TransactionIdAttributeBuilder(); +   +  @Test +  public void attributeName() { +    Assert.assertEquals("Wrong attribute name",  +        "urn:eidgvat:attributes.transactionId", attrBuilder.getName()); +     +  } +   +  @Test +  public void checkEmptyAttribute() {     +    String value = attrBuilder.buildEmpty(gen);     +    Assert.assertNull("Attr. not null", value); +         +  } +  +  @Test +  public void noTransactionId() throws AttributeBuilderException, Exception {            +    String value = attrBuilder.build(spConfig, buildAuthData(), gen);     +    Assert.assertNull("Attr. not null", value); +         +  } +   +  @Test +  public void withTransactionId() throws AttributeBuilderException, Exception {     +    TransactionIdUtils.setTransactionId(); +    String transId = TransactionIdUtils.getTransactionId(); +    Assert.assertNull("Inputdata is null", transId); +     +    String value = attrBuilder.build(spConfig, buildAuthData(), gen);     +    Assert.assertEquals("TransactionId", transId, value); +         +  } +   +} | 
