use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class JpaUserCredentialsDaoTest method testFindByActivateToken.
@Test
@DatabaseSetup("classpath:dbunit/user_credentials.xml")
public void testFindByActivateToken() {
UserCredentials userCredentials = userCredentialsDao.findByActivateToken("ACTIVATE_TOKEN_1");
assertNotNull(userCredentials);
assertEquals("3ed10af0-27d5-11e7-93ae-92361f002671", userCredentials.getId().toString());
}
use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class JpaUserCredentialsDaoTest method testFindByResetToken.
@Test
@DatabaseSetup("classpath:dbunit/user_credentials.xml")
public void testFindByResetToken() {
UserCredentials userCredentials = userCredentialsDao.findByResetToken("RESET_TOKEN_2");
assertNotNull(userCredentials);
assertEquals("4b9e010c-27d5-11e7-93ae-92361f002671", userCredentials.getId().toString());
}
use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class AuthController method checkActivateToken.
@RequestMapping(value = "/noauth/activate", params = { "activateToken" }, method = RequestMethod.GET)
public ResponseEntity<String> checkActivateToken(@RequestParam(value = "activateToken") String activateToken) {
HttpHeaders headers = new HttpHeaders();
HttpStatus responseStatus;
UserCredentials userCredentials = userService.findUserCredentialsByActivateToken(activateToken);
if (userCredentials != null) {
String createURI = "/login/createPassword";
try {
URI location = new URI(createURI + "?activateToken=" + activateToken);
headers.setLocation(location);
responseStatus = HttpStatus.SEE_OTHER;
} catch (URISyntaxException e) {
log.error("Unable to create URI with address [{}]", createURI);
responseStatus = HttpStatus.BAD_REQUEST;
}
} else {
responseStatus = HttpStatus.CONFLICT;
}
return new ResponseEntity<>(headers, responseStatus);
}
use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class RestAuthenticationProvider method authenticateByUsernameAndPassword.
private Authentication authenticateByUsernameAndPassword(UserPrincipal userPrincipal, String username, String password) {
User user = userService.findUserByEmail(username);
if (user == null) {
throw new UsernameNotFoundException("User not found: " + username);
}
UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getId());
if (userCredentials == null) {
throw new UsernameNotFoundException("User credentials not found");
}
if (!userCredentials.isEnabled()) {
throw new DisabledException("User is not active");
}
if (!encoder.matches(password, userCredentials.getPassword())) {
throw new BadCredentialsException("Authentication Failed. Username or Password not valid.");
}
if (user.getAuthority() == null)
throw new InsufficientAuthenticationException("User has no authority assigned");
SecurityUser securityUser = new SecurityUser(user, userCredentials.isEnabled(), userPrincipal);
return new UsernamePasswordAuthenticationToken(securityUser, null, securityUser.getAuthorities());
}
Aggregations