Search in sources :

Example 46 with OAuthServiceException

use of org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException in project cxf by apache.

the class OAuthUtils method setCertificateThumbprintConfirmation.

public static void setCertificateThumbprintConfirmation(MessageContext mc, X509Certificate cert) {
    try {
        byte[] thumbprint = createCertificateThumbprint(cert);
        String encodedThumbprint = Base64UrlUtility.encode(thumbprint);
        mc.put(JoseConstants.HEADER_X509_THUMBPRINT_SHA256, encodedThumbprint);
    } catch (Exception ex) {
        throw new OAuthServiceException(ex);
    }
}
Also used : OAuthServiceException(org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException) OAuthServiceException(org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)

Example 47 with OAuthServiceException

use of org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException in project cxf by apache.

the class OAuthUtils method getClientSecretSignatureAlgorithm.

public static SignatureAlgorithm getClientSecretSignatureAlgorithm(Properties sigProps) {
    String clientSecretSigProp = sigProps.getProperty(OAuthConstants.CLIENT_SECRET_SIGNATURE_ALGORITHM);
    if (clientSecretSigProp == null) {
        String sigProp = sigProps.getProperty(JoseConstants.RSSEC_SIGNATURE_ALGORITHM);
        if (AlgorithmUtils.isHmacSign(sigProp)) {
            clientSecretSigProp = sigProp;
        }
    }
    SignatureAlgorithm sigAlgo = SignatureAlgorithm.getAlgorithm(clientSecretSigProp);
    sigAlgo = sigAlgo != null ? sigAlgo : SignatureAlgorithm.HS256;
    if (!AlgorithmUtils.isHmacSign(sigAlgo)) {
        // Must be HS-based for the symmetric signature
        throw new OAuthServiceException(OAuthConstants.SERVER_ERROR);
    }
    return sigAlgo;
}
Also used : OAuthServiceException(org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException) SignatureAlgorithm(org.apache.cxf.rs.security.jose.jwa.SignatureAlgorithm)

Example 48 with OAuthServiceException

use of org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException in project cxf by apache.

the class JAXRSOAuth2TlsTest method testTwoWayTLSClientUnbound.

@Test
public void testTwoWayTLSClientUnbound() throws Exception {
    String address = "https://localhost:" + PORT + "/oauth2/token";
    WebClient wc = createOAuth2WebClient(address);
    try {
        OAuthClientUtils.getAccessToken(wc, new Consumer("unbound"), new CustomGrant());
        fail("exception_expected");
    } catch (OAuthServiceException ex) {
        assertEquals("invalid_client", ex.getError().getError());
    }
}
Also used : JwsJwtCompactConsumer(org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer) Consumer(org.apache.cxf.rs.security.oauth2.client.Consumer) OAuthServiceException(org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

OAuthServiceException (org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)37 ServerAccessToken (org.apache.cxf.rs.security.oauth2.common.ServerAccessToken)12 WebClient (org.apache.cxf.jaxrs.client.WebClient)11 Test (org.junit.Test)8 HashMap (java.util.HashMap)6 IOException (java.io.IOException)4 OAuthPermission (org.apache.cxf.rs.security.oauth2.common.OAuthPermission)4 UserSubject (org.apache.cxf.rs.security.oauth2.common.UserSubject)4 ArrayList (java.util.ArrayList)3 Base64Exception (org.apache.cxf.common.util.Base64Exception)3 Consumer (org.apache.cxf.rs.security.oauth2.client.Consumer)3 AccessTokenValidation (org.apache.cxf.rs.security.oauth2.common.AccessTokenValidation)3 OAuthError (org.apache.cxf.rs.security.oauth2.common.OAuthError)3 InputStream (java.io.InputStream)2 List (java.util.List)2 Map (java.util.Map)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 ProcessingException (javax.ws.rs.ProcessingException)2 Produces (javax.ws.rs.Produces)2