SSLSocketFactory is null. This can occur if javax.net.ssl.SSLSocketFactory.getDefault() is called t
2015-03-13 11:37
609 查看
问题 :
tmcat运行正常,移植到was上时报: SSLSocketFactory is null. This can occur if javax.net.ssl.SSLSocketFactory.getDefault() is called to create a socket and javax.net.ssl.* properties are not set.
代码如下:
LdapContext ctx;
public test1() {
Hashtable<String, String> env = new Hashtable<String, String>();
try {
// 设置信任证书
System.setProperty("javax.net.ssl.trustStore",System.getProperty("java.home")+"/lib/security/cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldaps://10.0.7.5:636");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,"CN=*,OU=*,DC=sinokorealife,DC=*");
env.put(Context.SECURITY_CREDENTIALS, "Sinokorealife_AD");
ctx = new InitialLdapContext(env, null);
System.out.println("管理员连接成功");
String password="123456";
String username="test";
ModificationItem[] mods = new ModificationItem[1];
String newQuotedPassword = "\"" + password + "\"";
byte[] newUnicodePassword = newQuotedPassword.getBytes("UTF-16LE");
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("unicodePwd",newUnicodePassword));
ctx.modifyAttributes("CN="+username+",OU=SINOKOREALIFE,DC=sinokorealife,DC=biz", mods);
ctx.close();
if(check(username,password))
{
System.out.println("成功");
}
} catch (NamingException e) {
e.printStackTrace();
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
在 ctx = new InitialLdapContext(env, null); 报SLLSocketFactory is null
原因判定:
1 .在tomcat采用sun的jvm,而在was上则采用的是ibm的jvm,两者功能上大体相同,但是细节方面还是有略微差异,所以可能是兼容性的问题导致System.setProperty()没有 被读取。
解决方法:
System.setProperty("javax.net.ssl.trustStore",System.getProperty("java.home")+"/lib/security/cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
更换为
env.put("javax.net.ssl.trustStore","System.getProperty("java.home")+"/lib/security/cacerts"");
env.put("javax.net.ssl.trustStorePassword", "changeit");
另外
env.put(Context.SECURITY_PROTOCOL, "ssl");与
env.put(Context.PROVIDER_URL, "ldaps://10.0.7.5:636");冲突
修改为
env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.PROVIDER_URL, "ldap://10.0.7.5:636");
tmcat运行正常,移植到was上时报: SSLSocketFactory is null. This can occur if javax.net.ssl.SSLSocketFactory.getDefault() is called to create a socket and javax.net.ssl.* properties are not set.
代码如下:
LdapContext ctx;
public test1() {
Hashtable<String, String> env = new Hashtable<String, String>();
try {
// 设置信任证书
System.setProperty("javax.net.ssl.trustStore",System.getProperty("java.home")+"/lib/security/cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldaps://10.0.7.5:636");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,"CN=*,OU=*,DC=sinokorealife,DC=*");
env.put(Context.SECURITY_CREDENTIALS, "Sinokorealife_AD");
ctx = new InitialLdapContext(env, null);
System.out.println("管理员连接成功");
String password="123456";
String username="test";
ModificationItem[] mods = new ModificationItem[1];
String newQuotedPassword = "\"" + password + "\"";
byte[] newUnicodePassword = newQuotedPassword.getBytes("UTF-16LE");
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("unicodePwd",newUnicodePassword));
ctx.modifyAttributes("CN="+username+",OU=SINOKOREALIFE,DC=sinokorealife,DC=biz", mods);
ctx.close();
if(check(username,password))
{
System.out.println("成功");
}
} catch (NamingException e) {
e.printStackTrace();
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
在 ctx = new InitialLdapContext(env, null); 报SLLSocketFactory is null
原因判定:
1 .在tomcat采用sun的jvm,而在was上则采用的是ibm的jvm,两者功能上大体相同,但是细节方面还是有略微差异,所以可能是兼容性的问题导致System.setProperty()没有 被读取。
解决方法:
System.setProperty("javax.net.ssl.trustStore",System.getProperty("java.home")+"/lib/security/cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
更换为
env.put("javax.net.ssl.trustStore","System.getProperty("java.home")+"/lib/security/cacerts"");
env.put("javax.net.ssl.trustStorePassword", "changeit");
另外
env.put(Context.SECURITY_PROTOCOL, "ssl");与
env.put(Context.PROVIDER_URL, "ldaps://10.0.7.5:636");冲突
修改为
env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.PROVIDER_URL, "ldap://10.0.7.5:636");
相关文章推荐
- websphere sslSocketFactory,SSLSocketFactory.getDefault() is null
- 启动hadoop出现java.lang.ClassNotFoundException: javax.net.SocketFactory
- android 5.0 SSL Socket exception javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
- Here is what can get this system to converge
- javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites
- ASP.NET + AJAX 出现 this._form is null' 错误之解决
- Ajax :this.get_element().style is null
- Data is Null. This method or property cannot be called on Null values.
- java.lang.NoClassDefFoundError: javax/net/ssl/SSLSocket 问题解决
- 启动hadoop NoClassDefFoundError: javax/net/SocketFactory
- 一个坑:java.sql.ResultSet.getInt==》the column value; if the value is SQL NULL, the value returned is 0
- 403-In general, this can occur when there is a genuine Cross Site Request Forgery, or whe
- MOSS爬网问题Error from SharePoint site: Data is Null. This method or property cannot be called on Null values
- javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
- PhoneFactory.getDefaultPhone must be called from Looper thread
- 出错:PhoneFactory.getDefaultPhone must be called from Looper thread
- IF OBJECT_ID('UP_GET_XXX_SEQNO') IS NOT NULL
- mysql select column default value if is null
- Data is Null. This method or property cannot be called on Null values.错误分析
- About Derby "ERROR 42X51: The class '***' does not exist or is inaccessible. This can hap pen if the class is not public."