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
c7e30148
Commit
c7e30148
authored
Apr 19, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add auth header
parent
e79343cf
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
6 deletions
+16
-6
RestTemplateFactory.java
...ava/com/ctrip/apollo/common/auth/RestTemplateFactory.java
+16
-2
AppService.java
...main/java/com/ctrip/apollo/portal/service/AppService.java
+0
-4
No files found.
apollo-common/src/main/java/com/ctrip/apollo/common/auth/RestTemplateFactory.java
View file @
c7e30148
package
com
.
ctrip
.
apollo
.
common
.
auth
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
org.apache.http.Header
;
import
org.apache.http.auth.AuthScope
;
import
org.apache.http.auth.UsernamePasswordCredentials
;
import
org.apache.http.impl.client.BasicCredentialsProvider
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.message.BasicHeader
;
import
org.springframework.beans.factory.FactoryBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestTemplate
;
import
com.google.common.io.BaseEncoding
;
@Component
public
class
RestTemplateFactory
implements
FactoryBean
<
RestTemplate
>,
InitializingBean
{
...
...
@@ -28,12 +36,18 @@ public class RestTemplateFactory implements FactoryBean<RestTemplate>, Initializ
return
true
;
}
public
void
afterPropertiesSet
()
{
public
void
afterPropertiesSet
()
throws
UnsupportedEncodingException
{
Collection
<
Header
>
defaultHeaders
=
new
ArrayList
<
Header
>();
Header
header
=
new
BasicHeader
(
"Authorization"
,
"Basic "
+
BaseEncoding
.
base64
().
encode
(
"apollo:"
.
getBytes
(
"UTF-8"
)));
defaultHeaders
.
add
(
header
);
BasicCredentialsProvider
credentialsProvider
=
new
BasicCredentialsProvider
();
credentialsProvider
.
setCredentials
(
AuthScope
.
ANY
,
new
UsernamePasswordCredentials
(
"apollo"
,
""
));
CloseableHttpClient
httpClient
=
HttpClientBuilder
.
create
().
setDefaultCredentialsProvider
(
credentialsProvider
).
build
();
HttpClientBuilder
.
create
().
setDefaultCredentialsProvider
(
credentialsProvider
)
.
setDefaultHeaders
(
defaultHeaders
).
build
();
restTemplate
=
new
RestTemplate
(
new
HttpComponentsClientHttpRequestFactory
(
httpClient
));
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
View file @
c7e30148
...
...
@@ -46,11 +46,7 @@ public class AppService {
}
public
AppDTO
save
(
AppDTO
app
)
{
String
createBy
=
app
.
getOwnerName
();
try
{
app
.
setDataChangeCreatedBy
(
createBy
);
app
.
setDataChangeCreatedTime
(
new
Date
());
app
.
setDataChangeLastModifiedBy
(
createBy
);
return
appAPI
.
save
(
Env
.
DEV
,
app
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"oops! save app error. app id:{}"
,
app
.
getAppId
(),
e
);
...
...
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