Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
4c071efb
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4c071efb
编写于
6月 03, 2016
作者:
L
lepdou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sso相关代码重构
上级
8c57944b
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
99 addition
and
55 deletion
+99
-55
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/CtripLogoutHandler.java
...trip/framework/apollo/portal/auth/CtripLogoutHandler.java
+39
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/CtripUserInfoHolder.java
...rip/framework/apollo/portal/auth/CtripUserInfoHolder.java
+2
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/DefaultLogoutHandler.java
...ip/framework/apollo/portal/auth/DefaultLogoutHandler.java
+18
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/DefaultUserInfoHolder.java
...p/framework/apollo/portal/auth/DefaultUserInfoHolder.java
+2
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/LogoutHandler.java
...com/ctrip/framework/apollo/portal/auth/LogoutHandler.java
+10
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/configutation/AuthConfiguration.java
...mework/apollo/portal/configutation/AuthConfiguration.java
+19
-5
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/configutation/ServletContextConfiguration.java
...llo/portal/configutation/ServletContextConfiguration.java
+5
-3
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PortalUserInfoController.java
...rk/apollo/portal/controller/PortalUserInfoController.java
+4
-43
未找到文件。
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/CtripLogoutHandler.java
0 → 100644
浏览文件 @
4c071efb
package
com.ctrip.framework.apollo.portal.auth
;
import
com.ctrip.framework.apollo.portal.repository.ServerConfigRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.io.IOException
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
public
class
CtripLogoutHandler
implements
LogoutHandler
{
@Autowired
private
ServerConfigRepository
serverConfigRepository
;
@Override
public
void
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
//将session销毁
request
.
getSession
().
invalidate
();
Cookie
cookie
=
new
Cookie
(
"memCacheAssertionID"
,
null
);
//将cookie的有效期设置为0,命令浏览器删除该cookie
cookie
.
setMaxAge
(
0
);
cookie
.
setPath
(
request
.
getContextPath
()
+
"/"
);
response
.
addCookie
(
cookie
);
//重定向到SSO的logout地址
String
casServerUrl
=
serverConfigRepository
.
findByKey
(
"casServerUrlPrefix"
).
getValue
();
String
serverName
=
serverConfigRepository
.
findByKey
(
"serverName"
).
getValue
();
try
{
response
.
sendRedirect
(
casServerUrl
+
"/logout?service="
+
serverName
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/CtripUserInfoHolder.java
浏览文件 @
4c071efb
...
...
@@ -21,7 +21,7 @@ public class CtripUserInfoHolder implements UserInfoHolder{
assertionHolder
=
clazz
.
newInstance
();
getAssertion
=
assertionHolder
.
getClass
().
getMethod
(
"getAssertion"
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"in
stance listen
er fail"
,
e
);
throw
new
RuntimeException
(
"in
it AssertionHold
er fail"
,
e
);
}
}
...
...
@@ -40,7 +40,7 @@ public class CtripUserInfoHolder implements UserInfoHolder{
return
userInfo
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
""
,
e
);
throw
new
RuntimeException
(
"
get user info from assertion holder error
"
,
e
);
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/DefaultLogoutHandler.java
0 → 100644
浏览文件 @
4c071efb
package
com.ctrip.framework.apollo.portal.auth
;
import
java.io.IOException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
public
class
DefaultLogoutHandler
implements
LogoutHandler
{
@Override
public
void
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
try
{
response
.
sendRedirect
(
"/"
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/
NotCtrip
UserInfoHolder.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/
Default
UserInfoHolder.java
浏览文件 @
4c071efb
...
...
@@ -5,10 +5,10 @@ import com.ctrip.framework.apollo.portal.entity.po.UserInfo;
/**
* 不是ctrip的公司默认提供一个假用户
*/
public
class
NotCtrip
UserInfoHolder
implements
UserInfoHolder
{
public
class
Default
UserInfoHolder
implements
UserInfoHolder
{
public
NotCtrip
UserInfoHolder
(){
public
Default
UserInfoHolder
(){
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/LogoutHandler.java
0 → 100644
浏览文件 @
4c071efb
package
com.ctrip.framework.apollo.portal.auth
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
public
interface
LogoutHandler
{
void
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/configutation/AuthConfiguration.java
浏览文件 @
4c071efb
package
com.ctrip.framework.apollo.portal.configutation
;
import
com.ctrip.framework.apollo.portal.auth.CtripLogoutHandler
;
import
com.ctrip.framework.apollo.portal.auth.CtripUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.NotCtripUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.DefaultLogoutHandler
;
import
com.ctrip.framework.apollo.portal.auth.DefaultUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.repository.ServerConfigRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.context.embedded.FilterRegistrationBean
;
import
org.springframework.boot.context.embedded.ServletListenerRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -31,7 +34,7 @@ public class AuthConfiguration {
*/
@Configuration
@Profile
(
"ctrip"
)
static
class
Ctrip
ProfileConfiguration
{
static
class
Ctrip
AuthAutoConfiguration
{
@Autowired
private
ServerConfigRepository
serverConfigRepository
;
...
...
@@ -109,6 +112,11 @@ public class AuthConfiguration {
return
new
CtripUserInfoHolder
();
}
@Bean
public
CtripLogoutHandler
logoutHandler
(){
return
new
CtripLogoutHandler
();
}
private
Filter
filter
(
String
className
){
Class
clazz
=
null
;
try
{
...
...
@@ -137,11 +145,17 @@ public class AuthConfiguration {
* 默认实现
*/
@Configuration
static
class
NotCtripProfileConfiguration
{
@ConditionalOnMissingBean
(
CtripUserInfoHolder
.
class
)
static
class
DefaultAuthAutoConfiguration
{
@Bean
public
DefaultUserInfoHolder
notCtripUserInfoHolder
(){
return
new
DefaultUserInfoHolder
();
}
@Bean
public
NotCtripUserInfoHolder
notCtripUserInfoHold
er
(){
return
new
NotCtripUserInfoHold
er
();
public
DefaultLogoutHandler
logoutHandl
er
(){
return
new
DefaultLogoutHandl
er
();
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/configutation/ServletContextConfiguration.java
浏览文件 @
4c071efb
...
...
@@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.context.embedded.ServletContextInitializer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Profile
;
import
javax.servlet.ServletContext
;
import
javax.servlet.ServletException
;
@Configuration
@Profile
(
"ctrip"
)
public
class
ServletContextConfiguration
{
@Autowired
...
...
@@ -27,9 +29,9 @@ public class ServletContextConfiguration {
ServerConfig
loggingServerIP
=
serverConfigRepository
.
findByKey
(
"loggingServerIP"
);
ServerConfig
loggingServerPort
=
serverConfigRepository
.
findByKey
(
"loggingServerPort"
);
ServerConfig
credisServiceUrl
=
serverConfigRepository
.
findByKey
(
"credisServiceUrl"
);
servletContext
.
setInitParameter
(
"loggingServerIP"
,
loggingServerIP
==
null
?
""
:
loggingServerIP
.
getValue
());
servletContext
.
setInitParameter
(
"loggingServerPort"
,
loggingServerPort
==
null
?
""
:
loggingServerPort
.
getValue
());
servletContext
.
setInitParameter
(
"credisServiceUrl"
,
credisServiceUrl
==
null
?
""
:
credisServiceUrl
.
getValue
());
servletContext
.
setInitParameter
(
"loggingServerIP"
,
loggingServerIP
==
null
?
""
:
loggingServerIP
.
getValue
());
servletContext
.
setInitParameter
(
"loggingServerPort"
,
loggingServerPort
==
null
?
""
:
loggingServerPort
.
getValue
());
servletContext
.
setInitParameter
(
"credisServiceUrl"
,
credisServiceUrl
==
null
?
""
:
credisServiceUrl
.
getValue
());
}
};
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PortalUserInfoController.java
浏览文件 @
4c071efb
package
com.ctrip.framework.apollo.portal.controller
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.portal.auth.CtripUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.NotCtripUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.LogoutHandler
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.entity.po.UserInfo
;
import
com.ctrip.framework.apollo.portal.repository.ServerConfigRepository
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.io.IOException
;
import
javax.annotation.PostConstruct
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
@RestController
public
class
PortalUserInfoController
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
PortalUserInfoController
.
class
);
@Autowired
private
ApplicationContext
applicationContext
;
@Autowired
private
ServerConfigRepository
serverConfigRepository
;
private
UserInfoHolder
userInfoHolder
;
@PostConstruct
public
void
post
()
{
try
{
userInfoHolder
=
applicationContext
.
getBean
(
CtripUserInfoHolder
.
class
);
}
catch
(
NoSuchBeanDefinitionException
e
)
{
logger
.
debug
(
"default user info holder"
);
userInfoHolder
=
applicationContext
.
getBean
(
NotCtripUserInfoHolder
.
class
);
}
}
@Autowired
private
LogoutHandler
logoutHandler
;
@RequestMapping
(
"/user"
)
public
UserInfo
getCurrentUserName
()
{
try
{
return
userInfoHolder
.
getUser
();
}
catch
(
Exception
e
)
{
throw
new
BadRequestException
(
"请先登录"
);
}
}
@RequestMapping
(
"/user/logout"
)
public
void
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
//将session销毁
request
.
getSession
().
invalidate
();
Cookie
cookie
=
new
Cookie
(
"memCacheAssertionID"
,
null
);
//将cookie的有效期设置为0,命令浏览器删除该cookie
cookie
.
setMaxAge
(
0
);
cookie
.
setPath
(
request
.
getContextPath
()
+
"/"
);
response
.
addCookie
(
cookie
);
//重定向到SSO的logout地址
String
casServerUrl
=
serverConfigRepository
.
findByKey
(
"casServerUrlPrefix"
).
getValue
();
String
serverName
=
serverConfigRepository
.
findByKey
(
"serverName"
).
getValue
();
response
.
sendRedirect
(
casServerUrl
+
"/logout?service="
+
serverName
);
logoutHandler
.
logout
(
request
,
response
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录