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
a474d5ca
Commit
a474d5ca
authored
Jun 27, 2016
by
张乐
Committed by
GitHub
Jun 27, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #300 from nobodyiam/assign-role-result
return users assigned and adjust rest template timeout
parents
78912008
a0a6a43b
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
65 additions
and
26 deletions
+65
-26
ServerConfigService.java
...rip/framework/apollo/biz/service/ServerConfigService.java
+5
-0
ActiveUser.java
...va/com/ctrip/framework/apollo/common/auth/ActiveUser.java
+0
-17
API.java
.../main/java/com/ctrip/framework/apollo/portal/api/API.java
+0
-1
RestTemplateFactory.java
...trip/framework/apollo/portal/api/RestTemplateFactory.java
+28
-6
CtripUserService.java
.../ctrip/framework/apollo/portal/auth/CtripUserService.java
+22
-1
RolePermissionService.java
...ramework/apollo/portal/service/RolePermissionService.java
+5
-1
ServerConfigService.java
.../framework/apollo/portal/service/ServerConfigService.java
+5
-0
No files found.
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ServerConfigService.java
View file @
a474d5ca
...
...
@@ -41,6 +41,11 @@ public class ServerConfigService {
return
serverConfig
==
null
?
null
:
serverConfig
.
getValue
();
}
public
String
getValue
(
String
key
,
String
defaultValue
)
{
String
value
=
getValue
(
key
);
return
value
==
null
?
defaultValue
:
value
;
}
String
getDataCenter
()
{
return
Foundation
.
server
().
getDataCenter
();
}
...
...
apollo-common/src/main/java/com/ctrip/framework/apollo/common/auth/ActiveUser.java
deleted
100644 → 0
View file @
78912008
package
com
.
ctrip
.
framework
.
apollo
.
common
.
auth
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
@Target
({
ElementType
.
PARAMETER
,
ElementType
.
TYPE
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@AuthenticationPrincipal
public
@interface
ActiveUser
{
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/API.java
View file @
a474d5ca
...
...
@@ -5,7 +5,6 @@ import javax.annotation.PostConstruct;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.framework.apollo.common.auth.RestTemplateFactory
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.service.ServiceLocator
;
...
...
apollo-
common/src/main/java/com/ctrip/framework/apollo/common/auth
/RestTemplateFactory.java
→
apollo-
portal/src/main/java/com/ctrip/framework/apollo/portal/api
/RestTemplateFactory.java
View file @
a474d5ca
package
com
.
ctrip
.
framework
.
apollo
.
common
.
auth
;
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
api
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
com.google.common.io.BaseEncoding
;
import
com.ctrip.framework.apollo.portal.service.ServerConfigService
;
import
org.apache.http.Header
;
import
org.apache.http.auth.AuthScope
;
...
...
@@ -19,13 +19,18 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestTemplate
;
import
com.google.common.io.BaseEncoding
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
@Component
public
class
RestTemplateFactory
implements
FactoryBean
<
RestTemplate
>,
InitializingBean
{
@Autowired
private
HttpMessageConverters
httpMessageConverters
;
@Autowired
private
ServerConfigService
serverConfigService
;
private
RestTemplate
restTemplate
;
public
RestTemplate
getObject
()
{
...
...
@@ -54,7 +59,24 @@ public class RestTemplateFactory implements FactoryBean<RestTemplate>, Initializ
.
setDefaultHeaders
(
defaultHeaders
).
build
();
restTemplate
=
new
RestTemplate
(
httpMessageConverters
.
getConverters
());
restTemplate
.
setRequestFactory
(
new
HttpComponentsClientHttpRequestFactory
(
httpClient
));
HttpComponentsClientHttpRequestFactory
requestFactory
=
new
HttpComponentsClientHttpRequestFactory
(
httpClient
);
requestFactory
.
setConnectTimeout
(
getConnectTimeout
());
requestFactory
.
setReadTimeout
(
getReadTimeout
());
restTemplate
.
setRequestFactory
(
requestFactory
);
}
private
int
getConnectTimeout
()
{
String
connectTimeout
=
serverConfigService
.
getValue
(
"api.connectTimeout"
,
"3000"
);
return
Integer
.
parseInt
(
connectTimeout
);
}
private
int
getReadTimeout
()
{
String
readTimeout
=
serverConfigService
.
getValue
(
"api.readTimeout"
,
"10000"
);
return
Integer
.
parseInt
(
readTimeout
);
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/CtripUserService.java
View file @
a474d5ca
...
...
@@ -12,6 +12,8 @@ import org.springframework.core.ParameterizedTypeReference;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.client.ClientHttpRequestFactory
;
import
org.springframework.http.client.SimpleClientHttpRequestFactory
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.client.RestTemplate
;
...
...
@@ -31,13 +33,32 @@ public class CtripUserService implements UserService {
public
CtripUserService
(
ServerConfigService
serverConfigService
)
{
this
.
serverConfigService
=
serverConfigService
;
this
.
restTemplate
=
new
RestTemplate
();
this
.
restTemplate
=
new
RestTemplate
(
clientHttpRequestFactory
()
);
this
.
searchUserMatchFields
=
Lists
.
newArrayList
(
"empcode"
,
"empaccount"
,
"displayname"
,
"c_name"
,
"pinyin"
);
this
.
responseType
=
new
ParameterizedTypeReference
<
Map
<
String
,
List
<
UserServiceResponse
>>>()
{
};
}
private
ClientHttpRequestFactory
clientHttpRequestFactory
()
{
SimpleClientHttpRequestFactory
factory
=
new
SimpleClientHttpRequestFactory
();
factory
.
setConnectTimeout
(
getConnectTimeout
());
factory
.
setReadTimeout
(
getReadTimeout
());
return
factory
;
}
private
int
getConnectTimeout
()
{
String
connectTimeout
=
serverConfigService
.
getValue
(
"api.connectTimeout"
,
"3000"
);
return
Integer
.
parseInt
(
connectTimeout
);
}
private
int
getReadTimeout
()
{
String
readTimeout
=
serverConfigService
.
getValue
(
"api.readTimeout"
,
"3000"
);
return
Integer
.
parseInt
(
readTimeout
);
}
@Override
public
List
<
UserInfo
>
searchUsers
(
String
keyword
,
int
offset
,
int
limit
)
{
UserServiceRequest
request
=
assembleSearchUserRequest
(
keyword
,
offset
,
limit
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RolePermissionService.java
View file @
a474d5ca
...
...
@@ -87,9 +87,12 @@ public class RolePermissionService implements InitializingBean {
/**
* Assign role to users
*
* @return the users assigned roles
*/
@Transactional
public
void
assignRoleToUsers
(
String
roleName
,
Set
<
String
>
userIds
,
String
operatorUserId
)
{
public
Set
<
String
>
assignRoleToUsers
(
String
roleName
,
Set
<
String
>
userIds
,
String
operatorUserId
)
{
Role
role
=
findRoleByRoleName
(
roleName
);
Preconditions
.
checkState
(
role
!=
null
,
"Role %s doesn't exist!"
,
roleName
);
...
...
@@ -110,6 +113,7 @@ public class RolePermissionService implements InitializingBean {
});
userRoleRepository
.
save
(
toCreate
);
return
toAssignUserIds
;
}
/**
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ServerConfigService.java
View file @
a474d5ca
...
...
@@ -28,4 +28,9 @@ public class ServerConfigService {
return
serverConfig
==
null
?
null
:
serverConfig
.
getValue
();
}
public
String
getValue
(
String
key
,
String
defaultValue
)
{
String
value
=
getValue
(
key
);
return
value
==
null
?
defaultValue
:
value
;
}
}
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