Search in sources :

Example 11 with MockAlgorithmProvider

use of org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider in project cxf by apache.

the class MessageVerifierTest method defaultRequiredHeaderPresent.

@Test
public void defaultRequiredHeaderPresent() throws IOException {
    Map<String, List<String>> headers = createMockHeaders();
    headers.put("Test", Collections.singletonList("value"));
    headers.put(HTTPSignatureConstants.REQUEST_TARGET, Collections.singletonList("12345"));
    createAndAddSignature(headers);
    MessageVerifier headerVerifier = new MessageVerifier(keyId -> keyPair.getPublic(), Collections.singletonList("test"));
    headerVerifier.setSecurityProvider(new MockSecurityProvider());
    headerVerifier.setAlgorithmProvider(new MockAlgorithmProvider());
    headerVerifier.verifyMessage(headers, METHOD, URI, new MessageImpl(), MESSAGE_BODY.getBytes());
}
Also used : MockAlgorithmProvider(org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider) ArrayList(java.util.ArrayList) List(java.util.List) MockSecurityProvider(org.apache.cxf.rs.security.httpsignature.provider.MockSecurityProvider) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 12 with MockAlgorithmProvider

use of org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider in project cxf by apache.

the class MessageVerifierTest method defaultRequiredHeaderNotPresent.

@Test(expected = InvalidDataToVerifySignatureException.class)
public void defaultRequiredHeaderNotPresent() throws IOException {
    Map<String, List<String>> headers = createMockHeaders();
    headers.put("Test", Collections.singletonList("value"));
    createAndAddSignature(headers);
    MessageVerifier headerVerifier = new MessageVerifier(keyId -> keyPair.getPublic(), Collections.singletonList("test"));
    headerVerifier.setSecurityProvider(new MockSecurityProvider());
    headerVerifier.setAlgorithmProvider(new MockAlgorithmProvider());
    headerVerifier.verifyMessage(headers, METHOD, URI, new MessageImpl(), MESSAGE_BODY.getBytes());
}
Also used : MockAlgorithmProvider(org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider) ArrayList(java.util.ArrayList) List(java.util.List) MockSecurityProvider(org.apache.cxf.rs.security.httpsignature.provider.MockSecurityProvider) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 13 with MockAlgorithmProvider

use of org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider in project cxf by apache.

the class MessageVerifierTest method requiredHeaderPresentButNotSigned.

@Test(expected = InvalidDataToVerifySignatureException.class)
public void requiredHeaderPresentButNotSigned() throws IOException {
    Map<String, List<String>> headers = createMockHeaders();
    createAndAddSignature(headers);
    headers.put("Test", Collections.singletonList("value"));
    MessageVerifier headerVerifier = new MessageVerifier(keyId -> keyPair.getPublic(), Collections.singletonList("test"));
    headerVerifier.setAddDefaultRequiredHeaders(false);
    headerVerifier.setSecurityProvider(new MockSecurityProvider());
    headerVerifier.setAlgorithmProvider(new MockAlgorithmProvider());
    headerVerifier.verifyMessage(headers, METHOD, URI, new MessageImpl(), MESSAGE_BODY.getBytes());
}
Also used : MockAlgorithmProvider(org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider) ArrayList(java.util.ArrayList) List(java.util.List) MockSecurityProvider(org.apache.cxf.rs.security.httpsignature.provider.MockSecurityProvider) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 14 with MockAlgorithmProvider

use of org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider in project cxf by apache.

the class MessageVerifierTest method setUp.

