Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sap-service
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
sap-service
Commits
844954fc
Commit
844954fc
authored
Aug 14, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
6f15cce6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
45 deletions
+59
-45
SapServiceApplication.java
src/main/java/com/egolm/sso/SapServiceApplication.java
+6
-1
SAPServiceFactory.java
src/main/java/com/egolm/sso/clients/SAPServiceFactory.java
+1
-44
MyTrustManager.java
src/main/java/com/egolm/sso/util/MyTrustManager.java
+52
-0
No files found.
src/main/java/com/egolm/sso/SapServiceApplication.java
View file @
844954fc
package
com
.
egolm
.
sso
;
import
java.security.KeyManagementException
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.TimeZone
;
import
org.springframework.boot.SpringApplication
;
...
...
@@ -8,6 +10,8 @@ import org.springframework.context.ApplicationContext;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
com.egolm.sso.util.MyTrustManager
;
@EnableScheduling
@SpringBootApplication
@EnableTransactionManagement
...
...
@@ -15,8 +19,9 @@ public class SapServiceApplication {
private
static
ApplicationContext
applicationContext
;
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
KeyManagementException
,
NoSuchAlgorithmException
{
TimeZone
.
setDefault
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
MyTrustManager
.
trustAllHttpsCertificates
();
applicationContext
=
SpringApplication
.
run
(
SapServiceApplication
.
class
,
args
);
}
...
...
src/main/java/com/egolm/sso/clients/SAPServiceFactory.java
View file @
844954fc
...
...
@@ -3,14 +3,9 @@ package com.egolm.sso.clients;
import
java.io.File
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.security.KeyManagementException
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.net.ssl.HostnameVerifier
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.SSLSession
;
import
javax.security.auth.callback.Callback
;
import
javax.security.auth.callback.CallbackHandler
;
import
javax.xml.namespace.QName
;
...
...
@@ -39,21 +34,6 @@ public class SAPServiceFactory {
@Value
(
"${schneider.password}"
)
private
String
password
;
public
SAPServiceFactory
()
throws
KeyManagementException
,
NoSuchAlgorithmException
{
javax
.
net
.
ssl
.
TrustManager
[]
trustAllCerts
=
new
javax
.
net
.
ssl
.
TrustManager
[
1
];
javax
.
net
.
ssl
.
TrustManager
tm
=
new
MyTrustManager
();
trustAllCerts
[
0
]
=
tm
;
javax
.
net
.
ssl
.
SSLContext
sc
=
javax
.
net
.
ssl
.
SSLContext
.
getInstance
(
"SSL"
);
sc
.
init
(
null
,
trustAllCerts
,
null
);
HttpsURLConnection
.
setDefaultSSLSocketFactory
(
sc
.
getSocketFactory
());
HttpsURLConnection
.
setDefaultHostnameVerifier
(
new
HostnameVerifier
()
{
public
boolean
verify
(
String
urlHostName
,
SSLSession
session
)
{
logger
.
warn
(
"Warning: URL Host: "
+
urlHostName
+
" vs. "
+
session
.
getPeerHost
());
return
true
;
}
});
}
public
<
T
>
T
create
(
Class
<
T
>
requiredType
,
String
WSDLPATH
,
QName
serviceQName
)
{
assert
requiredType
!=
null
:
"WebService requiredType cannot be null"
;
assert
WSDLPATH
!=
null
:
"WebService WSDLPATH cannot be null"
;
...
...
@@ -105,28 +85,5 @@ public class SAPServiceFactory {
public
enum
PasswordType
{
PasswordText
,
PasswordNone
,
PasswordDigest
}
public
static
class
MyTrustManager
implements
javax
.
net
.
ssl
.
TrustManager
,
javax
.
net
.
ssl
.
X509TrustManager
{
public
java
.
security
.
cert
.
X509Certificate
[]
getAcceptedIssuers
()
{
return
null
;
}
public
boolean
isServerTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
certs
)
{
return
true
;
}
public
boolean
isClientTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
certs
)
{
return
true
;
}
public
void
checkServerTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
certs
,
String
authType
)
throws
java
.
security
.
cert
.
CertificateException
{
return
;
}
public
void
checkClientTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
certs
,
String
authType
)
throws
java
.
security
.
cert
.
CertificateException
{
return
;
}
}
}
src/main/java/com/egolm/sso/util/MyTrustManager.java
0 → 100644
View file @
844954fc
package
com
.
egolm
.
sso
.
util
;
import
java.security.KeyManagementException
;
import
java.security.NoSuchAlgorithmException
;
import
javax.net.ssl.HostnameVerifier
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.SSLSession
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
public
class
MyTrustManager
implements
javax
.
net
.
ssl
.
TrustManager
,
javax
.
net
.
ssl
.
X509TrustManager
{
private
final
static
Log
logger
=
LogFactory
.
getLog
(
MyTrustManager
.
class
);
public
static
void
trustAllHttpsCertificates
()
throws
NoSuchAlgorithmException
,
KeyManagementException
{
javax
.
net
.
ssl
.
TrustManager
[]
trustAllCerts
=
new
javax
.
net
.
ssl
.
TrustManager
[
1
];
javax
.
net
.
ssl
.
TrustManager
tm
=
new
MyTrustManager
();
trustAllCerts
[
0
]
=
tm
;
javax
.
net
.
ssl
.
SSLContext
sc
=
javax
.
net
.
ssl
.
SSLContext
.
getInstance
(
"SSL"
);
sc
.
init
(
null
,
trustAllCerts
,
null
);
HttpsURLConnection
.
setDefaultSSLSocketFactory
(
sc
.
getSocketFactory
());
HttpsURLConnection
.
setDefaultHostnameVerifier
(
new
HostnameVerifier
()
{
public
boolean
verify
(
String
urlHostName
,
SSLSession
session
)
{
logger
.
warn
(
"Warning: URL Host: "
+
urlHostName
+
" vs. "
+
session
.
getPeerHost
());
return
true
;
}
});
}
public
java
.
security
.
cert
.
X509Certificate
[]
getAcceptedIssuers
()
{
return
null
;
}
public
boolean
isServerTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
certs
)
{
return
true
;
}
public
boolean
isClientTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
certs
)
{
return
true
;
}
public
void
checkServerTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
certs
,
String
authType
)
throws
java
.
security
.
cert
.
CertificateException
{
return
;
}
public
void
checkClientTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
certs
,
String
authType
)
throws
java
.
security
.
cert
.
CertificateException
{
return
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment