I need to access the HttpServletRequest properties to get the javax.servlet.request.X509Certificate which contains the X509Certificate arr
Without hacking:
With hacking:
ServletRequest field in handshake request instance.Get its javax.servlet.request.X509Certificate attribute.
In other words:
public class ServletAwareConfigurator extends Configurator {
@Override
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
ServletRequest servletRequest = getField(request, ServletRequest.class);
X509Certificate[] certificates = (X509Certificate[]) servletRequest.getAttribute("javax.servlet.request.X509Certificate");
// ...
}
private static F getField(I instance, Class fieldType) {
try {
for (Class> type = instance.getClass(); type != Object.class; type = type.getSuperclass()) {
for (Field field : type.getDeclaredFields()) {
if (fieldType.isAssignableFrom(field.getType())) {
field.setAccessible(true);
return (F) field.get(instance);
}
}
}
} catch (Exception e) {
// Handle?
}
return null;
}
}