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
fd3ad44b
Commit
fd3ad44b
authored
Aug 14, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
384c3271
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
9 deletions
+63
-9
SAPServiceFactory.java
src/main/java/com/egolm/sso/clients/SAPServiceFactory.java
+63
-9
No files found.
src/main/java/com/egolm/sso/clients/SAPServiceFactory.java
View file @
fd3ad44b
...
...
@@ -3,14 +3,21 @@ 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
;
import
javax.xml.ws.Service
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.cxf.frontend.ClientProxy
;
import
org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor
;
import
org.apache.ws.security.handler.WSHandlerConstants
;
...
...
@@ -24,12 +31,18 @@ import com.egolm.sso.config.XRException;
@Component
public
class
SAPServiceFactory
{
Log
logger
=
LogFactory
.
getLog
(
SAPServiceFactory
.
class
);
@Value
(
"${schneider.username}"
)
private
String
username
;
@Value
(
"${schneider.password}"
)
private
String
password
;
public
SAPServiceFactory
()
throws
KeyManagementException
,
NoSuchAlgorithmException
{
trustAllHttpsCertificates
();
HttpsURLConnection
.
setDefaultHostnameVerifier
(
hv
);
}
public
<
T
>
T
create
(
Class
<
T
>
requiredType
,
String
WSDLPATH
,
QName
serviceQName
,
QName
portQName
)
{
assert
requiredType
!=
null
:
"WebService requiredType cannot be null"
;
...
...
@@ -38,18 +51,19 @@ public class SAPServiceFactory {
try
{
URL
WSDL_URL
=
new
URL
(
this
.
getAbsolutePath
(
WSDLPATH
));
Service
dyService
=
Service
.
create
(
WSDL_URL
,
serviceQName
);
T
service
=
portQName
==
null
?
dyService
.
getPort
(
requiredType
)
:
dyService
.
getPort
(
portQName
,
requiredType
);
T
service
=
portQName
==
null
?
dyService
.
getPort
(
requiredType
)
:
dyService
.
getPort
(
portQName
,
requiredType
);
ClientProxy
.
getClient
(
service
).
getOutInterceptors
().
add
(
getWSS4JOutInterceptor
());
return
service
;
}
catch
(
MalformedURLException
e
)
{
throw
new
XRException
(
e
);
}
}
private
static
String
absolutePath
=
null
;
private
String
getAbsolutePath
(
String
WSDLPATH
)
{
if
(
absolutePath
==
null
)
{
if
(
absolutePath
==
null
)
{
ApplicationHome
home
=
new
ApplicationHome
(
getClass
());
File
jarFile
=
home
.
getSource
();
File
folder
=
jarFile
.
getParentFile
();
...
...
@@ -57,11 +71,11 @@ public class SAPServiceFactory {
}
return
"file:///"
+
absolutePath
+
"/"
+
WSDLPATH
;
}
private
WSS4JOutInterceptor
wss4JOutInterceptor
=
null
;
public
WSS4JOutInterceptor
getWSS4JOutInterceptor
()
{
if
(
wss4JOutInterceptor
==
null
)
{
if
(
wss4JOutInterceptor
==
null
)
{
Map
<
String
,
Object
>
pro
=
new
HashMap
<
String
,
Object
>();
pro
.
put
(
WSHandlerConstants
.
ACTION
,
WSHandlerConstants
.
USERNAME_TOKEN
);
pro
.
put
(
WSHandlerConstants
.
USER
,
username
);
...
...
@@ -78,8 +92,48 @@ public class SAPServiceFactory {
}
return
wss4JOutInterceptor
;
}
public
enum
PasswordType
{
PasswordText
,
PasswordNone
,
PasswordDigest
}
HostnameVerifier
hv
=
new
HostnameVerifier
()
{
public
boolean
verify
(
String
urlHostName
,
SSLSession
session
)
{
logger
.
warn
(
"Warning: URL Host: "
+
urlHostName
+
" vs. "
+
session
.
getPeerHost
());
return
true
;
}
};
private
void
trustAllHttpsCertificates
()
throws
KeyManagementException
,
NoSuchAlgorithmException
{
javax
.
net
.
ssl
.
TrustManager
[]
trustAllCerts
=
new
javax
.
net
.
ssl
.
TrustManager
[
1
];
javax
.
net
.
ssl
.
TrustManager
tm
=
new
miTM
();
trustAllCerts
[
0
]
=
tm
;
javax
.
net
.
ssl
.
SSLContext
sc
=
javax
.
net
.
ssl
.
SSLContext
.
getInstance
(
"SSL"
);
sc
.
init
(
null
,
trustAllCerts
,
null
);
javax
.
net
.
ssl
.
HttpsURLConnection
.
setDefaultSSLSocketFactory
(
sc
.
getSocketFactory
());
}
static
class
miTM
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
;
}
}
}
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