Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
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
openSource
apollo
Commits
7e920aeb
Commit
7e920aeb
authored
Jun 21, 2016
by
张乐
Committed by
GitHub
Jun 21, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #277 from nobodyiam/portal-super-admin
add super admin config and refactor server config service
parents
ef1a562f
7a280fb2
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
112 additions
and
47 deletions
+112
-47
PortalSettings.java
...ava/com/ctrip/framework/apollo/portal/PortalSettings.java
+18
-17
CtripLogoutHandler.java
...trip/framework/apollo/portal/auth/CtripLogoutHandler.java
+4
-4
AuthConfiguration.java
...mework/apollo/portal/configutation/AuthConfiguration.java
+6
-6
ServletContextConfiguration.java
...llo/portal/configutation/ServletContextConfiguration.java
+14
-10
OrganizationController.java
...work/apollo/portal/controller/OrganizationController.java
+10
-5
BizLoggingCustomizer.java
...amework/apollo/portal/customize/BizLoggingCustomizer.java
+4
-4
RolePermissionService.java
...ramework/apollo/portal/service/RolePermissionService.java
+33
-1
ServerConfigService.java
.../framework/apollo/portal/service/ServerConfigService.java
+23
-0
No files found.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalSettings.java
View file @
7e920aeb
package
com
.
ctrip
.
framework
.
apollo
.
portal
;
import
com.google.common.base.Strings
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.service.ServerConfigService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
...
...
@@ -14,19 +28,6 @@ import java.util.concurrent.TimeUnit;
import
javax.annotation.PostConstruct
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.stereotype.Component
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.entity.po.ServerConfig
;
import
com.ctrip.framework.apollo.portal.repository.ServerConfigRepository
;
@Component
public
class
PortalSettings
{
...
...
@@ -41,7 +42,7 @@ public class PortalSettings {
ApplicationContext
applicationContext
;
@Autowired
private
ServerConfig
Repository
serverConfigRepository
;
private
ServerConfig
Service
serverConfigService
;
private
List
<
Env
>
allEnvs
=
new
ArrayList
<
Env
>();
...
...
@@ -56,9 +57,9 @@ public class PortalSettings {
private
void
postConstruct
()
{
//初始化portal支持操作的环境集合,线上的portal可能支持所有的环境操作,而线下环境则支持一部分.
// 每个环境的portal支持哪些环境配置在数据库里
S
erverConfig
serverConfig
=
serverConfigRepository
.
findByKey
(
"apollo.portal.envs"
);
if
(
serverConfig
!=
null
){
String
[]
configedEnvs
=
serverConfig
.
getValue
().
split
(
","
);
S
tring
serverConfig
=
serverConfigService
.
getValue
(
"apollo.portal.envs"
);
if
(
!
Strings
.
isNullOrEmpty
(
serverConfig
)
){
String
[]
configedEnvs
=
serverConfig
.
split
(
","
);
allStrEnvs
=
Arrays
.
asList
(
configedEnvs
);
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/CtripLogoutHandler.java
View file @
7e920aeb
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
auth
;
import
com.ctrip.framework.apollo.portal.
repository.ServerConfigRepository
;
import
com.ctrip.framework.apollo.portal.
service.ServerConfigService
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -13,7 +13,7 @@ import javax.servlet.http.HttpServletResponse;
public
class
CtripLogoutHandler
implements
LogoutHandler
{
@Autowired
private
ServerConfig
Repository
serverConfigRepository
;
private
ServerConfig
Service
serverConfigService
;
@Override
public
void
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
...
...
@@ -27,8 +27,8 @@ public class CtripLogoutHandler implements LogoutHandler{
response
.
addCookie
(
cookie
);
//重定向到SSO的logout地址
String
casServerUrl
=
serverConfig
Repository
.
findByKey
(
"casServerUrlPrefix"
).
getValue
(
);
String
serverName
=
serverConfig
Repository
.
findByKey
(
"serverName"
).
getValue
(
);
String
casServerUrl
=
serverConfig
Service
.
getValue
(
"casServerUrlPrefix"
);
String
serverName
=
serverConfig
Service
.
getValue
(
"serverName"
);
try
{
response
.
sendRedirect
(
casServerUrl
+
"/logout?service="
+
serverName
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/configutation/AuthConfiguration.java
View file @
7e920aeb
...
...
@@ -6,7 +6,7 @@ import com.ctrip.framework.apollo.portal.auth.DefaultLogoutHandler;
import
com.ctrip.framework.apollo.portal.auth.DefaultUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.LogoutHandler
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.
repository.ServerConfigRepository
;
import
com.ctrip.framework.apollo.portal.
service.ServerConfigService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
...
...
@@ -39,7 +39,7 @@ public class AuthConfiguration {
static
class
CtripAuthAutoConfiguration
{
@Autowired
private
ServerConfig
Repository
serverConfigRepository
;
private
ServerConfig
Service
serverConfigService
;
@Bean
public
ServletListenerRegistrationBean
redisAppSettingListner
(){
...
...
@@ -69,8 +69,8 @@ public class AuthConfiguration {
Map
<
String
,
String
>
filterInitParam
=
new
HashMap
();
filterInitParam
.
put
(
"redisClusterName"
,
"casClientPrincipal"
);
filterInitParam
.
put
(
"serverName"
,
serverConfig
Repository
.
findByKey
(
"serverName"
).
getValue
(
));
filterInitParam
.
put
(
"casServerLoginUrl"
,
serverConfig
Repository
.
findByKey
(
"casServerLoginUrl"
).
getValue
(
));
filterInitParam
.
put
(
"serverName"
,
serverConfig
Service
.
getValue
(
"serverName"
));
filterInitParam
.
put
(
"casServerLoginUrl"
,
serverConfig
Service
.
getValue
(
"casServerLoginUrl"
));
casFilter
.
setInitParameters
(
filterInitParam
);
casFilter
.
setFilter
(
filter
(
"org.jasig.cas.client.authentication.AuthenticationFilter"
));
...
...
@@ -83,8 +83,8 @@ public class AuthConfiguration {
public
FilterRegistrationBean
casValidationFilter
(){
FilterRegistrationBean
casValidationFilter
=
new
FilterRegistrationBean
();
Map
<
String
,
String
>
filterInitParam
=
new
HashMap
();
filterInitParam
.
put
(
"casServerUrlPrefix"
,
serverConfig
Repository
.
findByKey
(
"casServerUrlPrefix"
).
getValue
(
));
filterInitParam
.
put
(
"serverName"
,
serverConfig
Repository
.
findByKey
(
"serverName"
).
getValue
(
));
filterInitParam
.
put
(
"casServerUrlPrefix"
,
serverConfig
Service
.
getValue
(
"casServerUrlPrefix"
));
filterInitParam
.
put
(
"serverName"
,
serverConfig
Service
.
getValue
(
"serverName"
));
filterInitParam
.
put
(
"encoding"
,
"UTF-8"
);
filterInitParam
.
put
(
"useRedis"
,
"true"
);
filterInitParam
.
put
(
"redisClusterName"
,
"casClientPrincipal"
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/configutation/ServletContextConfiguration.java
View file @
7e920aeb
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
configutation
;
import
com.ctrip.framework.apollo.portal.entity.po.ServerConfig
;
import
com.ctrip.framework.apollo.portal.repository.ServerConfigRepository
;
import
com.google.common.base.Strings
;
import
com.ctrip.framework.apollo.portal.service.ServerConfigService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.context.embedded.ServletContextInitializer
;
...
...
@@ -17,21 +18,24 @@ import javax.servlet.ServletException;
public
class
ServletContextConfiguration
{
@Autowired
private
ServerConfig
Repository
serverConfigRepository
;
private
ServerConfig
Service
serverConfigService
;
@Bean
public
ServletContextInitializer
initializer
(){
public
ServletContextInitializer
initializer
()
{
return
new
ServletContextInitializer
()
{
@Override
public
void
onStartup
(
ServletContext
servletContext
)
throws
ServletException
{
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
());
String
loggingServerIP
=
serverConfigService
.
getValue
(
"loggingServerIP"
);
String
loggingServerPort
=
serverConfigService
.
getValue
(
"loggingServerPort"
);
String
credisServiceUrl
=
serverConfigService
.
getValue
(
"credisServiceUrl"
);
servletContext
.
setInitParameter
(
"loggingServerIP"
,
Strings
.
isNullOrEmpty
(
loggingServerIP
)
?
""
:
loggingServerIP
);
servletContext
.
setInitParameter
(
"loggingServerPort"
,
Strings
.
isNullOrEmpty
(
loggingServerPort
)
?
""
:
loggingServerPort
);
servletContext
.
setInitParameter
(
"credisServiceUrl"
,
Strings
.
isNullOrEmpty
(
credisServiceUrl
)
?
""
:
credisServiceUrl
);
}
};
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/OrganizationController.java
View file @
7e920aeb
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
controller
;
import
com.google.common.base.Strings
;
import
com.google.gson.Gson
;
import
com.google.gson.reflect.TypeToken
;
import
com.ctrip.framework.apollo.portal.entity.po.ServerConfig
;
import
com.ctrip.framework.apollo.portal.entity.vo.Organization
;
import
com.ctrip.framework.apollo.portal.
repository.ServerConfigRepository
;
import
com.ctrip.framework.apollo.portal.
service.ServerConfigService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.lang.reflect.Type
;
import
java.util.Collections
;
import
java.util.List
;
/**
...
...
@@ -21,7 +22,7 @@ import java.util.List;
@RequestMapping
(
"/organizations"
)
public
class
OrganizationController
{
@Autowired
private
ServerConfig
Repository
serverConfigRepository
;
private
ServerConfig
Service
serverConfigService
;
@Autowired
private
Gson
gson
;
...
...
@@ -31,7 +32,11 @@ public class OrganizationController {
@RequestMapping
public
List
<
Organization
>
loadOrganization
()
{
ServerConfig
config
=
serverConfigRepository
.
findByKey
(
"organizations"
);
return
gson
.
fromJson
(
config
.
getValue
(),
responseType
);
String
organizations
=
serverConfigService
.
getValue
(
"organizations"
);
if
(
Strings
.
isNullOrEmpty
(
organizations
))
{
return
Collections
.
emptyList
();
}
return
gson
.
fromJson
(
organizations
,
responseType
);
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/customize/BizLoggingCustomizer.java
View file @
7e920aeb
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
customize
;
import
com.ctrip.framework.apollo.common.customize.LoggingCustomizer
;
import
com.ctrip.framework.apollo.portal.
repository.ServerConfigRepository
;
import
com.ctrip.framework.apollo.portal.
service.ServerConfigService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Profile
;
...
...
@@ -15,7 +15,7 @@ public class BizLoggingCustomizer extends LoggingCustomizer{
private
static
final
String
CLOGGING_SERVER_PORT_KEY
=
"clogging.server.port"
;
@Autowired
private
ServerConfig
Repository
serverConfigRepository
;
private
ServerConfig
Service
serverConfigService
;
private
String
cloggingUrl
;
private
String
cloggingPort
;
...
...
@@ -23,7 +23,7 @@ public class BizLoggingCustomizer extends LoggingCustomizer{
@Override
protected
String
cloggingUrl
()
{
if
(
cloggingUrl
==
null
){
cloggingUrl
=
serverConfig
Repository
.
findByKey
(
CLOGGING_SERVER_URL_KEY
).
getValue
(
);
cloggingUrl
=
serverConfig
Service
.
getValue
(
CLOGGING_SERVER_URL_KEY
);
}
return
cloggingUrl
;
}
...
...
@@ -31,7 +31,7 @@ public class BizLoggingCustomizer extends LoggingCustomizer{
@Override
protected
String
cloggingPort
()
{
if
(
cloggingPort
==
null
){
cloggingPort
=
serverConfig
Repository
.
findByKey
(
CLOGGING_SERVER_PORT_KEY
).
getValue
(
);
cloggingPort
=
serverConfig
Service
.
getValue
(
CLOGGING_SERVER_PORT_KEY
);
}
return
cloggingPort
;
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RolePermissionService.java
View file @
7e920aeb
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
service
;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Splitter
;
import
com.google.common.base.Strings
;
import
com.google.common.collect.FluentIterable
;
import
com.google.common.collect.HashMultimap
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Multimap
;
import
com.google.common.collect.Sets
;
...
...
@@ -16,6 +19,7 @@ import com.ctrip.framework.apollo.portal.repository.RolePermissionRepository;
import
com.ctrip.framework.apollo.portal.repository.RoleRepository
;
import
com.ctrip.framework.apollo.portal.repository.UserRoleRepository
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -31,7 +35,7 @@ import java.util.Set;
* @author Jason Song(song_s@ctrip.com)
*/
@Service
public
class
RolePermissionService
{
public
class
RolePermissionService
implements
InitializingBean
{
@Autowired
private
RoleRepository
roleRepository
;
...
...
@@ -44,6 +48,17 @@ public class RolePermissionService {
@Autowired
private
PermissionRepository
permissionRepository
;
@Autowired
private
ServerConfigService
serverConfigService
;
private
List
<
String
>
superAdminUsers
;
private
Splitter
configSplitter
;
public
RolePermissionService
()
{
superAdminUsers
=
Lists
.
newArrayList
();
configSplitter
=
Splitter
.
on
(
","
).
omitEmptyStrings
().
trimResults
();
}
/**
* Create role with permissions, note that role name should be unique
*/
...
...
@@ -155,6 +170,10 @@ public class RolePermissionService {
return
false
;
}
if
(
isSuperAdmin
(
userId
))
{
return
true
;
}
List
<
UserRole
>
userRoles
=
userRoleRepository
.
findByUserId
(
userId
);
if
(
CollectionUtils
.
isEmpty
(
userRoles
))
{
return
false
;
...
...
@@ -176,6 +195,10 @@ public class RolePermissionService {
return
false
;
}
private
boolean
isSuperAdmin
(
String
userId
)
{
return
superAdminUsers
.
contains
(
userId
);
}
/**
* Create permission, note that permissionType + targetId should be unique
*/
...
...
@@ -213,4 +236,13 @@ public class RolePermissionService {
Iterable
<
Permission
>
results
=
permissionRepository
.
save
(
permissions
);
return
FluentIterable
.
from
(
results
).
toSet
();
}
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
String
superAdminConfig
=
serverConfigService
.
getValue
(
"superAdmin"
);
if
(
Strings
.
isNullOrEmpty
(
superAdminConfig
))
{
return
;
}
superAdminUsers
=
configSplitter
.
splitToList
(
superAdminConfig
);
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ServerConfigService.java
0 → 100644
View file @
7e920aeb
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
service
;
import
com.ctrip.framework.apollo.portal.entity.po.ServerConfig
;
import
com.ctrip.framework.apollo.portal.repository.ServerConfigRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Service
public
class
ServerConfigService
{
@Autowired
private
ServerConfigRepository
serverConfigRepository
;
public
String
getValue
(
String
key
)
{
ServerConfig
serverConfig
=
serverConfigRepository
.
findByKey
(
key
);
return
serverConfig
==
null
?
null
:
serverConfig
.
getValue
();
}
}
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