Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loginservice
Overview
Overview
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
lanmw
loginservice
Commits
5a3a73b5
Commit
5a3a73b5
authored
Dec 22, 2020
by
chenzx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加单点登录认证接口和webserverservice接口
parent
5c8f4fa8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
204 additions
and
0 deletions
+204
-0
pom.xml
pom.xml
+13
-0
SSOCtrl.java
src/main/java/com/keymobile/proxy/api/SSOCtrl.java
+95
-0
WebServiceConfig.java
src/main/java/com/keymobile/proxy/conf/WebServiceConfig.java
+57
-0
Des.java
src/main/java/com/keymobile/proxy/util/Des.java
+0
-0
WebServerService.java
src/main/java/com/keymobile/proxy/wss/WebServerService.java
+13
-0
WebServerServiceImpl.java
...va/com/keymobile/proxy/wss/impl/WebServerServiceImpl.java
+26
-0
No files found.
pom.xml
View file @
5a3a73b5
...
@@ -79,6 +79,19 @@
...
@@ -79,6 +79,19 @@
<groupId>
org.springframework.cloud
</groupId>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-config-client
</artifactId>
<artifactId>
spring-cloud-config-client
</artifactId>
</dependency>
</dependency>
<!-- CXF webservice -->
<dependency>
<groupId>
org.apache.cxf
</groupId>
<artifactId>
cxf-spring-boot-starter-jaxws
</artifactId>
<version>
3.2.1
</version>
</dependency>
<dependency>
<groupId>
org.hibernate
</groupId>
<artifactId>
hibernate-validator
</artifactId>
<version>
5.2.4.Final
</version>
</dependency>
<!-- CXF webservice -->
</dependencies>
</dependencies>
<dependencyManagement>
<dependencyManagement>
...
...
src/main/java/com/keymobile/proxy/api/SSOCtrl.java
0 → 100644
View file @
5a3a73b5
package
com
.
keymobile
.
proxy
.
api
;
import
com.keymobile.proxy.util.Des
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.web.bind.annotation.*
;
import
javax.naming.AuthenticationException
;
import
javax.naming.Context
;
import
javax.naming.NamingException
;
import
javax.naming.directory.DirContext
;
import
javax.naming.directory.InitialDirContext
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.PrintWriter
;
import
java.util.Properties
;
@RestController
@RequestMapping
(
"/sso"
)
public
class
SSOCtrl
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
SSOCtrl
.
class
);
@RequestMapping
(
value
=
"/login"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ResponseBody
public
void
login
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@RequestParam
(
name
=
"portal_actionURL"
)
String
portal_actionURL
,
@RequestParam
(
name
=
"portal_username"
)
String
portal_username
,
@RequestParam
(
name
=
"portal_password"
)
String
portal_password
,
@RequestParam
(
name
=
"CallBack"
)
String
callBack
,
@RequestParam
(
name
=
"key"
)
String
key
)
{
Des
des
=
new
Des
();
String
pwd
=
des
.
strDec
(
portal_password
,
key
);
logger
.
info
(
"sso login param->userName:"
+
portal_username
+
" pwd:"
+
pwd
);
String
str
=
""
;
if
(
authenticate
(
portal_username
,
pwd
)){
str
=
callBack
+
"({'query':{'results':{'postresult':'portal_ssologin_succeed'}}});"
;
}
else
{
str
=
callBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
;
}
try
{
PrintWriter
out
=
response
.
getWriter
();
out
.
println
(
str
);
out
.
flush
();
out
.
close
();
}
catch
(
Exception
e
){
logger
.
info
(
"PrintWriter Exception:"
+
e
.
getLocalizedMessage
());
e
.
printStackTrace
();
}
}
/**
* 验证用户登录
*
* @param userName
* String 用户名格式为 username或者username@hntobacco.com
湖南内网的domain必须是@hntobacco.com,不是hnyc.com
* @param password
* String
* @return boolean
*/
public
boolean
authenticate
(
String
userName
,
String
password
)
{
if
(
password
!=
null
&&
!
""
.
equals
(
password
.
trim
()))
{
DirContext
ctx1
;
try
{
String
domain
=
"@hntobacco.com"
;
Properties
ldapEnv
=
new
Properties
();
ldapEnv
.
put
(
Context
.
INITIAL_CONTEXT_FACTORY
,
"com.sun.jndi.ldap.LdapCtxFactory"
);
ldapEnv
.
put
(
Context
.
PROVIDER_URL
,
"ldap://hntobacco.com:389"
);
//服务器必须配置DNS,否则无法解析hntobacc.com
ldapEnv
.
put
(
Context
.
SECURITY_AUTHENTICATION
,
"simple"
);
String
user
=
userName
.
indexOf
(
domain
)
>
0
?
userName
:
userName
+
domain
;
ldapEnv
.
put
(
Context
.
SECURITY_PRINCIPAL
,
user
);
ldapEnv
.
put
(
Context
.
SECURITY_CREDENTIALS
,
password
);
ctx1
=
new
InitialDirContext
(
ldapEnv
);
ctx1
.
close
();
logger
.
info
(
"登录验证成功!"
);
return
true
;
}
catch
(
AuthenticationException
e
)
{
logger
.
info
(
"登录失败!"
+
e
.
getLocalizedMessage
());
e
.
printStackTrace
();
return
false
;
}
catch
(
NamingException
e
)
{
logger
.
info
(
"登录失败!"
+
e
.
getLocalizedMessage
());
e
.
printStackTrace
();
return
false
;
}
}
else
{
logger
.
info
(
"登录验证失败!"
);
return
false
;
}
}
}
src/main/java/com/keymobile/proxy/conf/WebServiceConfig.java
0 → 100644
View file @
5a3a73b5
package
com
.
keymobile
.
proxy
.
conf
;
import
com.keymobile.proxy.wss.WebServerService
;
import
org.apache.cxf.Bus
;
import
org.apache.cxf.bus.spring.SpringBus
;
import
org.apache.cxf.jaxws.EndpointImpl
;
import
org.apache.cxf.transport.servlet.CXFServlet
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.xml.ws.Endpoint
;
@Configuration
public
class
WebServiceConfig
{
@Autowired
private
WebServerService
serverService
;
/**
* Apache CXF 核心架构是以BUS为核心,整合其他组件。
* Bus是CXF的主干, 为共享资源提供一个可配置的场所,作用类似于Spring的ApplicationContext,这些共享资源包括
* WSDl管理器、绑定工厂等。通过对BUS进行扩展,可以方便地容纳自己的资源,或者替换现有的资源。默认Bus实现基于Spring架构,
* 通过依赖注入,在运行时将组件串联起来。BusFactory负责Bus的创建。默认的BusFactory是SpringBusFactory,对应于默认
* 的Bus实现。在构造过程中,SpringBusFactory会搜索META-INF/cxf(包含在 CXF 的jar中)下的所有bean配置文件。
* 根据这些配置文件构建一个ApplicationContext。开发者也可以提供自己的配置文件来定制Bus。
*/
@Bean
(
name
=
Bus
.
DEFAULT_BUS_ID
)
public
SpringBus
springBus
()
{
return
new
SpringBus
();
}
/**
* 此方法作用是改变项目中服务名的前缀名,此处127.0.0.1或者localhost不能访问时,请使用ipconfig查看本机ip来访问
* 此方法被注释后, 即不改变前缀名(默认是services), wsdl访问地址为 http://127.0.0.1:8080/services/ws/api?wsdl
* 去掉注释后wsdl访问地址为:http://127.0.0.1:8080/soap/ws/api?wsdl
* http://127.0.0.1:8080/soap/列出服务列表 或 http://127.0.0.1:8080/soap/ws/api?wsdl 查看实际的服务
* 新建Servlet记得需要在启动类添加注解:@ServletComponentScan
*
* 如果启动时出现错误:not loaded because DispatcherServlet Registration found non dispatcher servlet dispatcherServlet
* 可能是springboot与cfx版本不兼容。
* 同时在spring boot2.0.6之后的版本与xcf集成,不需要在定义以下方法,直接在application.properties配置文件中添加:
* cxf.path=/service(默认是services)
*/
@Bean
(
name
=
"cxfServlet"
)
public
ServletRegistrationBean
dispatcherServlet
()
{
return
new
ServletRegistrationBean
(
new
CXFServlet
(),
"/soap/*"
);
}
@Bean
public
Endpoint
endpoint
()
{
EndpointImpl
endpoint
=
new
EndpointImpl
(
springBus
(),
serverService
);
endpoint
.
publish
(
"/wss/GetPermission"
);
return
endpoint
;
}
}
src/main/java/com/keymobile/proxy/util/Des.java
0 → 100644
View file @
5a3a73b5
This diff is collapsed.
Click to expand it.
src/main/java/com/keymobile/proxy/wss/WebServerService.java
0 → 100644
View file @
5a3a73b5
package
com
.
keymobile
.
proxy
.
wss
;
import
javax.jws.WebMethod
;
import
javax.jws.WebParam
;
import
javax.jws.WebService
;
@WebService
(
name
=
"SSOServerService"
,
targetNamespace
=
"http://wss.proxy.keymobile.com"
)
public
interface
WebServerService
{
@WebMethod
String
GetPermission
(
@WebParam
String
userId
);
}
src/main/java/com/keymobile/proxy/wss/impl/WebServerServiceImpl.java
0 → 100644
View file @
5a3a73b5
package
com
.
keymobile
.
proxy
.
wss
.
impl
;
import
com.keymobile.proxy.wss.WebServerService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
javax.jws.WebService
;
@Component
@WebService
(
name
=
"SSOServerService"
,
targetNamespace
=
"http://wss.proxy.keymobile.com"
,
endpointInterface
=
"com.keymobile.proxy.wss.WebServerService"
)
public
class
WebServerServiceImpl
implements
WebServerService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
WebServerServiceImpl
.
class
);
@Override
public
String
GetPermission
(
String
userId
)
{
if
(
null
==
userId
||
""
.
equals
(
userId
.
trim
())){
logger
.
info
(
"GetPermission传递userId参数为空"
);
return
"0"
;
}
logger
.
info
(
"GetPermission传递userId:"
+
userId
);
return
"1"
;
}
}
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