Search in sources :

Example 1 with User

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);
}
Also used : PathParam(javax.ws.rs.PathParam) User(com.datastax.fallout.service.core.User) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Form(javax.ws.rs.core.Form) EMAIL_PATTERN(com.datastax.fallout.service.resources.server.AccountResource.EMAIL_PATTERN) Date(java.util.Date) HdrHistogramChecker(com.datastax.fallout.components.file_artifact_checkers.HdrHistogramChecker) Path(javax.ws.rs.Path) Auth(io.dropwizard.auth.Auth) TestRunIdentifier(com.datastax.fallout.service.core.TestRunIdentifier) TestRun(com.datastax.fallout.service.core.TestRun) FalloutView(com.datastax.fallout.service.views.FalloutView) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) PerformanceReportDAO(com.datastax.fallout.service.db.PerformanceReportDAO) DELETE(javax.ws.rs.DELETE) MainView(com.datastax.fallout.service.views.MainView) FileUtils(com.datastax.fallout.util.FileUtils) UserGroupMapper(com.datastax.fallout.service.db.UserGroupMapper) FormParam(javax.ws.rs.FormParam) TableDisplayOption(com.datastax.fallout.service.views.LinkedTestRuns.TableDisplayOption) POST(javax.ws.rs.POST) Files(java.nio.file.Files) Set(java.util.Set) PerformanceReport(com.datastax.fallout.service.core.PerformanceReport) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) ReadOnlyTestRun(com.datastax.fallout.service.core.ReadOnlyTestRun) List(java.util.List) TestDAO(com.datastax.fallout.service.db.TestDAO) TestRunDAO(com.datastax.fallout.service.db.TestRunDAO) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) WebApplicationException(javax.ws.rs.WebApplicationException) Optional(java.util.Optional) LinkedTestRuns(com.datastax.fallout.service.views.LinkedTestRuns) PerformanceReport(com.datastax.fallout.service.core.PerformanceReport) WebApplicationException(javax.ws.rs.WebApplicationException) TestRun(com.datastax.fallout.service.core.TestRun) ReadOnlyTestRun(com.datastax.fallout.service.core.ReadOnlyTestRun) LinkedTestRuns(com.datastax.fallout.service.views.LinkedTestRuns) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with User

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);
    }
}
Also used : User(com.datastax.fallout.service.core.User) AuthenticationException(io.dropwizard.auth.AuthenticationException) AuthenticationException(io.dropwizard.auth.AuthenticationException) Session(com.datastax.fallout.service.core.Session)

Example 3 with User

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());
}
Also used : User(com.datastax.fallout.service.core.User) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 4 with User

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;
}
Also used : User(com.datastax.fallout.service.core.User)

Example 5 with 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();
}
Also used : User(com.datastax.fallout.service.core.User) WebApplicationException(javax.ws.rs.WebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) Session(com.datastax.fallout.service.core.Session) NewCookie(javax.ws.rs.core.NewCookie) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

User (com.datastax.fallout.service.core.User)13 POST (javax.ws.rs.POST)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 WebApplicationException (javax.ws.rs.WebApplicationException)6 Timed (com.codahale.metrics.annotation.Timed)5 ReadOnlyTestRun (com.datastax.fallout.service.core.ReadOnlyTestRun)4 TestRun (com.datastax.fallout.service.core.TestRun)4 PerformanceReportDAO (com.datastax.fallout.service.db.PerformanceReportDAO)4 TestDAO (com.datastax.fallout.service.db.TestDAO)4 TestRunDAO (com.datastax.fallout.service.db.TestRunDAO)4 UserGroupMapper (com.datastax.fallout.service.db.UserGroupMapper)4 MainView (com.datastax.fallout.service.views.MainView)4 URI (java.net.URI)4 Paths (java.nio.file.Paths)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Set (java.util.Set)4