Search in sources :

Example 6 with Renewing

use of org.apache.cxf.sts.request.Renewing in project cxf by apache.

the class SAMLTokenRenewerLifetimeTest method createSAMLAssertion.

private Element createSAMLAssertion(String tokenType, Crypto crypto, String signatureUsername, CallbackHandler callbackHandler, long ttlMs, boolean allowRenewing, boolean allowRenewingAfterExpiry) 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);
    Renewing renewing = new Renewing();
    renewing.setAllowRenewing(allowRenewing);
    renewing.setAllowRenewingAfterExpiry(allowRenewingAfterExpiry);
    providerParameters.getTokenRequirements().setRenewing(renewing);
    if (ttlMs != 0) {
        Instant creationTime = Instant.now();
        Instant expirationTime = creationTime.plusNanos(ttlMs * 1000000L);
        Lifetime lifetime = new Lifetime();
        lifetime.setCreated(creationTime.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true)));
        lifetime.setExpires(expirationTime.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true)));
        providerParameters.getTokenRequirements().setLifetime(lifetime);
    }
    TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
    assertTrue(providerResponse != null);
    assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
    return (Element) providerResponse.getToken();
}
Also used : Lifetime(org.apache.cxf.sts.request.Lifetime) SAMLTokenProvider(org.apache.cxf.sts.token.provider.SAMLTokenProvider) Renewing(org.apache.cxf.sts.request.Renewing) Instant(java.time.Instant) Element(org.w3c.dom.Element) DefaultConditionsProvider(org.apache.cxf.sts.token.provider.DefaultConditionsProvider) TokenProviderResponse(org.apache.cxf.sts.token.provider.TokenProviderResponse) TokenProviderParameters(org.apache.cxf.sts.token.provider.TokenProviderParameters)

Aggregations

Instant (java.time.Instant)6 Renewing (org.apache.cxf.sts.request.Renewing)6 Element (org.w3c.dom.Element)6 Lifetime (org.apache.cxf.sts.request.Lifetime)5 DefaultConditionsProvider (org.apache.cxf.sts.token.provider.DefaultConditionsProvider)5 SAMLTokenProvider (org.apache.cxf.sts.token.provider.SAMLTokenProvider)5 TokenProviderResponse (org.apache.cxf.sts.token.provider.TokenProviderResponse)5 TokenProviderParameters (org.apache.cxf.sts.token.provider.TokenProviderParameters)4 JAXBElement (javax.xml.bind.JAXBElement)1 TokenRequirements (org.apache.cxf.sts.request.TokenRequirements)1 TokenProvider (org.apache.cxf.sts.token.provider.TokenProvider)1 RealmProperties (org.apache.cxf.sts.token.realm.RealmProperties)1 STSException (org.apache.cxf.ws.security.sts.provider.STSException)1 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)1 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)1 WSSConfig (org.apache.wss4j.dom.engine.WSSConfig)1 SecurityContextToken (org.apache.wss4j.dom.message.token.SecurityContextToken)1 Document (org.w3c.dom.Document)1