Search in sources :

Example 6 with User

use of org.jbehave.example.spring.security.domain.User in project jbehave-core by jbehave.

the class AuthenticationEventListener method onAuthenticationSuccess.

protected void onAuthenticationSuccess(AuthenticationSuccessEvent event) {
    // on success - principal is a UserDetails
    UserDetails details = (UserDetails) event.getAuthentication().getPrincipal();
    String username = details.getUsername();
    if (!StringUtils.isBlank(username)) {
        Long orgId = organizationManager.getOrganization().getId();
        User user = userDao.findUserByOrganizationAndUsername(orgId, username);
        if (user != null) {
            user.setLoginFailureCount(0);
            userDao.persist(user);
        }
    }
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) User(org.jbehave.example.spring.security.domain.User)

Example 7 with User

use of org.jbehave.example.spring.security.domain.User in project jbehave-core by jbehave.

the class UserDetailsServiceImpl method loadUserByUsername.

public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    Organization org = organizationManager.getOrganization();
    User user = userDao.findUserByOrganizationAndUsername(org.getId(), username);
    if (user == null) {
        throw new UsernameNotFoundException(username);
    }
    return new UserDetailsImpl(user, org.getAuthenticationPolicy());
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) Organization(org.jbehave.example.spring.security.domain.Organization) User(org.jbehave.example.spring.security.domain.User)

Aggregations

User (org.jbehave.example.spring.security.domain.User)7 Organization (org.jbehave.example.spring.security.domain.Organization)5 Given (org.jbehave.core.annotations.Given)4 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1