@Test
  public void shouldSetRelayStateForSamlGetRequests() throws Exception {
    HttpMessage requestMessage = TestConstants.samlGetRequestMessage;
    SAMLMessage samlMessage = new SAMLMessage(requestMessage);
    samlMessage.setRelayState("newValueReq");
    HttpMessage changedHttpMessage = samlMessage.getChangedMessage();
    String relayState = new SAMLMessage(changedHttpMessage).getRelayState();
    assertEquals(relayState.trim(), "newValueReq");

    HttpMessage responseMessage = TestConstants.samlGetResponseMessage;
    samlMessage = new SAMLMessage(responseMessage);
    samlMessage.setRelayState("newValueRsp");
    changedHttpMessage = samlMessage.getChangedMessage();
    relayState = new SAMLMessage(changedHttpMessage).getRelayState();
    assertEquals(relayState.trim(), "newValueRsp");
  }
Exemplo n.º 2
0
  @Override
  public boolean onHttpRequestSend(HttpMessage message) {
    if (isActive() && SAMLUtils.hasSAMLMessage(message)) {
      try {
        SAMLMessage samlMessage = new SAMLMessage(message);

        // change the params
        for (Attribute attribute : configuration.getAutoChangeAttributes()) {
          String value = attribute.getValue().toString();
          boolean changed = samlMessage.changeAttributeValueTo(attribute.getName(), value);
          if (changed) {
            log.debug(attribute.getName() + ": value changed to " + value);
          }
        }

        // change the original message
        HttpMessage changedMessege = samlMessage.getChangedMessage();
        if (changedMessege != message) {
          // check for reference, if they are same the message is already changed,
          // else the header and body are changed
          message.setRequestBody(changedMessege.getRequestBody());
          message.setRequestHeader(changedMessege.getRequestHeader());
        }

      } catch (SAMLException ignored) {
      }
    }
    return true;
  }