@BeforeClass
public static void setUp() {
    try {
        keyPair = KeyPairGenerator.getInstance(KEY_PAIR_GENERATOR_ALGORITHM).generateKeyPair();
        messageVerifier = new MessageVerifier(keyId -> keyPair.getPublic());
        messageVerifier.setSecurityProvider(new MockSecurityProvider());
        messageVerifier.setAlgorithmProvider(new MockAlgorithmProvider());
        messageVerifier.setAddDefaultRequiredHeaders(false);
        messageSigner = new MessageSigner(keyId -> keyPair.getPrivate(), KEY_ID);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
}
Also used : KeyPairGenerator(java.security.KeyPairGenerator) MessageImpl(org.apache.cxf.message.MessageImpl) MultipleSignatureHeaderException(org.apache.cxf.rs.security.httpsignature.exception.MultipleSignatureHeaderException) KeyPair(java.security.KeyPair) MockSecurityProvider(org.apache.cxf.rs.security.httpsignature.provider.MockSecurityProvider) BeforeClass(org.junit.BeforeClass) IOException(java.io.IOException) HashMap(java.util.HashMap) MockAlgorithmProvider(org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider) Test(org.junit.Test) InvalidDataToVerifySignatureException(org.apache.cxf.rs.security.httpsignature.exception.InvalidDataToVerifySignatureException) KeyGenerator(javax.crypto.KeyGenerator) InvalidSignatureHeaderException(org.apache.cxf.rs.security.httpsignature.exception.InvalidSignatureHeaderException) ArrayList(java.util.ArrayList) DifferentAlgorithmsException(org.apache.cxf.rs.security.httpsignature.exception.DifferentAlgorithmsException) List(java.util.List) InvalidSignatureException(org.apache.cxf.rs.security.httpsignature.exception.InvalidSignatureException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Map(java.util.Map) ZoneOffset(java.time.ZoneOffset) SecretKey(javax.crypto.SecretKey) Collections(java.util.Collections) MissingSignatureHeaderException(org.apache.cxf.rs.security.httpsignature.exception.MissingSignatureHeaderException) SignatureHeaderUtils(org.apache.cxf.rs.security.httpsignature.utils.SignatureHeaderUtils) MockAlgorithmProvider(org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider) MockSecurityProvider(org.apache.cxf.rs.security.httpsignature.provider.MockSecurityProvider) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BeforeClass(org.junit.BeforeClass)

Example 15 with MockAlgorithmProvider

use of org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider in project cxf by apache.

the class MessageVerifierTest method requiredHeaderPresent.

@Test
public void requiredHeaderPresent() throws IOException {
    Map<String, List<String>> headers = createMockHeaders();
    headers.put("Test", Collections.singletonList("value"));
    createAndAddSignature(headers);
    MessageVerifier headerVerifier = new MessageVerifier(keyId -> keyPair.getPublic(), Collections.singletonList("test"));
    headerVerifier.setAddDefaultRequiredHeaders(false);
    headerVerifier.setSecurityProvider(new MockSecurityProvider());
    headerVerifier.setAlgorithmProvider(new MockAlgorithmProvider());
    headerVerifier.verifyMessage(headers, METHOD, URI, new MessageImpl(), MESSAGE_BODY.getBytes());
}
Also used : MockAlgorithmProvider(org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider) ArrayList(java.util.ArrayList) List(java.util.List) MockSecurityProvider(org.apache.cxf.rs.security.httpsignature.provider.MockSecurityProvider) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Aggregations

MessageImpl (org.apache.cxf.message.MessageImpl)15 MockAlgorithmProvider (org.apache.cxf.rs.security.httpsignature.provider.MockAlgorithmProvider)15 MockSecurityProvider (org.apache.cxf.rs.security.httpsignature.provider.MockSecurityProvider)15 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)9 List (java.util.List)9 ClientRequestContext (javax.ws.rs.client.ClientRequestContext)3 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)3 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)3 Message (org.apache.cxf.message.Message)3 CreateSignatureInterceptor (org.apache.cxf.rs.security.httpsignature.filters.CreateSignatureInterceptor)3 VerifySignatureFilter (org.apache.cxf.rs.security.httpsignature.filters.VerifySignatureFilter)3 IOException (java.io.IOException)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ZoneOffset (java.time.ZoneOffset)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1