簡體   English   中英

春季:安全性上下文未保存我的密碼

[英]Spring: Security-context doesn't save my password

我正在用基本身份驗證編寫其余的應用程序。 它可以正常工作,但是每次重新啟動后都會生成新的用戶密碼。 我的Security-context.xml是

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/security

           http://www.springframework.org/schema/security/spring-security-3.0.xsd">

    <security:http auto-config='true'>
        <security:intercept-url pattern="/api/**" access="ROLE_USER"/>
        <security:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
        <security:http-basic />
    </security:http>

    <security:authentication-manager>
        <security:authentication-provider>
            <security:user-service>
                <security:user name="user" password="password1" authorities="ROLE_USER" />
            </security:user-service>
        </security:authentication-provider>
    </security:authentication-manager>

</beans>

為什么不使用password =“ password1”?

您可以按照以下步驟在application.properties文件中設置用戶和密碼。

security.user.name=user # Default user name.
security.user.password= # Password for the default user name. A random password is logged on startup by default.

這直接來自Spring Boot Properties docs Here

除非您有充分的理由這樣做,否則請不要對抗Spring Boot的自動配置魔術。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM