Search in sources :

Example 31 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class AuthTokenDaoImplTest method testCreateAuthToken_expectOk.

@Test
public void testCreateAuthToken_expectOk() throws Exception {
    User user = userService.createUser(UserFactory.createNewUserTemplate());
    passwordService.setUserPassword(user.getUuid(), "aaa");
    AuthToken authToken = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
    assertNotNull(authToken);
}
Also used : User(org.summerb.users.api.dto.User) AuthToken(org.summerb.users.api.dto.AuthToken) Test(org.junit.Test)

Example 32 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class AuthTokenDaoImplTest method testIsAuthTokenValid_expectTokenMustBeValidRightAfterCreation.

@Test
public void testIsAuthTokenValid_expectTokenMustBeValidRightAfterCreation() throws Exception {
    User user = userService.createUser(UserFactory.createNewUserTemplate());
    passwordService.setUserPassword(user.getUuid(), "aaa");
    AuthToken authToken = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
    assertNotNull(authToken);
    AuthToken result = authTokenService.isAuthTokenValid(user.getUuid(), authToken.getUuid(), authToken.getTokenValue());
    assertNotNull(result);
}
Also used : User(org.summerb.users.api.dto.User) AuthToken(org.summerb.users.api.dto.AuthToken) Test(org.junit.Test)

Example 33 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class AuthTokenDaoImplTest method testDeleteAuthToken_expectDeletedAuthTokenMustNotBeValid.

@Test
public void testDeleteAuthToken_expectDeletedAuthTokenMustNotBeValid() throws Exception {
    User user = userService.createUser(UserFactory.createNewUserTemplate());
    passwordService.setUserPassword(user.getUuid(), "aaa");
    AuthToken authToken = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
    assertNotNull(authToken);
    AuthToken result = authTokenService.isAuthTokenValid(user.getUuid(), authToken.getUuid(), authToken.getTokenValue());
    assertNotNull(result);
    authTokenService.deleteAuthToken(authToken.getUuid());
    result = authTokenService.isAuthTokenValid(user.getUuid(), authToken.getUuid(), authToken.getTokenValue());
    assertNull(result);
}
Also used : User(org.summerb.users.api.dto.User) AuthToken(org.summerb.users.api.dto.AuthToken) Test(org.junit.Test)

Example 34 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class AuthTokenDaoImplTest method testFindExpiredAuthTokens_expect2Tokens.

@Test
public void testFindExpiredAuthTokens_expect2Tokens() throws Exception {
    User user = userService.createUser(UserFactory.createNewUserTemplate());
    passwordService.setUserPassword(user.getUuid(), "aaa");
    AuthToken authToken1 = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
    assertNotNull(authToken1);
    Thread.sleep(501);
    AuthToken authToken2 = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
    assertNotNull(authToken2);
    Thread.sleep(501);
    List<AuthToken> tokens = authTokenService.findUserAuthTokens(user.getUuid());
    assertEquals(2, tokens.size());
}
Also used : User(org.summerb.users.api.dto.User) AuthToken(org.summerb.users.api.dto.AuthToken) Test(org.junit.Test)

Example 35 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class AuthTokenDaoImplTest method testUpdateToken_expectValueWillBeUpdated.

@Test
public void testUpdateToken_expectValueWillBeUpdated() throws Exception {
    User user = userService.createUser(UserFactory.createNewUserTemplate());
    passwordService.setUserPassword(user.getUuid(), "aaa");
    AuthToken authToken = authTokenService.createAuthToken(user.getEmail(), "LOCAL", "tUuid1", "tValue1");
    assertNotNull(authToken);
    authTokenDao.updateToken(authToken.getUuid(), new Date().getTime() + 1, "newValue2");
    authToken = authTokenService.getAuthTokenByUuid(authToken.getUuid());
    assertEquals("newValue2", authToken.getTokenValue());
}
Also used : User(org.summerb.users.api.dto.User) AuthToken(org.summerb.users.api.dto.AuthToken) Date(java.util.Date) Test(org.junit.Test)

Aggregations

User (org.summerb.users.api.dto.User)61 Test (org.junit.Test)33 UserNotFoundException (org.summerb.users.api.exceptions.UserNotFoundException)13 AuthToken (org.summerb.users.api.dto.AuthToken)11 UserServiceUnexpectedException (org.summerb.users.api.exceptions.UserServiceUnexpectedException)11 FieldValidationException (org.summerb.validation.FieldValidationException)11 Transactional (org.springframework.transaction.annotation.Transactional)8 Date (java.util.Date)4 PagerParams (org.summerb.easycrud.api.dto.PagerParams)4 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 InvalidPasswordException (org.summerb.users.api.exceptions.InvalidPasswordException)3 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 GenericException (org.summerb.utils.exceptions.GenericException)2 ValidationContext (org.summerb.validation.ValidationContext)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 EventBus (com.google.common.eventbus.EventBus)1 Locale (java.util.Locale)1 Secured (org.springframework.security.access.annotation.Secured)1 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)1