我想做什么:
我正在尝试使用Java连接到Web Portal [使用https].我编写了使用Authenticator类提供用户凭据的代码.当我运行程序时,我得到一个异常:"java.lang.UnsupportedOperationException:Not supported yet"
我发布了代码:
__CODE__ 根据Dreamweaver:
public class Main {
public class MyAuthenticator extends Authenticator {
protected PasswordAuthentication getpasswordAuthentication() {
String username = "username";
String password = "password";
// Return the information
return new PasswordAuthentication(username, password.toCharArray());
}
@Override
public Result authenticate(HttpExchange he) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
public static void main(String[] args) {
// TODO code application logic here
TrustManager[] trustClients = new TrustManager[]{
new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
throw new UnsupportedOperationException("Not supported yet.");
}
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
throw new UnsupportedOperationException("Not supported yet.");
}
public X509Certificate[] getAcceptedIssuers() {
return null;
//throw new UnsupportedOperationException("Not supported yet.");
}
}
};
try {
SSLContext sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(null, trustClients, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext.getSocketFactory());
} catch (Exception e) {
System.out.println("in 1st catch " + e);
}
try {
URL url = new URL("https://someURL.server.com/fmk/jsp/ltpaLogin.jsp");
URLConnection urlconnection = url.openConnection();
System.out.println(urlconnection);
System.out.print(urlconnection.getInputStream().toString());
} catch (Exception e) {
System.out.println("in 2ndcatch " + e.getMessage());
}
}
}
如果你不想实现这个方法:
@Override
public Result authenticate(HttpExchange he) {
throw new UnsupportedOperationException("Not supported yet.");
}
Run Code Online (Sandbox Code Playgroud)
放轻松,只删除这行方法:
throw new UnsupportedOperationException("Not supported yet.");
Run Code Online (Sandbox Code Playgroud)
你见过这段代码吗?
@Override
public Result authenticate(HttpExchange he) {
throw new UnsupportedOperationException("Not supported yet.");
}
Run Code Online (Sandbox Code Playgroud)
每次尝试进行身份验证时,都会抛出上述异常.
因此,在我看来,您的身份验证问题的解决方案非常简单:实现此方法.
| 归档时间: |
|
| 查看次数: |
59544 次 |
| 最近记录: |