mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
support basic auth
This commit is contained in:
@@ -45,6 +45,11 @@
|
||||
<artifactId>arthas-channel-server-starter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.alibaba.arthas.channel.server;
|
||||
|
||||
import com.alibaba.arthas.channel.server.autoconfigure.ChannelServerProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
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.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
private ChannelServerProperties channelServerProperties;
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
String username = channelServerProperties.getAuth().getUsername();
|
||||
if (StringUtils.hasText(username)) {
|
||||
auth.inMemoryAuthentication()
|
||||
//.passwordEncoder(new BCryptPasswordEncoder())
|
||||
.passwordEncoder(NoOpPasswordEncoder.getInstance()) // CHANGE IT for production
|
||||
.withUser(username)
|
||||
.password(channelServerProperties.getAuth().getPassword())
|
||||
.roles("USER");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
String username = channelServerProperties.getAuth().getUsername();
|
||||
if (StringUtils.hasText(username)) {
|
||||
http.csrf().disable().authorizeRequests()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.httpBasic();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,9 @@ arthas.channel.server.message-exchange.topic-survival-time-mills=60000
|
||||
arthas.channel.server.message-exchange.topic-capacity=1000
|
||||
|
||||
|
||||
# auth
|
||||
#arthas.channel.server.auth.username=arthas
|
||||
#arthas.channel.server.auth.password=arthas
|
||||
|
||||
# for all endpoints
|
||||
management.endpoints.web.exposure.include=*
|
||||
|
||||
+30
@@ -12,6 +12,8 @@ public class ChannelServerProperties {
|
||||
|
||||
private AgentCleaner agentCleaner = new AgentCleaner();
|
||||
|
||||
private Auth auth = new Auth();
|
||||
|
||||
public Server getWebsocket() {
|
||||
return websocket;
|
||||
}
|
||||
@@ -44,6 +46,14 @@ public class ChannelServerProperties {
|
||||
this.messageExchange = messageExchange;
|
||||
}
|
||||
|
||||
public Auth getAuth() {
|
||||
return auth;
|
||||
}
|
||||
|
||||
public void setAuth(Auth auth) {
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public static class Server {
|
||||
private String host;
|
||||
private int port;
|
||||
@@ -158,4 +168,24 @@ public class ChannelServerProperties {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Auth {
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user