You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oltu.apache.org by si...@apache.org on 2013/09/19 10:29:14 UTC
svn commit: r1524655 - in /oltu/trunk/jose/jws/src:
main/java/org/apache/oltu/jose/jws/
test/java/org/apache/oltu/jose/jws/signature/
Author: simonetripodi
Date: Thu Sep 19 08:29:14 2013
New Revision: 1524655
URL: http://svn.apache.org/r1524655
Log:
OLTU-118 - Implement JWS of the JOSE working group
added signature generation/verification basic test cases
Added:
oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/
oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/SignatureMethodTestCase.java (with props)
oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSignatureMethod.java (with props)
oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSymetricKey.java (with props)
Modified:
oltu/trunk/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java
Modified: oltu/trunk/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java
URL: http://svn.apache.org/viewvc/oltu/trunk/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java?rev=1524655&r1=1524654&r2=1524655&view=diff
==============================================================================
--- oltu/trunk/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java (original)
+++ oltu/trunk/jose/jws/src/main/java/org/apache/oltu/jose/jws/JWS.java Thu Sep 19 08:29:14 2013
@@ -21,7 +21,6 @@ import java.util.Map;
import org.apache.oltu.jose.jws.signature.SignatureMethod;
import org.apache.oltu.jose.jws.signature.SigningKey;
-import org.apache.oltu.jose.jws.signature.SymetricKey;
import org.apache.oltu.jose.jws.signature.VerifyingKey;
public class JWS {
@@ -208,11 +207,6 @@ public class JWS {
return setSignature(method.calculate(signingKey));
}
- public <SK extends SymetricKey> Builder sign(SignatureMethod<SK, SK> method,
- SK signingKey) {
- return sign(method, signingKey);
- }
-
public JWS build() {
return new JWS(new Header(algorithm,
jwkSetUrl,
Added: oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/SignatureMethodTestCase.java
URL: http://svn.apache.org/viewvc/oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/SignatureMethodTestCase.java?rev=1524655&view=auto
==============================================================================
--- oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/SignatureMethodTestCase.java (added)
+++ oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/SignatureMethodTestCase.java Thu Sep 19 08:29:14 2013
@@ -0,0 +1,66 @@
+/*
+ * 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.oltu.jose.jws.signature;
+
+import static org.junit.Assert.*;
+
+import org.apache.oltu.jose.jws.JWS;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public final class SignatureMethodTestCase {
+
+ private String signature;
+
+ private TestSymetricKey key;
+
+ private TestSignatureMethod method;
+
+ @Before
+ public void setUp() {
+ signature = "supercalifragilistichespiralidoso123456789";
+ key = new TestSymetricKey(signature);
+ method = new TestSignatureMethod();
+ }
+
+ @After
+ public void tearDown() {
+ signature = null;
+ key = null;
+ method = null;
+ }
+
+ @Test
+ public void simpleSignatureVerification() {
+ assertEquals(signature, method.calculate(key));
+ assertTrue(method.verify(signature, key));
+ }
+
+ @Test
+ public void signJWS() {
+ JWS jws = new JWS.Builder()
+ .setType("JWT")
+ .setPayload("{\"iss\":\"joe\",\r\n \"exp\":1300819380,\r\n \"http://example.com/is_root\":true}")
+ .sign( method, key )
+ .build();
+
+ assertEquals("TEST", jws.getHeader().getAlgorithm());
+ assertEquals(signature, jws.getSignature());
+ }
+
+}
Propchange: oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/SignatureMethodTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/SignatureMethodTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/SignatureMethodTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSignatureMethod.java
URL: http://svn.apache.org/viewvc/oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSignatureMethod.java?rev=1524655&view=auto
==============================================================================
--- oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSignatureMethod.java (added)
+++ oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSignatureMethod.java Thu Sep 19 08:29:14 2013
@@ -0,0 +1,36 @@
+/*
+ * 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.oltu.jose.jws.signature;
+
+final class TestSignatureMethod implements SignatureMethod<TestSymetricKey, TestSymetricKey> {
+
+ @Override
+ public String calculate(TestSymetricKey signingKey) {
+ return signingKey.getValue();
+ }
+
+ @Override
+ public boolean verify(String signature, TestSymetricKey verifyingKey) {
+ return signature.equals(verifyingKey.getValue());
+ }
+
+ @Override
+ public String getAlgorithm() {
+ return "TEST";
+ }
+
+}
Propchange: oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSignatureMethod.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSignatureMethod.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSignatureMethod.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSymetricKey.java
URL: http://svn.apache.org/viewvc/oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSymetricKey.java?rev=1524655&view=auto
==============================================================================
--- oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSymetricKey.java (added)
+++ oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSymetricKey.java Thu Sep 19 08:29:14 2013
@@ -0,0 +1,36 @@
+/*
+ * 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.oltu.jose.jws.signature;
+
+final class TestSymetricKey implements SymetricKey {
+
+ private final String value;
+
+ public TestSymetricKey(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ @Override
+ public String[] getAlgorithmMethods() {
+ return new String[]{ "TEST" };
+ }
+
+}
Propchange: oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSymetricKey.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSymetricKey.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: oltu/trunk/jose/jws/src/test/java/org/apache/oltu/jose/jws/signature/TestSymetricKey.java
------------------------------------------------------------------------------
svn:mime-type = text/plain