Skip to content

Commit

Permalink
remove useless authentication codes
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyiam committed Oct 9, 2017
1 parent 2650b3c commit 0f03174
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class AbstractControllerTest {
@Autowired
private HttpMessageConverters httpMessageConverters;

RestTemplate restTemplate = new TestRestTemplate("apollo", "");
RestTemplate restTemplate = new TestRestTemplate();

@PostConstruct
private void postConstruct() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testItemSetCreated() {

ItemChangeSets itemSet = new ItemChangeSets();
itemSet.setDataChangeLastModifiedBy("created");
RestTemplate createdTemplate = new TestRestTemplate("created", "");
RestTemplate createdTemplate = new TestRestTemplate();
createdTemplate.setMessageConverters(restTemplate.getMessageConverters());

int createdSize = 3;
Expand Down Expand Up @@ -96,7 +96,7 @@ public void testItemSetUpdated() {

ItemChangeSets createChangeSet = new ItemChangeSets();
createChangeSet.setDataChangeLastModifiedBy("created");
RestTemplate createdRestTemplate = new TestRestTemplate("created", "");
RestTemplate createdRestTemplate = new TestRestTemplate();
createdRestTemplate.setMessageConverters(restTemplate.getMessageConverters());

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

RestTemplate updatedRestTemplate = new TestRestTemplate("updated", "");
RestTemplate updatedRestTemplate = new TestRestTemplate();
updatedRestTemplate.setMessageConverters(restTemplate.getMessageConverters());

int updatedSize = 2;
Expand Down Expand Up @@ -170,7 +170,7 @@ public void testItemSetDeleted() {

ItemChangeSets createChangeSet = new ItemChangeSets();
createChangeSet.setDataChangeLastModifiedBy("created");
RestTemplate createdTemplate = new TestRestTemplate("created", "");
RestTemplate createdTemplate = new TestRestTemplate();
createdTemplate.setMessageConverters(restTemplate.getMessageConverters());

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

ItemChangeSets deleteChangeSet = new ItemChangeSets();
deleteChangeSet.setDataChangeLastModifiedBy("deleted");
RestTemplate deletedTemplate = new TestRestTemplate("deleted", "");
RestTemplate deletedTemplate = new TestRestTemplate();
deletedTemplate.setMessageConverters(restTemplate.getMessageConverters());

int deletedSize = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.ctrip.framework.apollo.adminservice.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

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

http.headers().frameOptions().disable();
}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("").roles("USER");
auth.inMemoryAuthentication().withUser("apollo").password("").roles("USER", "ADMIN");
auth.inMemoryAuthentication().withUser("created").password("").roles("TEST");
auth.inMemoryAuthentication().withUser("updated").password("").roles("TEST");
auth.inMemoryAuthentication().withUser("deleted").password("").roles("TEST");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ protected void configure(HttpSecurity http) throws Exception {
http.headers().frameOptions().sameOrigin();
}

/**
* Although the authentication below is useless, we may not remove them for backward compatibility.
* Because if we remove them and the old clients(before 0.9.0) still send the authentication
* information, the server will return 401, which should cause big problems.
*
* We may remove the following once we remove spring security from Apollo.
*/
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("").roles("USER").and()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package com.ctrip.framework.apollo.util.http;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URL;

import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.google.common.base.Function;
import com.google.common.io.BaseEncoding;
import com.google.common.io.CharStreams;
import com.google.gson.Gson;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

/**
Expand All @@ -24,19 +20,13 @@
public class HttpUtil {
private ConfigUtil m_configUtil;
private Gson gson;
private String basicAuth;

/**
* Constructor.
*/
public HttpUtil() {
m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
gson = new Gson();
try {
basicAuth = "Basic " + BaseEncoding.base64().encode("user:".getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
}

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

conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", basicAuth);

int connectTimeout = httpRequest.getConnectTimeout();
if (connectTimeout < 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.ctrip.framework.apollo.configservice.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

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

http.headers().frameOptions().disable();
}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("").roles("USER");
auth.inMemoryAuthentication().withUser("apollo").password("").roles("USER", "ADMIN");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public abstract class AbstractBaseIntegrationTest {

private Gson gson = new Gson();

RestTemplate restTemplate = new TestRestTemplate("user", "");
RestTemplate restTemplate = new TestRestTemplate();

@PostConstruct
private void postConstruct() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@WebIntegrationTest(randomPort = true)
public abstract class AbstractIntegrationTest {

RestTemplate restTemplate = new TestRestTemplate("apollo", "");
RestTemplate restTemplate = new TestRestTemplate();

@PostConstruct
private void postConstruct() {
Expand Down

0 comments on commit 0f03174

Please sign in to comment.