Spring security_Password Encryption

Yogesh

Login using spring security is working fine for multiple users. Now I've to login to the application using password, which should be encrypted in the database.

HomeController : Here I'm retrieving username, password from FORM.

spring-security.xml : Here I'm retrieving username, password from DB.

Now somewhere I've to compare these passwords for matching and then I've to make the person to login.

Please give me an Idea, how we can do this using spring security. ??

Kumar Sambhav

I believe you don't do the credential matching yourself when using Spring Security. That's the responsibility of AuthenticationManager you have configured.

You can specify the encoder to use while matching credentials like:-

<!-- This is the authentication manager -->
<authentication-manager>
   <authentication-provider user-service-ref="yourUserService">
    <password-encoder hash="sha"/>
   </authentication-provider>
</authentication-manager>

All you need to care is storing encoded password in your user details table.

Take a look at docs

SPOILER

If you are using Spring Security, you don't need to have a controller to collect user credentials. Spring Security filters takes care of that.

For example:-

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/security
                           http://www.springframework.org/schema/security/spring-security-3.2.xsd">

    <security:global-method-security secured-annotations="enabled" />

    <security:http auto-config="true">
        <!-- Restrict URLs based on role -->
        <security:intercept-url pattern="/login*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
        <security:intercept-url pattern="/logoutSuccess*" access="IS_AUTHENTICATED_ANONYMOUSLY" />

        <security:intercept-url pattern="/css/main.css" access="IS_AUTHENTICATED_ANONYMOUSLY" />
        <security:intercept-url pattern="/resources/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />

        <security:intercept-url pattern="/**" access="ROLE_USER" />

        <!-- Override default login and logout pages -->
        <security:form-login login-page="/login.html" // this is where your custome login page lives.
                             login-processing-url="/loginProcess"  //this is where you POST your login form
                             default-target-url="/index.jsp" 
                             authentication-failure-url="/login.html?login_error=1" />
        <security:logout logout-url="/logout" logout-success-url="/logoutSuccess.html" />
    </security:http>

    <security:authentication-manager>
        <security:authentication-provider >
            <security:jdbc-user-service data-source-ref="dataSource" />
        </security:authentication-provider>
    </security:authentication-manager>

</beans>

I suggest you to go through a reference docs and simple blog/tutorial (there are plenty).

Even more, give Spring Boot Security a shot.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Joomla 3.2.1 password encryption

분류에서Dev

Recover username and password with spring security

분류에서Dev

Security of bash script involving gpg symmetric encryption

분류에서Dev

Loopback password encryption vis-a-vis rails AES password

분류에서Dev

FreeBSD "Fatal double fault" upon entering ZFS encryption password

분류에서Dev

Issues with using SHA1 password encryption in PHP/mysql

분류에서Dev

Is Sql Compact Edition database still readable after password protection and encryption?

분류에서Dev

복어와 동등한 Security.Encryption.Cryptography?

분류에서Dev

Latest Spring Boot upgrade is throwing Invalid property 'text[encryption] from SecurityProperties

분류에서Dev

Guide to implementing password recovery with dynamic URL sent to email over atlassian crowd with spring security

분류에서Dev

BCryptPasswordEncoder in Spring Security with JSF 2.0 custom login page - Login with encrypted password saved in DB

분류에서Dev

Dell Latitude E7450 cant write disk encryption password A7 password

분류에서Dev

AspectJ with Spring Security

분류에서Dev

Spring Security with Backbone URLs

분류에서Dev

Spring security not authenticate the user

분류에서Dev

Spring Security two authenticationSuccessHandler

분류에서Dev

Spring Security Active Directory

분류에서Dev

Crypto Encryption

분류에서Dev

Encryption Android

분류에서Dev

Spring mvc and spring security version conflict

분류에서Dev

xmlBeanDefinitionStoreException while implementing spring security

분류에서Dev

Spring Security @preauthorize 우회

분류에서Dev

Confusion in Spring Security Filter Chain

분류에서Dev

spring security 3.2 java configuration

분류에서Dev

Person and Group with authority on Spring security

분류에서Dev

Spring security session time out

분류에서Dev

Spring MVC + Security with Java Configuration

분류에서Dev

Spring Framework 4.0 및 Spring Security 3.2.4의 Spring Security SAML 확장

분류에서Dev

Spring Web Flow 2.4.1 및 Spring Security 4.0.1

Related 관련 기사

  1. 1

    Joomla 3.2.1 password encryption

  2. 2

    Recover username and password with spring security

  3. 3

    Security of bash script involving gpg symmetric encryption

  4. 4

    Loopback password encryption vis-a-vis rails AES password

  5. 5

    FreeBSD "Fatal double fault" upon entering ZFS encryption password

  6. 6

    Issues with using SHA1 password encryption in PHP/mysql

  7. 7

    Is Sql Compact Edition database still readable after password protection and encryption?

  8. 8

    복어와 동등한 Security.Encryption.Cryptography?

  9. 9

    Latest Spring Boot upgrade is throwing Invalid property 'text[encryption] from SecurityProperties

  10. 10

    Guide to implementing password recovery with dynamic URL sent to email over atlassian crowd with spring security

  11. 11

    BCryptPasswordEncoder in Spring Security with JSF 2.0 custom login page - Login with encrypted password saved in DB

  12. 12

    Dell Latitude E7450 cant write disk encryption password A7 password

  13. 13

    AspectJ with Spring Security

  14. 14

    Spring Security with Backbone URLs

  15. 15

    Spring security not authenticate the user

  16. 16

    Spring Security two authenticationSuccessHandler

  17. 17

    Spring Security Active Directory

  18. 18

    Crypto Encryption

  19. 19

    Encryption Android

  20. 20

    Spring mvc and spring security version conflict

  21. 21

    xmlBeanDefinitionStoreException while implementing spring security

  22. 22

    Spring Security @preauthorize 우회

  23. 23

    Confusion in Spring Security Filter Chain

  24. 24

    spring security 3.2 java configuration

  25. 25

    Person and Group with authority on Spring security

  26. 26

    Spring security session time out

  27. 27

    Spring MVC + Security with Java Configuration

  28. 28

    Spring Framework 4.0 및 Spring Security 3.2.4의 Spring Security SAML 확장

  29. 29

    Spring Web Flow 2.4.1 및 Spring Security 4.0.1

뜨겁다태그

보관