Fixed unit tests - they were broken due to an error in application-context.xml; not because of the refactor. App context was trying to instantiate an Hmac signer with name "HMACSHA256", which should have been "HS256". I updated the exceptions thrown by the signer impls so that if an Algorithm name mismatch occurs it will tell you what it is trying to match against.
parent
0a29eba617
commit
b986b30695
|
@ -5,6 +5,12 @@
|
|||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
<dependent-module archiveName="spring-security-oauth2-1.0.0.BUILD-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/spring-security-oauth2/spring-security-oauth2">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="openid-connect-common-0.1.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/openid-connect-common/openid-connect-common">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<property name="java-output-path" value="/openid/target/classes"/>
|
||||
<property name="context-root" value="openid-connect-server"/>
|
||||
</wb-module>
|
||||
|
|
|
@ -3,13 +3,13 @@ package org.mitre.jwt.signer.impl;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyPair;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.Signature;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.mitre.jwt.signer.AbstractJwtSigner;
|
||||
|
@ -60,7 +60,7 @@ public class EcdsaSigner extends AbstractJwtSigner implements InitializingBean {
|
|||
|
||||
// corresponding type not found
|
||||
throw new IllegalArgumentException(
|
||||
"Algorithm name does not have a corresponding Algorithm");
|
||||
"Algorithm name " + name + " does not have a corresponding Algorithm: expected one of [" + StringUtils.join(Algorithm.values(), ", ") + "]");
|
||||
}
|
||||
|
||||
private final String standardName;
|
||||
|
|
|
@ -4,11 +4,13 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.nio.charset.Charset;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.mitre.jwt.signer.AbstractJwtSigner;
|
||||
|
@ -43,15 +45,21 @@ public class HmacSigner extends AbstractJwtSigner implements InitializingBean {
|
|||
* @return
|
||||
*/
|
||||
public static Algorithm getByName(String name) {
|
||||
|
||||
for (Algorithm correspondingType : Algorithm.values()) {
|
||||
if (correspondingType.toString().equals(name)) {
|
||||
return correspondingType;
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<String> longValues = new ArrayList<String>();
|
||||
for (Algorithm v : Algorithm.values()) {
|
||||
longValues.add(v.standardName);
|
||||
}
|
||||
|
||||
// corresponding type not found
|
||||
throw new IllegalArgumentException(
|
||||
"Algorithm name does not have a corresponding Algorithm");
|
||||
"Algorithm name " + name + " does not have a corresponding Algorithm: expected one of [" + StringUtils.join(Algorithm.values(), ", ") + "]");
|
||||
}
|
||||
|
||||
private final String standardName;
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.security.interfaces.RSAPrivateKey;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.mitre.jwt.signer.AbstractJwtSigner;
|
||||
|
@ -57,7 +58,7 @@ public class RsaSigner extends AbstractJwtSigner implements InitializingBean {
|
|||
|
||||
// corresponding type not found
|
||||
throw new IllegalArgumentException(
|
||||
"Algorithm name does not have a corresponding Algorithm");
|
||||
"Algorithm name " + name + " does not have a corresponding Algorithm: expected one of [" + StringUtils.join(Algorithm.values(), ", ") + "]");
|
||||
}
|
||||
|
||||
private final String standardName;
|
||||
|
|
|
@ -138,7 +138,7 @@
|
|||
</entry>
|
||||
<entry key="hmac1">
|
||||
<bean id="hmacSigner" class="org.mitre.jwt.signer.impl.HmacSigner">
|
||||
<property name="algorithm" value="HMACSHA256" />
|
||||
<property name="algorithm" value="HS256" />
|
||||
<property name="passphrase" value="changeit" />
|
||||
</bean>
|
||||
</entry>
|
||||
|
|
Loading…
Reference in New Issue