Java Code Examples for org.apache.cxf.rs.security.oauth2.utils.OAuthUtils#generateRandomTokenKey()

The following examples show how to use org.apache.cxf.rs.security.oauth2.utils.OAuthUtils#generateRandomTokenKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemoryClientCodeStateManager.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public MultivaluedMap<String, String> toRedirectState(MessageContext mc,
                                                      MultivaluedMap<String, String> requestState) {
    String stateParam = OAuthUtils.generateRandomTokenKey();
    MultivaluedMap<String, String> redirectMap = new MetadataMap<>();

    if (generateNonce) {
        String nonceParam = MessageDigestUtils.generate(CryptoUtils.generateSecureRandomBytes(32));
        requestState.putSingle(OAuthConstants.NONCE, nonceParam);
        redirectMap.putSingle(OAuthConstants.NONCE, nonceParam);
    }
    map.put(stateParam, requestState);
    OAuthUtils.setSessionToken(mc, stateParam, "state", 0);
    redirectMap.putSingle(OAuthConstants.STATE, stateParam);
    return redirectMap;
}
 
Example 2
Source File: MemoryClientTokenContextManager.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void setClientTokenContext(MessageContext mc, ClientTokenContext request) {
    String key = getKey(mc, false);
    if (key == null) {
        key = OAuthUtils.generateRandomTokenKey();
        OAuthUtils.setSessionToken(mc, key, "org.apache.cxf.websso.context", 0);
    }
    map.put(key, request);

}
 
Example 3
Source File: JoseClientCodeStateManager.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public MultivaluedMap<String, String> toRedirectState(MessageContext mc,
                                                      MultivaluedMap<String, String> requestState) {
    JweEncryptionProvider theEncryptionProvider = getInitializedEncryptionProvider();
    JwsSignatureProvider theSigProvider = getInitializedSigProvider(theEncryptionProvider);
    if (theEncryptionProvider == null && theSigProvider == null) {
        throw new OAuthServiceException("The state can not be protected");
    }
    MultivaluedMap<String, String> redirectMap = new MetadataMap<>();

    if (generateNonce && theSigProvider != null) {
        JwsCompactProducer nonceProducer = new JwsCompactProducer(OAuthUtils.generateRandomTokenKey());
        String nonceParam = nonceProducer.signWith(theSigProvider);
        requestState.putSingle(OAuthConstants.NONCE, nonceParam);
        redirectMap.putSingle(OAuthConstants.NONCE, nonceParam);
    }
    Map<String, Object> stateMap = CastUtils.cast((Map<?, ?>)requestState);
    String json = jsonp.toJson(stateMap);

    String stateParam = null;
    if (theSigProvider != null) {
        JwsCompactProducer stateProducer = new JwsCompactProducer(json);
        stateParam = stateProducer.signWith(theSigProvider);
    }

    if (theEncryptionProvider != null) {
        stateParam = theEncryptionProvider.encrypt(StringUtils.toBytesUTF8(stateParam), null);
    }
    if (storeInSession) {
        String sessionStateAttribute = OAuthUtils.generateRandomTokenKey();
        OAuthUtils.setSessionToken(mc, stateParam, sessionStateAttribute, 0);
        stateParam = sessionStateAttribute;
    }
    redirectMap.putSingle(OAuthConstants.STATE, stateParam);

    return redirectMap;
}
 
Example 4
Source File: HawkAccessToken.java    From cxf with Apache License 2.0 5 votes vote down vote up
public HawkAccessToken(Client client,
                      HmacAlgorithm macAlgo,
                      long lifetime) {
    this(client,
         macAlgo,
         OAuthUtils.generateRandomTokenKey(),
         lifetime,
         OAuthUtils.getIssuedAt());
}
 
Example 5
Source File: BearerAccessToken.java    From cxf with Apache License 2.0 5 votes vote down vote up
public BearerAccessToken(Client client,
                         long lifetime) {
    super(client,
          OAuthConstants.BEARER_TOKEN_TYPE,
          OAuthUtils.generateRandomTokenKey(),
          lifetime,
          OAuthUtils.getIssuedAt());
}
 
Example 6
Source File: RefreshToken.java    From cxf with Apache License 2.0 5 votes vote down vote up
public RefreshToken(Client client,
                    long lifetime) {
    super(client,
            OAuthConstants.REFRESH_TOKEN_TYPE,
            OAuthUtils.generateRandomTokenKey(),
            lifetime,
            OAuthUtils.getIssuedAt());
}
 
Example 7
Source File: DefaultEncryptingCodeDataProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected String getCode(AuthorizationCodeRegistration reg) {
    return OAuthUtils.generateRandomTokenKey();
}
 
Example 8
Source File: AbstractAuthorizationCodeDataProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected String getCode(AuthorizationCodeRegistration reg) {
    return OAuthUtils.generateRandomTokenKey();
}
 
Example 9
Source File: ServerAuthorizationCodeGrant.java    From cxf with Apache License 2.0 4 votes vote down vote up
public ServerAuthorizationCodeGrant(Client client,
                                    long lifetime) {
    this(client, OAuthUtils.generateRandomTokenKey(), lifetime,
            OAuthUtils.getIssuedAt());
}
 
Example 10
Source File: DynamicRegistrationService.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected String createRegAccessToken(Client client) {
    String regAccessToken = OAuthUtils.generateRandomTokenKey();
    client.getProperties().put(ClientRegistrationResponse.REG_ACCESS_TOKEN,
                               regAccessToken);
    return regAccessToken;
}
 
Example 11
Source File: HawkAccessToken.java    From cxf with Apache License 2.0 4 votes vote down vote up
public HawkAccessToken(ServerAccessToken token) {
    this(token, OAuthUtils.generateRandomTokenKey());
}
 
Example 12
Source File: BearerAccessToken.java    From cxf with Apache License 2.0 4 votes vote down vote up
public BearerAccessToken(ServerAccessToken token) {
    this(token, OAuthUtils.generateRandomTokenKey());
}