springcloud eureka, plus le mot de passe d'accès

1. pom.xml se joindre à la dépendance

	
		<! -加入密码认证-> 
		<dependency> 
            <groupId> org.springframework.boot </ groupId> 
            <artifactId> Ressort-boot-démarreur sécurité </ artifactId> 
        </ dependency>

2. configuration application.properties est le suivant nom d'utilisateur et mot de passe

# Activer le nom d'utilisateur d'authentification sécurisée et mot de passe = spring.security.basic.enabled truespring.security.user.name = adminspring.security.user.password = racine

3. Ajouter une classe configuration WebSecurityConfig.java

empaqueter org.fh.config; org.springframework.security.config.annotation.web.builders.HttpSecurity importation; org.springframework.security.config.annotation.web.configuration.EnableWebSecurity importation; org.springframework.security.config importation. annotation.web.configuration.WebSecurityConfigurerAdapter; org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler importation; / ** 
 *说明: CSRF保护禁用
 *作者: www.1b23.com 
 * / @ EnableWebSecuritypublic classe WebSecurityConfig étend WebSecurityConfigurerAdapter {	 
    @Override 
    protégé configure vide (http HttpSecurity) throws Exception { 
    	
    	SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler (); 
		successHandler.setTargetUrlParameter ( "RedirectTo"); 

		http.headers () (frameOptions) désactiver ()..;
    	
    	http.csrf () désactiver () authorizeRequests () antMatchers ( "/ actionneur / **") permitAll (HTTPBasic) () anyRequest () authentifié () et ()........; 
    } 
}

 


Je suppose que tu aimes

Origine blog.51cto.com/14622073/2483087
conseillé
Classement