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
Show 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;
...
@@ -3,14 +3,21 @@ package com.egolm.sso.clients;
import
java.io.File
;
import
java.io.File
;
import
java.net.MalformedURLException
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URL
;
import
java.security.KeyManagementException
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
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.Callback
;
import
javax.security.auth.callback.CallbackHandler
;
import
javax.security.auth.callback.CallbackHandler
;
import
javax.xml.namespace.QName
;
import
javax.xml.namespace.QName
;
import
javax.xml.ws.Service
;
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.frontend.ClientProxy
;
import
org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor
;
import
org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor
;
import
org.apache.ws.security.handler.WSHandlerConstants
;
import
org.apache.ws.security.handler.WSHandlerConstants
;
...
@@ -24,12 +31,18 @@ import com.egolm.sso.config.XRException;
...
@@ -24,12 +31,18 @@ import com.egolm.sso.config.XRException;
@Component
@Component
public
class
SAPServiceFactory
{
public
class
SAPServiceFactory
{
Log
logger
=
LogFactory
.
getLog
(
SAPServiceFactory
.
class
);
@Value
(
"${schneider.username}"
)
@Value
(
"${schneider.username}"
)
private
String
username
;
private
String
username
;
@Value
(
"${schneider.password}"
)
@Value
(
"${schneider.password}"
)
private
String
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
)
{
public
<
T
>
T
create
(
Class
<
T
>
requiredType
,
String
WSDLPATH
,
QName
serviceQName
,
QName
portQName
)
{
assert
requiredType
!=
null
:
"WebService requiredType cannot be null"
;
assert
requiredType
!=
null
:
"WebService requiredType cannot be null"
;
...
@@ -38,7 +51,8 @@ public class SAPServiceFactory {
...
@@ -38,7 +51,8 @@ public class SAPServiceFactory {
try
{
try
{
URL
WSDL_URL
=
new
URL
(
this
.
getAbsolutePath
(
WSDLPATH
));
URL
WSDL_URL
=
new
URL
(
this
.
getAbsolutePath
(
WSDLPATH
));
Service
dyService
=
Service
.
create
(
WSDL_URL
,
serviceQName
);
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
());
ClientProxy
.
getClient
(
service
).
getOutInterceptors
().
add
(
getWSS4JOutInterceptor
());
return
service
;
return
service
;
}
catch
(
MalformedURLException
e
)
{
}
catch
(
MalformedURLException
e
)
{
...
@@ -49,7 +63,7 @@ public class SAPServiceFactory {
...
@@ -49,7 +63,7 @@ public class SAPServiceFactory {
private
static
String
absolutePath
=
null
;
private
static
String
absolutePath
=
null
;
private
String
getAbsolutePath
(
String
WSDLPATH
)
{
private
String
getAbsolutePath
(
String
WSDLPATH
)
{
if
(
absolutePath
==
null
)
{
if
(
absolutePath
==
null
)
{
ApplicationHome
home
=
new
ApplicationHome
(
getClass
());
ApplicationHome
home
=
new
ApplicationHome
(
getClass
());
File
jarFile
=
home
.
getSource
();
File
jarFile
=
home
.
getSource
();
File
folder
=
jarFile
.
getParentFile
();
File
folder
=
jarFile
.
getParentFile
();
...
@@ -61,7 +75,7 @@ public class SAPServiceFactory {
...
@@ -61,7 +75,7 @@ public class SAPServiceFactory {
private
WSS4JOutInterceptor
wss4JOutInterceptor
=
null
;
private
WSS4JOutInterceptor
wss4JOutInterceptor
=
null
;
public
WSS4JOutInterceptor
getWSS4JOutInterceptor
()
{
public
WSS4JOutInterceptor
getWSS4JOutInterceptor
()
{
if
(
wss4JOutInterceptor
==
null
)
{
if
(
wss4JOutInterceptor
==
null
)
{
Map
<
String
,
Object
>
pro
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
pro
=
new
HashMap
<
String
,
Object
>();
pro
.
put
(
WSHandlerConstants
.
ACTION
,
WSHandlerConstants
.
USERNAME_TOKEN
);
pro
.
put
(
WSHandlerConstants
.
ACTION
,
WSHandlerConstants
.
USERNAME_TOKEN
);
pro
.
put
(
WSHandlerConstants
.
USER
,
username
);
pro
.
put
(
WSHandlerConstants
.
USER
,
username
);
...
@@ -82,4 +96,44 @@ public class SAPServiceFactory {
...
@@ -82,4 +96,44 @@ public class SAPServiceFactory {
public
enum
PasswordType
{
public
enum
PasswordType
{
PasswordText
,
PasswordNone
,
PasswordDigest
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