Beispiel #1
0
  /*
   * Mock up an SAML assertion element
   */
  private Element createSAMLAssertion(
      String tokenType,
      Crypto crypto,
      String signatureUsername,
      CallbackHandler callbackHandler,
      Map<String, RealmProperties> realms,
      String user,
      String issuer)
      throws WSSecurityException {
    SAMLTokenProvider samlTokenProvider = new SAMLTokenProvider();
    samlTokenProvider.setRealmMap(realms);

    TokenProviderParameters providerParameters =
        createProviderParameters(
            tokenType,
            STSConstants.BEARER_KEY_KEYTYPE,
            crypto,
            signatureUsername,
            callbackHandler,
            user,
            issuer);
    if (realms != null) {
      providerParameters.setRealm("A");
    }
    TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
    assertTrue(providerResponse != null);
    assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);

    return (Element) providerResponse.getToken();
  }
  private Element createSAMLAssertion(
      String tokenType,
      Crypto crypto,
      String signatureUsername,
      CallbackHandler callbackHandler,
      long ttlMs)
      throws WSSecurityException {
    SAMLTokenProvider samlTokenProvider = new SAMLTokenProvider();
    DefaultConditionsProvider conditionsProvider = new DefaultConditionsProvider();
    conditionsProvider.setAcceptClientLifetime(true);
    samlTokenProvider.setConditionsProvider(conditionsProvider);
    TokenProviderParameters providerParameters =
        createProviderParameters(
            tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername, callbackHandler);

    if (ttlMs != 0) {
      Lifetime lifetime = new Lifetime();
      Date creationTime = new Date();
      Date expirationTime = new Date();
      expirationTime.setTime(creationTime.getTime() + ttlMs);

      XmlSchemaDateFormat fmt = new XmlSchemaDateFormat();
      lifetime.setCreated(fmt.format(creationTime));
      lifetime.setExpires(fmt.format(expirationTime));

      providerParameters.getTokenRequirements().setLifetime(lifetime);
    }

    TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
    assertTrue(providerResponse != null);
    assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);

    return providerResponse.getToken();
  }