Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using email and username both as login in spring security plugin in Grails

I am using spring security plugin in my Grails application and i would like the users registered to login into the application with username or email address provided during the registration process.(just like fb)

I have already looked into the web and concerned Grails docs ::: http://grails-plugins.github.io/grails-spring-security-core/docs/manual/guide/single.html#4.1%20Person%20Class

but could not find any solution.

Any help would be highly appreciated.

Thanks in advance

like image 487
dpak005 Avatar asked Sep 29 '13 07:09

dpak005


People also ask

Does Spring Security use default login form?

Spring Boot Login Page tutorial shows how to work with a default login page. Spring security secures all HTTP endpoints by default. A user has to login in a default HTTP form. To enable Spring Boot security, we add spring-boot-starter-security to the dependencies.

What is the default username for spring security?

As of Spring Security version 5.7. 1, the default username is user and the password is randomly generated and displayed in the console (e.g. 8e557245-73e2-4286-969a-ff57fe326336 ).


1 Answers

From a spring-security point of view, what you should do is implement your own org.springframework.security.core.userdetails.UserDetailsService

public class MyUserServiceImpl implements UserDetailsService{

    @Autowired
    private AdminUserDao dao;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {

    ... Here comes your logic to get your the user based on email or userid ...

    }
}

in your spring config you have to reference your UserDetails class:

<authentication-manager>
    <authentication-provider user-service-ref="myUserServiceImpl" />
</authentication-manager>

hth

like image 51
Frederic Close Avatar answered Oct 11 '22 00:10

Frederic Close