重定向到另一个URL并返回Certifcate base Login

时间:2018-01-31 05:32:20

标签: spring spring-mvc ssl cloudfoundry pivotal-cloud-foundry

目前我开发的应用程序有两条不同域的路由。

示例:

路线1:https://test.apps.com

路线2:https://test.cert-apps.com

用户使用Route 1访问该应用程序。在“登录”页面中,有一个基于证书的登录选项。但基于证书的身份验证仅在路由2中启用。

那么如何通过从路由1重定向到路由2来进行基于证书的身份验证,并在客户端通过身份验证后重定向到路由1。

以下是我目前使用的无效代码:

@Controller
@RequestMapping("/login")
public class LoginContr {

    @RequestMapping("/certificate")
    public String message(HttpServletRequest request, HttpServletResponse response) {
        try {
              sendGET();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return "login";
    }
   @RequestMapping("/extractcertificate")
    private String extractEmailFromCertificate(HttpServletRequest request) {
        String email = "";
        //Code to extract email from certificate
        return email;
    }
private static void sendGET() throws IOException {
    URL obj = new URL("https://test.cert-apps.com/login/extractcertificate");
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    con.setRequestMethod("GET");
    int responseCode = con.getResponseCode();
    System.out.println("GET Response Code :: " + responseCode);
    if (responseCode == HttpURLConnection.HTTP_OK) { // success
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();

        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();

        // print result
        System.out.println(response.toString());
    } else {
        System.out.println("GET request not worked");
    }

}

}

上面的代码给出了错误:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)

sendGet()方法向路由2发送请求并调用/extractcertificate webservice进行基于证书的身份验证,一旦完成,它将检索电子邮件地址。

用于app的技术:Java,Spring,Angualar 4,Cloud Foundary

有没有替代方法可以做到这一点或任何内置实现,任何提示都会有很大的优势..

0 个答案:

没有答案