Skip to content

Commit bf496b4

Browse files
authored
Merge pull request apolloconfig#782 from nobodyiam/remove-useless-authentication-codes
remove useless authentication codes
2 parents 2650b3c + 0f03174 commit bf496b4

File tree

8 files changed

+20
-43
lines changed

8 files changed

+20
-43
lines changed

apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/controller/AbstractControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public abstract class AbstractControllerTest {
2323
@Autowired
2424
private HttpMessageConverters httpMessageConverters;
2525

26-
RestTemplate restTemplate = new TestRestTemplate("apollo", "");
26+
RestTemplate restTemplate = new TestRestTemplate();
2727

2828
@PostConstruct
2929
private void postConstruct() {

apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/controller/ItemSetControllerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void testItemSetCreated() {
4747

4848
ItemChangeSets itemSet = new ItemChangeSets();
4949
itemSet.setDataChangeLastModifiedBy("created");
50-
RestTemplate createdTemplate = new TestRestTemplate("created", "");
50+
RestTemplate createdTemplate = new TestRestTemplate();
5151
createdTemplate.setMessageConverters(restTemplate.getMessageConverters());
5252

5353
int createdSize = 3;
@@ -96,7 +96,7 @@ public void testItemSetUpdated() {
9696

9797
ItemChangeSets createChangeSet = new ItemChangeSets();
9898
createChangeSet.setDataChangeLastModifiedBy("created");
99-
RestTemplate createdRestTemplate = new TestRestTemplate("created", "");
99+
RestTemplate createdRestTemplate = new TestRestTemplate();
100100
createdRestTemplate.setMessageConverters(restTemplate.getMessageConverters());
101101

102102
int createdSize = 3;
@@ -123,7 +123,7 @@ public void testItemSetUpdated() {
123123
ItemChangeSets updateChangeSet = new ItemChangeSets();
124124
updateChangeSet.setDataChangeLastModifiedBy("updated");
125125

126-
RestTemplate updatedRestTemplate = new TestRestTemplate("updated", "");
126+
RestTemplate updatedRestTemplate = new TestRestTemplate();
127127
updatedRestTemplate.setMessageConverters(restTemplate.getMessageConverters());
128128

129129
int updatedSize = 2;
@@ -170,7 +170,7 @@ public void testItemSetDeleted() {
170170

171171
ItemChangeSets createChangeSet = new ItemChangeSets();
172172
createChangeSet.setDataChangeLastModifiedBy("created");
173-
RestTemplate createdTemplate = new TestRestTemplate("created", "");
173+
RestTemplate createdTemplate = new TestRestTemplate();
174174
createdTemplate.setMessageConverters(restTemplate.getMessageConverters());
175175

176176
int createdSize = 3;
@@ -196,7 +196,7 @@ public void testItemSetDeleted() {
196196

197197
ItemChangeSets deleteChangeSet = new ItemChangeSets();
198198
deleteChangeSet.setDataChangeLastModifiedBy("deleted");
199-
RestTemplate deletedTemplate = new TestRestTemplate("deleted", "");
199+
RestTemplate deletedTemplate = new TestRestTemplate();
200200
deletedTemplate.setMessageConverters(restTemplate.getMessageConverters());
201201

202202
int deletedSize = 1;
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.ctrip.framework.apollo.adminservice.controller;
22

3-
import org.springframework.beans.factory.annotation.Autowired;
43
import org.springframework.context.annotation.Configuration;
54
import org.springframework.core.annotation.Order;
6-
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
75
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
86
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
97

@@ -20,13 +18,4 @@ protected void configure(HttpSecurity http) throws Exception {
2018

2119
http.headers().frameOptions().disable();
2220
}
23-
24-
@Autowired
25-
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
26-
auth.inMemoryAuthentication().withUser("user").password("").roles("USER");
27-
auth.inMemoryAuthentication().withUser("apollo").password("").roles("USER", "ADMIN");
28-
auth.inMemoryAuthentication().withUser("created").password("").roles("TEST");
29-
auth.inMemoryAuthentication().withUser("updated").password("").roles("TEST");
30-
auth.inMemoryAuthentication().withUser("deleted").password("").roles("TEST");
31-
}
3221
}

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/auth/WebSecurityConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ protected void configure(HttpSecurity http) throws Exception {
2323
http.headers().frameOptions().sameOrigin();
2424
}
2525

26+
/**
27+
* Although the authentication below is useless, we may not remove them for backward compatibility.
28+
* Because if we remove them and the old clients(before 0.9.0) still send the authentication
29+
* information, the server will return 401, which should cause big problems.
30+
*
31+
* We may remove the following once we remove spring security from Apollo.
32+
*/
2633
@Autowired
2734
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
2835
auth.inMemoryAuthentication().withUser("user").password("").roles("USER").and()

apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpUtil.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
package com.ctrip.framework.apollo.util.http;
22

3-
import java.io.IOException;
4-
import java.io.InputStream;
5-
import java.io.InputStreamReader;
6-
import java.io.UnsupportedEncodingException;
7-
import java.lang.reflect.Type;
8-
import java.net.HttpURLConnection;
9-
import java.net.URL;
10-
113
import com.ctrip.framework.apollo.build.ApolloInjector;
124
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
135
import com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException;
146
import com.ctrip.framework.apollo.util.ConfigUtil;
157
import com.google.common.base.Function;
16-
import com.google.common.io.BaseEncoding;
178
import com.google.common.io.CharStreams;
189
import com.google.gson.Gson;
10+
import java.io.IOException;
11+
import java.io.InputStreamReader;
12+
import java.lang.reflect.Type;
13+
import java.net.HttpURLConnection;
14+
import java.net.URL;
1915
import java.nio.charset.StandardCharsets;
2016

2117
/**
@@ -24,19 +20,13 @@
2420
public class HttpUtil {
2521
private ConfigUtil m_configUtil;
2622
private Gson gson;
27-
private String basicAuth;
2823

2924
/**
3025
* Constructor.
3126
*/
3227
public HttpUtil() {
3328
m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
3429
gson = new Gson();
35-
try {
36-
basicAuth = "Basic " + BaseEncoding.base64().encode("user:".getBytes("UTF-8"));
37-
} catch (UnsupportedEncodingException ex) {
38-
ex.printStackTrace();
39-
}
4030
}
4131

4232
/**
@@ -85,7 +75,6 @@ private <T> HttpResponse<T> doGetWithSerializeFunction(HttpRequest httpRequest,
8575
HttpURLConnection conn = (HttpURLConnection) new URL(httpRequest.getUrl()).openConnection();
8676

8777
conn.setRequestMethod("GET");
88-
conn.setRequestProperty("Authorization", basicAuth);
8978

9079
int connectTimeout = httpRequest.getConnectTimeout();
9180
if (connectTimeout < 0) {

apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/controller/TestWebSecurityConfig.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.ctrip.framework.apollo.configservice.controller;
22

3-
import org.springframework.beans.factory.annotation.Autowired;
43
import org.springframework.context.annotation.Configuration;
54
import org.springframework.core.annotation.Order;
6-
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
75
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
86
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
97

@@ -20,10 +18,4 @@ protected void configure(HttpSecurity http) throws Exception {
2018

2119
http.headers().frameOptions().disable();
2220
}
23-
24-
@Autowired
25-
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
26-
auth.inMemoryAuthentication().withUser("user").password("").roles("USER");
27-
auth.inMemoryAuthentication().withUser("apollo").password("").roles("USER", "ADMIN");
28-
}
2921
}

apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/integration/AbstractBaseIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public abstract class AbstractBaseIntegrationTest {
4646

4747
private Gson gson = new Gson();
4848

49-
RestTemplate restTemplate = new TestRestTemplate("user", "");
49+
RestTemplate restTemplate = new TestRestTemplate();
5050

5151
@PostConstruct
5252
private void postConstruct() {

apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/AbstractIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@WebIntegrationTest(randomPort = true)
1818
public abstract class AbstractIntegrationTest {
1919

20-
RestTemplate restTemplate = new TestRestTemplate("apollo", "");
20+
RestTemplate restTemplate = new TestRestTemplate();
2121

2222
@PostConstruct
2323
private void postConstruct() {

0 commit comments

Comments
 (0)