Search code examples
javawso2openidopenid4javawso2-identity-server

openid4java YadisException peer not authenticated error


I am writing a Java JSP code that authenthicates against a WSO2 IS server using openid. I have taken the example code from de developer so I get the following:

<%
        ConsumerManager manager = new ConsumerManager ();
        String _returnURL = "https://192.168.15.48:9443/ficlient/secret.jsp";
        List discoveries = manager.discover("https://myserverIP/openid");
        DiscoveryInformation discovered = manager.associate(discoveries);
        session.setAttribute("discovered", discovered);
        AuthRequest authReq = manager.authenticate(discovered, _returnURL);
        nextlink = authReq.getDestinationUrl(true);
%>
       <a href="<%out.println(nextlink);%>">Secret data</a>

On the 3rd line (List discoveries...) I get an exception:

org.openid4java.discovery.yadis.YadisException: 0x704: I/O transport error: peer not authenticated

I have understood that this is due to a non valid ssl certificate issued for the https comunication and have tried including the following (as found on Internet), to avoid the verification:

<% 
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[]{
   new X509TrustManager() {
      public java.security.cert.X509Certificate[] getAcceptedIssuers() {
         return null;
      }

      public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType) {}

      public void checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType) {}
   }
};

HostnameVerifier allHostsValid = new HostnameVerifier() {
   public boolean verify(String hostname, SSLSession session) {
      return true;
   }
};

try {
   SSLContext sc = SSLContext.getInstance("SSL");
   sc.init(null, trustAllCerts, new java.security.SecureRandom());
   HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
   HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
} catch (Exception e) {}
%>

But it is still not working. What have I missed?


Solution

  • I finally solved it by using Oltu libraries for authenthication.