çok temel "temel kimlik doğrulaması"
(https://github.com/spring-cloud-samples/configserver buradan) Sen mesela yoluyla yay çizme-marş (Bahar Güvenlik fazladan bağımlılığı dahil Temel HTTP kimlik doğrulaması ekleyebilir -güvenlik). Kullanıcı adı "kullanıcı" ve şifre başlangıçta konsolda (standart Yay Çizme yaklaşımı) basılmıştır. Özel kullanıcı/şifre çifti istiyorsanız
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
, siz (BasicSecurityConfiguration.java
) sunucu yapılandırma dosyası
security:
basic:
enabled: false
belirtmek ve kodunuzda bu asgari Class eklemek gerekir:: maven (pom.xml
) kullanılıyorsa
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.WebSecurityConfigurerAdapter;
@Configuration
//@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class BasicSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Value("#{'${qa.admin.password:admin}'}") //property with default value
String admin_password;
@Value("#{'${qa.user.password:user}'}") //property with default value
String user_password;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password(user_password).roles("USER")
.and()
.withUser("admin").password(admin_password).roles("USER", "ACTUATOR");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.httpBasic()
.and()
.authorizeRequests()
.antMatchers("/encrypt/**").authenticated()
.antMatchers("/decrypt/**").authenticated()
//.antMatchers("/admin/**").hasAuthority("ROLE_ACTUATOR")
//.antMatchers("/qa/**").permitAll()
;
}
}
@value ("# { '$ {qa.admin.password: yönetici}'}") izin şifreleri mülkiyet yapılandırma dosyası, ortam değişkenleri veya komut satırında tanımlanması gerekir. Örneğin
(application.yml
):
server:
port: 8888
security:
basic:
enabled: false
qa:
admin:
password: adminadmin
user:
password: useruser
management:
port: 8888
context-path: /admin
logging:
level:
org.springframework.cloud: 'DEBUG'
spring:
cloud:
config:
server:
git:
ignoreLocalSshSettings: true
uri: ssh://[email protected]/repo/configuration.git
Bu benim için çalışıyor.
Düzenleme: Yerine Sınıf nedeniyle, application.yaml
doğrudan temel kullanıcı yapılandırmasını koyabilirsiniz:
security:
basic:
enabled: true
path: /**
ignored: /health**,/info**,/metrics**,/trace**
user:
name: admin
password: tupassword
Sen bootstrap.yml şifre için yer tutucu ve bir ortam değişkeni olarak şifreyi söz deneyebilirsiniz. –