2017-08-07 5 views
1

私は自分のpom.xmlで春のセキュリティ、そして春のセキュリティは自動的にデフォルトのユーザーと生成されたパスワードが設定されてい:春のセキュリティ:どのようにデフォルトのユーザーとパスワードを変更するには?

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

私は、デフォルトのユーザー名とパスワードを変更するにはどうすればよいですか?

+0

この[投稿](https://stackoverflow.com/questions/37285016/what-is-username-and-password-when-starting-spring-boot-with-tomcat)が役立ち、解決策があるとしますあなたが期待しているもののために。 –

+0

[TomcatでSpringブートを開始するときのユーザ名とパスワードは何ですか?](https://stackoverflow.com/questions/37285016/what-is-username-and-password-when-starting-spring-boot-with) -tomcat) – Graham

答えて

2

これはstraight from the docsです:

設定クラスを作成します。

@Configuration 
@EnableWebSecurity 
public class HelloWebSecurityConfiguration 
    extends WebSecurityConfigurerAdapter { 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) { 
    auth 
     .inMemoryAuthentication() 
     .withUser("user").password("password").roles("USER"); 
    } 
} 

Newer Docs

これは多少異なりますが、効果は同じになります:

@EnableWebSecurity 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Bean 
    public UserDetailsService userDetailsService() throws Exception { 
     InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); 
     manager.createUser(User.withUsername("user").password("password").roles("USER").build()); 
     return manager; 
    } 
} 
+0

2013年7月3日古いドキュメント: '( – ahmedmess

+0

私はちょうど1.5.6 successullyでこれを行いました。 – Brian

+0

また、同じ設定を参照する新しいドキュメントが追加されました。 – Brian

6

この簡単にあなたの中で行うことができますapplication.propertiesファイル:

security.user.name=user # Default user name.

security.user.password= # Password

security.user.role= # A comma separated list of roles

ここdocumentationです。

関連する問題