Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor package structure. Delete IdentifiedSigner as it is duplicat…
…ed with CommonSigner
- Loading branch information
Showing
10 changed files
with
177 additions
and
108 deletions.
There are no files selected for viewing
48 changes: 0 additions & 48 deletions
48
server/src/main/java/org/cloudfoundry/identity/uaa/oauth/CommonSigner.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 16 additions & 13 deletions
29
...ty/uaa/oauth/CommonSignatureVerifier.java → ...aa/oauth/jwt/CommonSignatureVerifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
server/src/main/java/org/cloudfoundry/identity/uaa/oauth/jwt/CommonSigner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* **************************************************************************** | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved. | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
* **************************************************************************** | ||
*/ | ||
package org.cloudfoundry.identity.uaa.oauth.jwt; | ||
|
||
import org.cloudfoundry.identity.uaa.oauth.KeyInfo; | ||
import org.springframework.security.jwt.crypto.sign.MacSigner; | ||
import org.springframework.security.jwt.crypto.sign.RsaSigner; | ||
|
||
public class CommonSigner implements Signer { | ||
|
||
private final org.springframework.security.jwt.crypto.sign.Signer delegate; | ||
private final String keyId; | ||
|
||
public CommonSigner(String keyId, String signingKey) { | ||
org.springframework.security.jwt.crypto.sign.Signer signer; | ||
if (signingKey == null) { | ||
throw new IllegalArgumentException(signingKey); | ||
} else if(KeyInfo.isAssymetricKey(signingKey)) { | ||
signer = new RsaSigner(signingKey); | ||
} else { | ||
signer = new MacSigner(signingKey); | ||
} | ||
delegate = signer; | ||
this.keyId = keyId; | ||
} | ||
|
||
@Override | ||
public String keyId() { | ||
return keyId; | ||
} | ||
|
||
@Override | ||
public byte[] sign(byte[] bytes) { | ||
return delegate.sign(bytes); | ||
} | ||
|
||
@Override | ||
public String algorithm() { | ||
return delegate.algorithm(); | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
server/src/main/java/org/cloudfoundry/identity/uaa/oauth/jwt/IdentifiedSigner.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
server/src/test/java/org/cloudfoundry/identity/uaa/oauth/jwt/CommonSignerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* **************************************************************************** | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved. | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
* **************************************************************************** | ||
*/ | ||
|
||
package org.cloudfoundry.identity.uaa.oauth.jwt; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
public class CommonSignerTest { | ||
private String rsaSigningKey; | ||
private String macSigningKey; | ||
|
||
@Before | ||
public void setup() { | ||
rsaSigningKey = "-----BEGIN RSA PRIVATE KEY-----\n" + | ||
"MIIBOQIBAAJAcjAgsHEfrUxeTFwQPb17AkZ2Im4SfZdpY8Ada9pZfxXz1PZSqv9T\n" + | ||
"PTMAzNx+EkzMk2IMYN+uNm1bfDzaxVdz+QIDAQABAkBoR39y4rw0/QsY3PKQD5xo\n" + | ||
"hYSZCMCmJUI/sFCuECevIFY4h6q9KBP+4Set96f7Bgs9wJWVvCMx/nJ6guHAjsIB\n" + | ||
"AiEAywVOoCGIZ2YzARXWYcMRYZ89hxoHh8kZ+QMthRSZieECIQCP/GWQYgyofAQA\n" + | ||
"BtM8YwThXEV+S3KtuCn4IAQ89gqdGQIgULBASpZpPyc4OEM0nFBKFTGT46EtwwLj\n" + | ||
"RrvDmLPSPiECICQi9FqIQSUH+vkGvX0qXM8ymT5ZMS7oSaA8aNPj7EYBAiEAx5V3\n" + | ||
"2JGEulMY3bK1PVGYmtsXF1gq6zbRMoollMCRSMg=\n" + | ||
"-----END RSA PRIVATE KEY-----"; | ||
macSigningKey = "mac-sign-key"; | ||
} | ||
|
||
@Test | ||
public void test_rsa_key_null_id() { | ||
CommonSigner signer = new CommonSigner(null, rsaSigningKey); | ||
assertEquals("SHA256withRSA", signer.algorithm()); | ||
assertNull(signer.keyId()); | ||
} | ||
|
||
@Test | ||
public void test_rsa_key_with_id() { | ||
CommonSigner signer = new CommonSigner("id", rsaSigningKey); | ||
assertEquals("SHA256withRSA", signer.algorithm()); | ||
assertEquals("id", signer.keyId()); | ||
} | ||
|
||
@Test | ||
public void test_mac_key_null_id() { | ||
CommonSigner signer = new CommonSigner(null, macSigningKey); | ||
assertEquals("HMACSHA256", signer.algorithm()); | ||
assertNull(signer.keyId()); | ||
} | ||
|
||
@Test | ||
public void test_mac_key_with_id() { | ||
CommonSigner signer = new CommonSigner("id", macSigningKey); | ||
assertEquals("HMACSHA256", signer.algorithm()); | ||
assertEquals("id", signer.keyId()); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void null_key_is_rejected() { | ||
new CommonSigner("id", null); | ||
} | ||
|
||
} |
5 changes: 2 additions & 3 deletions
5
server/src/test/java/org/cloudfoundry/identity/uaa/oauth/jwt/JwtHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters