added spring aspect to project, tweaked configuration to point to keystore file correctly, added JWK endpoint views
parent
35c09743f9
commit
6d7371ba1a
|
@ -31,8 +31,14 @@
|
|||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.springframework.ide.eclipse.core.springbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.springframework.ide.eclipse.core.springnature</nature>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
|
|
|
@ -5,12 +5,17 @@ package org.mitre.openid.connect.view;
|
|||
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigInteger;
|
||||
import java.security.PublicKey;
|
||||
import java.security.interfaces.DSAPublicKey;
|
||||
import java.security.interfaces.ECPublicKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.validation.BeanPropertyBindingResult;
|
||||
import org.springframework.web.servlet.view.AbstractView;
|
||||
|
||||
|
@ -49,21 +54,47 @@ public class JwkKeyListView extends AbstractView {
|
|||
}
|
||||
|
||||
})
|
||||
.registerTypeAdapter(RSAPublicKey.class, new JsonSerializer<RSAPublicKey>() {
|
||||
.registerTypeHierarchyAdapter(PublicKey.class, new JsonSerializer<PublicKey>() {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(RSAPublicKey src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
public JsonElement serialize(PublicKey src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
|
||||
|
||||
if (src instanceof RSAPublicKey) {
|
||||
|
||||
JsonObject o = new JsonObject();
|
||||
o.addProperty("mod", src.getModulus().toString());
|
||||
RSAPublicKey rsa = (RSAPublicKey)src;
|
||||
|
||||
|
||||
BigInteger mod = rsa.getModulus();
|
||||
BigInteger exp = rsa.getPublicExponent();
|
||||
|
||||
String m64 = Base64.encodeBase64URLSafeString(mod.toByteArray());
|
||||
String e64 = Base64.encodeBase64URLSafeString(exp.toByteArray());
|
||||
|
||||
JsonObject o = new JsonObject();
|
||||
|
||||
o.addProperty("mod", m64);
|
||||
o.addProperty("exp", e64);
|
||||
|
||||
return o;
|
||||
} else if (src instanceof ECPublicKey) {
|
||||
|
||||
ECPublicKey ec = (ECPublicKey)src;
|
||||
|
||||
// TODO: serialize the EC
|
||||
|
||||
return null;
|
||||
|
||||
} else {
|
||||
|
||||
// skip this class ... we shouldn't have any keys in here that aren't encodable by this serializer
|
||||
return null;
|
||||
}
|
||||
|
||||
return o;
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
.create();
|
||||
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ public class JsonWebKeyEndpoint {
|
|||
|
||||
List<PublicKey> keys = jwtService.getAllPublicKeys();
|
||||
|
||||
// TODO: check if keys are empty, return a 404 here?
|
||||
// TODO: check if keys are empty, return a 404 here or just an empty list?
|
||||
|
||||
return new ModelAndView("jwkKeyList", "keys", keys); // TODO: make a view
|
||||
return new ModelAndView("jwkKeyList", "entity", keys);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
<!-- JSON views for each type of model object -->
|
||||
<beans:bean id="jsonOpenIdConfigurationView" class="org.mitre.swd.view.JsonOpenIdConfigurationView" />
|
||||
<beans:bean id="jsonSwdResponseView" class="org.mitre.swd.view.SwdResponse" />
|
||||
<beans:bean id="jwkKeyList" class="org.mitre.openid.connect.view.JwkKeyListView" />
|
||||
|
||||
<!-- <beans:bean id="jsonUserInfoView" class="org.mitre.openid.connect.view.JSONUserInfoView"/> -->
|
||||
<!-- <beans:bean id="jsonIdTokenView" class="org.mitre.openid.connect.view.JSONIdTokenView"/> -->
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
</property>
|
||||
</bean>
|
||||
|
||||
<jwt-signer:keystore id="defaultKeystore" location="file:src/main/webapp/WEB-INF/spring/keystore.jks" password="changeit" type="JKS" />
|
||||
<jwt-signer:keystore id="defaultKeystore" location="WEB-INF/spring/keystore.jks" password="changeit" type="JKS" />
|
||||
|
||||
<jwt-signer:service id="defaultSignerService">
|
||||
<jwt-signer:rsa bits="256" keystore-ref="defaultKeystore" key-alias="test" password="changeit" />
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue