2016-12-31 2 views
0

私はスプリングブートRESTアプリケーションを作成しようとしています。アプリケーションをデプロイするときは、認証が必要で、ユーザー名とパスワードを要求しています。これを回避するにはどうすればよいですか、または認証にユーザー名とパスワードを追加するにはどうすればよいですか?スプリングブートによるスプリングセキュリティ

pomのセキュリティエントリを削除する必要がありますか?

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-security</artifactId> 
</dependency> 

答えて

0

pom.xmlからセキュリティを削除する必要はありません。あなたのプロジェクトでは、以下のようなものを試すことができます。 SecurityConfigを作成してWebSecurityConfigurerAdapterに拡張し、ユーザー名とパスワードを入力して後でカスタマイズすることを試みてください。

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; 

@Configuration 
@EnableWebMvcSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 
    @Override 
    protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
     auth 
      .inMemoryAuthentication() 
       .withUser("user") 
        .password("user") 
        .roles("USER") 
        .and() 
       .withUser("user2") 
        .password("secret2") 
        .roles("USER"); 
    } 
    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .authorizeRequests() 
       .anyRequest().fullyAuthenticated(); 
     http 
      .httpBasic(); 
     http 
      .csrf().disable(); 
    } 
} 

public @interface EnableWebMvcSecurity { 

} 
0

あなたはすべての認証を使用したくない場合は、依存関係を削除する必要があります。

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-security</artifactId> 
</dependency> 

Spring Boot Reference Guideを参照してください:

春のセキュリティの場合クラスパス上にあると、Webアプリケーションはデフォルトで安全になりますすべてのHTTPエンドポイントでの '基本的な'認証

関連する問題