use of com.datastax.fallout.service.core.User in project fallout by datastax.
the class PerformanceToolResource method report.
@GET
@Path("{email:" + EMAIL_PATTERN + "}/report/{report:" + TestResource.ID_PATTERN + "}")
@Produces(MediaType.TEXT_HTML)
public FalloutView report(@Auth Optional<User> user, @PathParam("email") String email, @PathParam("report") String reportId) {
PerformanceReport report = reportDAO.get(email, UUID.fromString(reportId));
if (report == null)
throw new WebApplicationException("Report not found");
List<TestRun> testRuns = report.getReportTestRuns().stream().map(tri -> {
TestRun tr = testRunDAO.get(tri);
if (tr != null) {
return tr;
}
return createOwnerlessTestRun(tri);
}).toList();
LinkedTestRuns linkedTestRuns = new LinkedTestRuns(userGroupMapper, user, testRuns).hide(TableDisplayOption.MUTATION_ACTIONS, TableDisplayOption.RESTORE_ACTIONS);
return new ReportView(user, report, linkedTestRuns);
}
use of com.datastax.fallout.service.core.User in project fallout by datastax.
the class FalloutTokenAuthenticator method authenticate.
@Override
public Optional<User> authenticate(String token) throws AuthenticationException {
try {
Session session = userDao.getSession(token);
if (session != null && !session.getTokenType().equals(tokenType)) {
logger.error("Used " + session.getTokenType() + " type token for " + tokenType + " authenticator.");
return Optional.empty();
}
if (session != null && session.getUserId() != null) {
String userId = session.getUserId();
User user = userDao.getUser(userId);
logger.info("Logged in user: " + userId + " (" + user.getEmail() + ")");
return Optional.of(user);
}
logger.info("Failed to authenticate token: " + token);
return Optional.empty();
} catch (Exception e) {
throw new AuthenticationException(e);
}
}
use of com.datastax.fallout.service.core.User in project fallout by datastax.
the class FalloutServerlessCommand method parseUserCredentials.
protected UserCredentialsFactory.UserCredentials parseUserCredentials(Validator validator, Path credsYamlPath) {
final var objectMapper = JacksonUtils.getYamlObjectMapper();
final User user;
try {
user = objectMapper.readValue(readString(credsYamlPath), User.class);
} catch (JsonProcessingException e) {
throw new UserError("Couldn't read user credentials from '%s': %s", credsYamlPath, e.getMessage());
}
final var errors = validator.validate(user);
if (!errors.isEmpty()) {
throw new UserError("User credentials in '%s' are not valid:\n %s", credsYamlPath, errors.stream().map(error -> String.format("%s %s", error.getPropertyPath(), error.getMessage())).collect(Collectors.joining("\n ")));
}
return new UserCredentialsFactory.UserCredentials(user, Optional.empty());
}
use of com.datastax.fallout.service.core.User in project fallout by datastax.
the class UserDAO method makeUser.
private User makeUser(String name, String email, String password, String group) {
User user = new User();
user.setEmail(email);
user.setName(name);
user.setGroup(group);
user.setSalt(securityUtil.generateSalt());
user.setEncryptedPassword(securityUtil.getEncryptedPassword(password, user.getSalt()));
return user;
}
use of com.datastax.fallout.service.core.User in project fallout by datastax.
the class AccountResource method doLogin.
@POST
@Path("/login")
@Timed
@Produces(MediaType.APPLICATION_JSON)
public Response doLogin(@FormParam("email") @NotEmpty String email, @FormParam("password") @NotEmpty String password, @FormParam("remember") @DefaultValue("false") String rememberStr) {
validateEmail(email);
User existingUser = userDAO.getUser(email);
boolean badCreds = existingUser == null || existingUser.getSalt() == null;
try {
badCreds = badCreds || !securityUtil.authenticate(password, existingUser.getEncryptedPassword(), existingUser.getSalt());
} catch (Exception e) {
logger.error("Error creating user", e);
throw new WebApplicationException(e.getMessage());
}
if (badCreds) {
throw new WebApplicationException("Bad Email/Password", Response.Status.BAD_REQUEST);
}
Session session = userDAO.addSession(existingUser);
// 2 weeks
int expires = rememberStr.equals("false") ? -1 : 60 * 60 * 24 * 14;
return Response.ok().cookie(new NewCookie(FalloutService.COOKIE_NAME, session.getTokenId().toString(), "/", null, null, expires, false)).build();
}
Aggregations