Repository: cxf Updated Branches: refs/heads/3.1.x-fixes 50138677d -> 951644d9c
Adding a jws test for loading a publik key from JKS Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/951644d9 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/951644d9 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/951644d9 Branch: refs/heads/3.1.x-fixes Commit: 951644d9c18634e1a552f36c7492b3baab11d04b Parents: 5013867 Author: Sergey Beryozkin <[email protected]> Authored: Thu Dec 3 10:27:59 2015 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Thu Dec 3 10:29:05 2015 +0000 ---------------------------------------------------------------------- .../cxf/rs/security/jose/jws/JwsUtilsTest.java | 68 +++++++++++++++++++ .../apache/cxf/rs/security/jose/jws/alice.jks | Bin 0 -> 4125 bytes 2 files changed, 68 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/951644d9/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/JwsUtilsTest.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/JwsUtilsTest.java b/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/JwsUtilsTest.java new file mode 100644 index 0000000..f82ce92 --- /dev/null +++ b/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/JwsUtilsTest.java @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.rs.security.jose.jws; + +import java.util.List; +import java.util.Properties; + +import org.apache.cxf.Bus; +import org.apache.cxf.BusFactory; +import org.apache.cxf.message.Exchange; +import org.apache.cxf.message.ExchangeImpl; +import org.apache.cxf.message.Message; +import org.apache.cxf.message.MessageImpl; +import org.apache.cxf.rs.security.jose.common.JoseConstants; +import org.apache.cxf.rs.security.jose.jwk.JsonWebKey; +import org.apache.cxf.rs.security.jose.jwk.JsonWebKeys; +import org.apache.cxf.rs.security.jose.jwk.JwkUtils; +import org.apache.cxf.rs.security.jose.jwk.KeyType; + +import org.junit.Assert; +import org.junit.Test; + +public class JwsUtilsTest extends Assert { + @Test + public void testLoadVerificationKeys() throws Exception { + Properties p = new Properties(); + p.put(JoseConstants.RSSEC_KEY_STORE_FILE, + "org/apache/cxf/rs/security/jose/jws/alice.jks"); + p.put(JoseConstants.RSSEC_KEY_STORE_PSWD, "password"); + p.put(JoseConstants.RSSEC_KEY_STORE_ALIAS, "alice"); + JsonWebKeys keySet = JwsUtils.loadPublicVerificationKeys(createMessage(), p); + assertEquals(1, keySet.asMap().size()); + List<JsonWebKey> keys = keySet.getRsaKeys(); + assertEquals(1, keys.size()); + JsonWebKey key = keys.get(0); + System.out.println(JwkUtils.jwkKeyToJson(key)); + assertEquals(KeyType.RSA, key.getKeyType()); + assertEquals("alice", key.getKeyId()); + assertNotNull(key.getKeyProperty(JsonWebKey.RSA_PUBLIC_EXP)); + assertNotNull(key.getKeyProperty(JsonWebKey.RSA_MODULUS)); + assertNull(key.getKeyProperty(JsonWebKey.RSA_PRIVATE_EXP)); + } + + private Message createMessage() { + Message m = new MessageImpl(); + Exchange e = new ExchangeImpl(); + e.put(Bus.class, BusFactory.getThreadDefaultBus()); + m.setExchange(e); + e.setInMessage(m); + return m; + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/951644d9/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/alice.jks ---------------------------------------------------------------------- diff --git a/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/alice.jks b/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/alice.jks new file mode 100644 index 0000000..213b26c Binary files /dev/null and b/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/alice.jks differ
