Commit 0f03174c by nobodyiam

remove useless authentication codes

parent 2650b3c0
...@@ -23,7 +23,7 @@ public abstract class AbstractControllerTest { ...@@ -23,7 +23,7 @@ public abstract class AbstractControllerTest {
@Autowired @Autowired
private HttpMessageConverters httpMessageConverters; private HttpMessageConverters httpMessageConverters;
RestTemplate restTemplate = new TestRestTemplate("apollo", ""); RestTemplate restTemplate = new TestRestTemplate();
@PostConstruct @PostConstruct
private void postConstruct() { private void postConstruct() {
......
...@@ -47,7 +47,7 @@ public class ItemSetControllerTest extends AbstractControllerTest { ...@@ -47,7 +47,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets itemSet = new ItemChangeSets(); ItemChangeSets itemSet = new ItemChangeSets();
itemSet.setDataChangeLastModifiedBy("created"); itemSet.setDataChangeLastModifiedBy("created");
RestTemplate createdTemplate = new TestRestTemplate("created", ""); RestTemplate createdTemplate = new TestRestTemplate();
createdTemplate.setMessageConverters(restTemplate.getMessageConverters()); createdTemplate.setMessageConverters(restTemplate.getMessageConverters());
int createdSize = 3; int createdSize = 3;
...@@ -96,7 +96,7 @@ public class ItemSetControllerTest extends AbstractControllerTest { ...@@ -96,7 +96,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets createChangeSet = new ItemChangeSets(); ItemChangeSets createChangeSet = new ItemChangeSets();
createChangeSet.setDataChangeLastModifiedBy("created"); createChangeSet.setDataChangeLastModifiedBy("created");
RestTemplate createdRestTemplate = new TestRestTemplate("created", ""); RestTemplate createdRestTemplate = new TestRestTemplate();
createdRestTemplate.setMessageConverters(restTemplate.getMessageConverters()); createdRestTemplate.setMessageConverters(restTemplate.getMessageConverters());
int createdSize = 3; int createdSize = 3;
...@@ -123,7 +123,7 @@ public class ItemSetControllerTest extends AbstractControllerTest { ...@@ -123,7 +123,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets updateChangeSet = new ItemChangeSets(); ItemChangeSets updateChangeSet = new ItemChangeSets();
updateChangeSet.setDataChangeLastModifiedBy("updated"); updateChangeSet.setDataChangeLastModifiedBy("updated");
RestTemplate updatedRestTemplate = new TestRestTemplate("updated", ""); RestTemplate updatedRestTemplate = new TestRestTemplate();
updatedRestTemplate.setMessageConverters(restTemplate.getMessageConverters()); updatedRestTemplate.setMessageConverters(restTemplate.getMessageConverters());
int updatedSize = 2; int updatedSize = 2;
...@@ -170,7 +170,7 @@ public class ItemSetControllerTest extends AbstractControllerTest { ...@@ -170,7 +170,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets createChangeSet = new ItemChangeSets(); ItemChangeSets createChangeSet = new ItemChangeSets();
createChangeSet.setDataChangeLastModifiedBy("created"); createChangeSet.setDataChangeLastModifiedBy("created");
RestTemplate createdTemplate = new TestRestTemplate("created", ""); RestTemplate createdTemplate = new TestRestTemplate();
createdTemplate.setMessageConverters(restTemplate.getMessageConverters()); createdTemplate.setMessageConverters(restTemplate.getMessageConverters());
int createdSize = 3; int createdSize = 3;
...@@ -196,7 +196,7 @@ public class ItemSetControllerTest extends AbstractControllerTest { ...@@ -196,7 +196,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets deleteChangeSet = new ItemChangeSets(); ItemChangeSets deleteChangeSet = new ItemChangeSets();
deleteChangeSet.setDataChangeLastModifiedBy("deleted"); deleteChangeSet.setDataChangeLastModifiedBy("deleted");
RestTemplate deletedTemplate = new TestRestTemplate("deleted", ""); RestTemplate deletedTemplate = new TestRestTemplate();
deletedTemplate.setMessageConverters(restTemplate.getMessageConverters()); deletedTemplate.setMessageConverters(restTemplate.getMessageConverters());
int deletedSize = 1; int deletedSize = 1;
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order; 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.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
...@@ -20,13 +18,4 @@ public class TestWebSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -20,13 +18,4 @@ public class TestWebSecurityConfig extends WebSecurityConfigurerAdapter {
http.headers().frameOptions().disable(); 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");
}
} }
...@@ -23,6 +23,13 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -23,6 +23,13 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
http.headers().frameOptions().sameOrigin(); 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 @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("").roles("USER").and() auth.inMemoryAuthentication().withUser("user").password("").roles("USER").and()
......
package com.ctrip.framework.apollo.util.http; 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.build.ApolloInjector;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException; import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException; import com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException;
import com.ctrip.framework.apollo.util.ConfigUtil; import com.ctrip.framework.apollo.util.ConfigUtil;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.io.BaseEncoding;
import com.google.common.io.CharStreams; import com.google.common.io.CharStreams;
import com.google.gson.Gson; 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; import java.nio.charset.StandardCharsets;
/** /**
...@@ -24,7 +20,6 @@ import java.nio.charset.StandardCharsets; ...@@ -24,7 +20,6 @@ import java.nio.charset.StandardCharsets;
public class HttpUtil { public class HttpUtil {
private ConfigUtil m_configUtil; private ConfigUtil m_configUtil;
private Gson gson; private Gson gson;
private String basicAuth;
/** /**
* Constructor. * Constructor.
...@@ -32,11 +27,6 @@ public class HttpUtil { ...@@ -32,11 +27,6 @@ public class HttpUtil {
public HttpUtil() { public HttpUtil() {
m_configUtil = ApolloInjector.getInstance(ConfigUtil.class); m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
gson = new Gson(); gson = new Gson();
try {
basicAuth = "Basic " + BaseEncoding.base64().encode("user:".getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
} }
/** /**
...@@ -85,7 +75,6 @@ public class HttpUtil { ...@@ -85,7 +75,6 @@ public class HttpUtil {
HttpURLConnection conn = (HttpURLConnection) new URL(httpRequest.getUrl()).openConnection(); HttpURLConnection conn = (HttpURLConnection) new URL(httpRequest.getUrl()).openConnection();
conn.setRequestMethod("GET"); conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", basicAuth);
int connectTimeout = httpRequest.getConnectTimeout(); int connectTimeout = httpRequest.getConnectTimeout();
if (connectTimeout < 0) { if (connectTimeout < 0) {
......
package com.ctrip.framework.apollo.configservice.controller; package com.ctrip.framework.apollo.configservice.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order; 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.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
...@@ -20,10 +18,4 @@ public class TestWebSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -20,10 +18,4 @@ public class TestWebSecurityConfig extends WebSecurityConfigurerAdapter {
http.headers().frameOptions().disable(); 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");
}
} }
...@@ -46,7 +46,7 @@ public abstract class AbstractBaseIntegrationTest { ...@@ -46,7 +46,7 @@ public abstract class AbstractBaseIntegrationTest {
private Gson gson = new Gson(); private Gson gson = new Gson();
RestTemplate restTemplate = new TestRestTemplate("user", ""); RestTemplate restTemplate = new TestRestTemplate();
@PostConstruct @PostConstruct
private void postConstruct() { private void postConstruct() {
......
...@@ -17,7 +17,7 @@ import javax.annotation.PostConstruct; ...@@ -17,7 +17,7 @@ import javax.annotation.PostConstruct;
@WebIntegrationTest(randomPort = true) @WebIntegrationTest(randomPort = true)
public abstract class AbstractIntegrationTest { public abstract class AbstractIntegrationTest {
RestTemplate restTemplate = new TestRestTemplate("apollo", ""); RestTemplate restTemplate = new TestRestTemplate();
@PostConstruct @PostConstruct
private void postConstruct() { private void postConstruct() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment