[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[转帖]No Name Matching localhost found Error : Tomcat and CAS configuration

上一篇:[转帖]Configure CAS Server and Client in Java
下一篇:[转帖]web.xml中的配置作用

添加日期:2013/9/3 8:36:43 快速返回   返回列表 阅读23828次
http://www.javaroots.com/2013/05/no-name-matching-localhost-found-error.html

No Name Matching localhost found Error : Tomcat and CAS configuration


javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching localhost found

This error occurs when we try to connect to https enabled web service using standalone java program for localhost configuration.

This Post provides the solution by adding javax.net.ssl.HostnameVerifier in the java program. 

But , sometimes we can not change the code because of third party code restriction . For example , setting up and configuring CAS. CAS also uses http client to connect to the CAS server war application deployed on server.

To overcome this problem , we can import the certificate for localhost in our java environment by following these simple steps : 

First of all , create a keystore by using keytool present in your $JDK_HOME/bin directory.


keytool -genkey -alias tomcat -keystore ./keystore -keyalg RSA

Enter keystore password:
Re-enter new password:
What is your first and last name?
  [Unknown]:  localhost
What is the name of your organizational unit?
  [Unknown]:  localhost
What is the name of your organization?
  [Unknown]:  localhost
What is the name of your City or Locality?
  [Unknown]:  localhost
What is the name of your State or Province?
  [Unknown]:  localhost
What is the two-letter country code for this unit?
  [Unknown]:  in
Is CN=localhost, OU=localhost, O=localhost, L=localhost, ST=localhost, C=in correct?
  [no]:  yes


make sure you enter localhost for first name and last name . 
Now copy the generated key to tomcat home directory and configure the tomcat to enable SSL like this :


<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
 maxThreads="150" scheme="https" secure="true" keystoreFile="keystore" keystorePass="changeit"
               clientAuth="false" sslProtocol="TLS" />


Now restart tomcat and you should be able to access https on https://localhost:8443 Now export the certificate of this localhost:8443 to disk using your browser.(In mozilla you will find option to export in certificate viewer tab ) 
Now use the keytool in your jdk to import this certificate in your jvm certificates.


keytool -importcert -alias tomcat -file ${PATH_WHERE_CERT_IS_EXPORTED} -keystore $JDK_HOME\jre\lib\security\cacerts



That's it . Now you can run your standalone java program without modifying it. 
Post your comments and Suggestions !!!
- See more at: http://www.javaroots.com/2013/05/no-name-matching-localhost-found-error.html#sthash.3T4xnaI3.dpuf
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved