Fixed JWS algorithm parsing
parent
aeb6644d38
commit
1c34f83297
|
@ -15,6 +15,9 @@
|
|||
******************************************************************************/
|
||||
package org.mitre.jwt.signer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
|
@ -38,21 +41,27 @@ public enum JwsAlgorithm {
|
|||
RS512("SHA512withRSA", "RS512");
|
||||
|
||||
|
||||
private static final Map<String, JwsAlgorithm> jwaLookup = new HashMap<String, JwsAlgorithm>();
|
||||
private static final Map<String, JwsAlgorithm> jceLookup = new HashMap<String, JwsAlgorithm>();
|
||||
static {
|
||||
for (JwsAlgorithm alg : JwsAlgorithm.values()) {
|
||||
jwaLookup.put(alg.getJwaName(), alg);
|
||||
jceLookup.put(alg.getStandardName(), alg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Algorithm for the JWS-registered name
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static JwsAlgorithm getByName(String name) {
|
||||
for (JwsAlgorithm correspondingType : JwsAlgorithm.values()) {
|
||||
if (correspondingType.toString().equals(name)) {
|
||||
return correspondingType;
|
||||
}
|
||||
public static JwsAlgorithm getByJwaName(String name) {
|
||||
return jwaLookup.get(name);
|
||||
}
|
||||
|
||||
// corresponding type not found
|
||||
throw new IllegalArgumentException("JwsAlgorithm name " + name + " does not have a corresponding JwsAlgorithm: expected one of [" + StringUtils.join(JwsAlgorithm.values(), ", ") + "]");
|
||||
public static JwsAlgorithm getByStandardName(String name) {
|
||||
return jceLookup.get(name);
|
||||
}
|
||||
|
||||
private final String standardName;
|
||||
|
|
|
@ -101,7 +101,7 @@ public class HmacSigner extends AbstractJwtSigner implements InitializingBean {
|
|||
* the passphrase
|
||||
*/
|
||||
public HmacSigner(String algorithmName, String passphrase) {
|
||||
super(JwsAlgorithm.getByName(algorithmName));
|
||||
super(JwsAlgorithm.getByJwaName(algorithmName));
|
||||
|
||||
Assert.notNull(passphrase, "A passphrase must be supplied");
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ public class RsaSigner extends AbstractJwtSigner implements InitializingBean {
|
|||
* @throws GeneralSecurityException
|
||||
*/
|
||||
public RsaSigner(String algorithmName, KeyStore keystore, String alias, String password) throws GeneralSecurityException {
|
||||
super(JwsAlgorithm.getByName(algorithmName));
|
||||
super(JwsAlgorithm.getByJwaName(algorithmName));
|
||||
|
||||
setKeystore(keystore);
|
||||
setAlias(alias);
|
||||
|
@ -122,7 +122,7 @@ public class RsaSigner extends AbstractJwtSigner implements InitializingBean {
|
|||
* The private key
|
||||
*/
|
||||
public RsaSigner(String algorithmName, PublicKey publicKey, PrivateKey privateKey) {
|
||||
super(JwsAlgorithm.getByName(algorithmName));
|
||||
super(JwsAlgorithm.getByJwaName(algorithmName));
|
||||
|
||||
this.publicKey = publicKey;
|
||||
this.privateKey = privateKey;
|
||||
|
|
Loading…
Reference in New Issue