Search in sources :

Example 1 with User

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

the class UserSteps method setUserExpired.

@Given("user for $orgName $username is expired")
public void setUserExpired(String orgName, String username) {
    Organization org = organizationDao.findByName(orgName);
    User user = userDao.findUserByOrganizationAndUsername(org.getId(), username);
    user.setExpired(true);
    userDao.persist(user);
}
Also used : Organization(org.jbehave.example.spring.security.domain.Organization) User(org.jbehave.example.spring.security.domain.User) Given(org.jbehave.core.annotations.Given)

Example 2 with User

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

the class UserSteps method setUserEnabled.

@Given("user for $orgName $username is enabled")
public void setUserEnabled(String orgName, String username) {
    Organization org = organizationDao.findByName(orgName);
    User user = userDao.findUserByOrganizationAndUsername(org.getId(), username);
    user.setEnabled(true);
    userDao.persist(user);
}
Also used : Organization(org.jbehave.example.spring.security.domain.Organization) User(org.jbehave.example.spring.security.domain.User) Given(org.jbehave.core.annotations.Given)

Example 3 with User

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

the class UserSteps method setUserDisabled.

@Given("user for $orgName $username is disabled")
public void setUserDisabled(String orgName, String username) {
    Organization org = organizationDao.findByName(orgName);
    User user = userDao.findUserByOrganizationAndUsername(org.getId(), username);
    user.setEnabled(false);
    userDao.persist(user);
}
Also used : Organization(org.jbehave.example.spring.security.domain.Organization) User(org.jbehave.example.spring.security.domain.User) Given(org.jbehave.core.annotations.Given)

Example 4 with User

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

the class UserSteps method createUserWithUsernameAndPassword.

@Given("a user for $orgName with username $username and password $password")
public void createUserWithUsernameAndPassword(String orgName, String username, String password) {
    Organization org = organizationDao.findByName(orgName);
    User user = new User();
    user.setOrganization(org);
    user.setUsername(username);
    user.setPasswordCleartext(password);
    userDao.persist(user);
}
Also used : Organization(org.jbehave.example.spring.security.domain.Organization) User(org.jbehave.example.spring.security.domain.User) Given(org.jbehave.core.annotations.Given)

Example 5 with User

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

the class AuthenticationEventListener method onAuthenticationFailure.

protected void onAuthenticationFailure(AbstractAuthenticationFailureEvent event) {
    // on failure - principal is a username
    String username = (String) event.getAuthentication().getPrincipal();
    if (!StringUtils.isBlank(username)) {
        Long orgId = organizationManager.getOrganization().getId();
        User user = userDao.findUserByOrganizationAndUsername(orgId, username);
        if (user != null) {
            int loginFailureCount = user.getLoginFailureCount();
            user.setLoginFailureCount(++loginFailureCount);
            userDao.persist(user);
        }
    }
}
Also used : 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