Commit 0f5cfb0d authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

stub of registration resource

parent 19918a59
...@@ -5,17 +5,12 @@ import com.google.common.collect.ImmutableSet; ...@@ -5,17 +5,12 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath; import com.google.common.reflect.ClassPath;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.telephoners.krakyournet.ctf.beans.Team;
import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.commands.PurgeDatabaseCommand; import com.telephoners.krakyournet.ctf.commands.PurgeDatabaseCommand;
import com.telephoners.krakyournet.ctf.commands.RegisterTasksCommand; import com.telephoners.krakyournet.ctf.commands.RegisterTasksCommand;
import com.telephoners.krakyournet.ctf.commands.RegisterTeamsCommand; import com.telephoners.krakyournet.ctf.commands.RegisterTeamsCommand;
import com.telephoners.krakyournet.ctf.core.ApplicationConfiguration; import com.telephoners.krakyournet.ctf.core.ApplicationConfiguration;
import com.telephoners.krakyournet.ctf.logging.LoggingFilter; import com.telephoners.krakyournet.ctf.logging.LoggingFilter;
import com.telephoners.krakyournet.ctf.modules.ApplicationModule; import com.telephoners.krakyournet.ctf.modules.ApplicationModule;
import com.telephoners.krakyournet.ctf.repositories.Repository;
import io.dropwizard.Application; import io.dropwizard.Application;
import io.dropwizard.assets.AssetsBundle; import io.dropwizard.assets.AssetsBundle;
import io.dropwizard.jersey.setup.JerseyEnvironment; import io.dropwizard.jersey.setup.JerseyEnvironment;
...@@ -47,8 +42,8 @@ public class CTFApplication extends Application<ApplicationConfiguration> ...@@ -47,8 +42,8 @@ public class CTFApplication extends Application<ApplicationConfiguration>
JerseyEnvironment jersey = environment.jersey(); JerseyEnvironment jersey = environment.jersey();
final ClassPath classPath = ClassPath.from(this.getClass().getClassLoader()); final ClassPath classPath = ClassPath.from(this.getClass().getClassLoader());
ImmutableSet<ClassPath.ClassInfo> resourceClasses = classPath.getTopLevelClasses("com.telephoners.krakyournet.ctf.resources"); ImmutableSet<ClassPath.ClassInfo> resourceClasses = classPath.getTopLevelClasses("com.telephoners.krakyournet.ctf.resources");
// resourceClasses.stream()
// .forEach(classInfo -> jersey.register(injector.getInstance(classInfo.load()))); resourceClasses.forEach(classInfo -> jersey.register(injector.getInstance(classInfo.load())));
} }
private void registerAuthFeatures(Environment environment) private void registerAuthFeatures(Environment environment)
......
package com.telephoners.krakyournet.ctf.resources;
import com.telephoners.krakyournet.ctf.beans.Team;
import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.repositories.Repository;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
@Singleton
@Path(value = "/register")
@Produces(MediaType.APPLICATION_JSON)
public class RegistrationResource
{
private final Repository<Team> teamsRepository;
private final Repository<User> userRepository;
@Inject
public RegistrationResource(final Repository<User> userRepository,
final Repository<Team> teamsRepository)
{
//todo: checkNotNUll
this.teamsRepository = teamsRepository;
this.userRepository = userRepository;
}
@GET
@Path("/team")
public String registerTeam(@QueryParam("teamName") final String teamName)
{
Team team = new Team();
team.setName(teamName);
team.setDescription("descr");
teamsRepository.add(team);
return team.getId();
}
@GET
@Path("/user")
public void register(@QueryParam("userName") final String userName,
@QueryParam("teamId") final String teamId)
{
if (!teamsRepository.contains(teamId))
{
throw new RuntimeException("Team does not exist");
}
User user = new User();
user.setEmail("gpietrusza@gmail.com");
user.setName(userName);
user.setPassword("password");
user.setAdmin(false);
user.setTeamId(teamId);
}
}
package com.telephoners.krakyournet.ctf.resources; package com.telephoners.krakyournet.ctf.resources;
import com.telephoners.krakyournet.ctf.beans.Flag;
import com.telephoners.krakyournet.ctf.beans.Solution;
import com.telephoners.krakyournet.ctf.beans.Team;
import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.beans.tasks.Task;
import com.telephoners.krakyournet.ctf.repositories.Repository;
import io.dropwizard.auth.Auth;
import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
import java.util.Map;
@Singleton @Singleton
@Path(value = "/solutions") @Path(value = "/solutions")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public class SolutionsResource public class SolutionsResource
{ {
private final Repository<Team> teamsRepository;
private final Repository<Solution> solutionsRepository;
private final Repository<Task> tasksRepository;
@Inject @GET
public SolutionsResource(Repository<Solution> solutionsRepository, public void get(){
Repository<Task> tasksRepository,
Repository<Team> teamsRepository)
{
this.solutionsRepository = solutionsRepository;
this.teamsRepository = teamsRepository;
this.tasksRepository = tasksRepository;
} }
// private final Repository<Team> teamsRepository;
// private final Repository<Solution> solutionsRepository;
// private final Repository<Task> tasksRepository;
//
// @Inject
// public SolutionsResource(Repository<Solution> solutionsRepository,
// Repository<Task> tasksRepository,
// Repository<Team> teamsRepository)
// {
// this.solutionsRepository = solutionsRepository;
// this.teamsRepository = teamsRepository;
// this.tasksRepository = tasksRepository;
// }
/*
@POST @POST
@Path("/{task_level}") @Path("/{task_level}")
public Response submitSolution(@Auth User user, public Response submitSolution(@Auth User user,
...@@ -47,7 +39,7 @@ public class SolutionsResource ...@@ -47,7 +39,7 @@ public class SolutionsResource
{ {
return null; return null;
//todo: this should be by id //todo: this should be by id
/*
Task task = tasksRepository.getByLevel(taskLevel); Task task = tasksRepository.getByLevel(taskLevel);
Flag flag = task.getFlags() Flag flag = task.getFlags()
.stream() .stream()
...@@ -56,7 +48,7 @@ public class SolutionsResource ...@@ -56,7 +48,7 @@ public class SolutionsResource
.orElseThrow(InvalidSolutionException::new); .orElseThrow(InvalidSolutionException::new);
solutionsRepository.submitSolution(new Solution(teamsRepository.getTeamByUser(user), task, flag)); solutionsRepository.submitSolution(new Solution(teamsRepository.getTeamByUser(user), task, flag));
return Response.ok().entity(flag).build();*/ return Response.ok().entity(flag).build();
} }
@GET @GET
...@@ -64,8 +56,8 @@ public class SolutionsResource ...@@ -64,8 +56,8 @@ public class SolutionsResource
public List<Integer> getTeamCompletedTasks(@Auth User user) public List<Integer> getTeamCompletedTasks(@Auth User user)
{ {
return null; return null;
/*
return solutionsRepository.getCompletedTasks(teamsRepository.getTeamByUser(user));*/ return solutionsRepository.getCompletedTasks(teamsRepository.getTeamByUser(user));
} }
@GET @GET
...@@ -73,22 +65,22 @@ return null; ...@@ -73,22 +65,22 @@ return null;
public Map<String, List<Integer>> getAllTeamsCompletedTasks(@Auth User user) public Map<String, List<Integer>> getAllTeamsCompletedTasks(@Auth User user)
{ {
return null; return null;
/*
return teamsRepository.getAll() return teamsRepository.getAll()
.stream() .stream()
.collect(Collectors.toMap( .collect(Collectors.toMap(
Team::getName, Team::getName,
solutionsRepository::getCompletedTasks solutionsRepository::getCompletedTasks
));*/ ));
} }
@GET @GET
@Path("/my") @Path("/my")
public Map<Integer, List<Flag>> getTeamSummittedFlags(@Auth User user) { public Map<Integer, List<Flag>> getTeamSummittedFlags(@Auth User user) {
return null; return null;
/*
Map<Integer, List<Flag>> teamSolutions = solutionsRepository.getTeamSolutions(teamsRepository.getTeamByUser(user)); Map<Integer, List<Flag>> teamSolutions = solutionsRepository.getTeamSolutions(teamsRepository.getTeamByUser(user));
return teamSolutions;*/ return teamSolutions;
} }
@GET @GET
...@@ -96,12 +88,12 @@ return null; ...@@ -96,12 +88,12 @@ return null;
public Map<String, Map<Integer, Integer>> getTeamsSolutions() public Map<String, Map<Integer, Integer>> getTeamsSolutions()
{ {
return null; return null;
/*
return teamsRepository.getAll() return teamsRepository.getAll()
.stream() .stream()
.collect(Collectors.toMap( .collect(Collectors.toMap(
Team::getName, Team::getName,
solutionsRepository::getPointsSum solutionsRepository::getPointsSum
));*/ ));
} }*/
} }
package com.telephoners.krakyournet.ctf.resources; package com.telephoners.krakyournet.ctf.resources;
import com.telephoners.krakyournet.ctf.beans.User; import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.beans.tasks.Task;
import com.telephoners.krakyournet.ctf.repositories.Repository;
import io.dropwizard.auth.Auth; import io.dropwizard.auth.Auth;
import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
...@@ -20,13 +17,13 @@ import java.net.URISyntaxException; ...@@ -20,13 +17,13 @@ import java.net.URISyntaxException;
@Path(value = "/task") @Path(value = "/task")
public class TaskResource public class TaskResource
{ {
private final Repository<Task> tasksRepository; // private final Repository<Task> tasksRepository;
//
@Inject // @Inject
public TaskResource(Repository<Task> tasksRepository) // public TaskResource(Repository<Task> tasksRepository)
{ // {
this.tasksRepository = tasksRepository; // this.tasksRepository = tasksRepository;
} // }
@Path("{task_level}/{path: .*}") @Path("{task_level}/{path: .*}")
......
package com.telephoners.krakyournet.ctf.resources; package com.telephoners.krakyournet.ctf.resources;
import com.telephoners.krakyournet.ctf.beans.tasks.Task; import com.telephoners.krakyournet.ctf.beans.tasks.Task;
import com.telephoners.krakyournet.ctf.repositories.Repository;
import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
...@@ -16,13 +14,13 @@ import java.util.List; ...@@ -16,13 +14,13 @@ import java.util.List;
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public class TasksResource public class TasksResource
{ {
private final Repository<Task> tasksRepository; // private final Repository<Task> tasksRepository;
//
@Inject // @Inject
public TasksResource(Repository<Task> tasksRepository) // public TasksResource(Repository<Task> tasksRepository)
{ // {
this.tasksRepository = tasksRepository; // this.tasksRepository = tasksRepository;
} // }
@GET @GET
public List<Task> getTasksPublic() public List<Task> getTasksPublic()
......
package com.telephoners.krakyournet.ctf.resources; package com.telephoners.krakyournet.ctf.resources;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.telephoners.krakyournet.ctf.beans.Team;
import com.telephoners.krakyournet.ctf.beans.User; import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.core.ApplicationConfiguration;
import com.telephoners.krakyournet.ctf.repositories.Repository;
import io.dropwizard.auth.Auth; import io.dropwizard.auth.Auth;
import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
...@@ -23,22 +19,23 @@ import java.io.IOException; ...@@ -23,22 +19,23 @@ import java.io.IOException;
public class UtilResource public class UtilResource
{ {
private static String redirectHtml = "<!DOCTYPE html><html lang=\"en\" ng-app=\"ctfApp\"><head></head><script type=\"text/javascript\">window.location = \"http://\" + window.location.host;</script></html>"; private static String redirectHtml = "<!DOCTYPE html><html lang=\"en\" ng-app=\"ctfApp\"><head></head><script type=\"text/javascript\">window.location = \"http://\" + window.location.host;</script></html>";
private final Repository<Team> teamsRepository; // private final Repository<Team> teamsRepository;
private final ApplicationConfiguration applicationConfiguration; // private final ApplicationConfiguration applicationConfiguration;
@Inject // @Inject
public UtilResource(Repository<Team> teamsRepository, // public UtilResource(Repository<Team> teamsRepository,
ApplicationConfiguration applicationConfiguration) // ApplicationConfiguration applicationConfiguration)
{ // {
this.teamsRepository = teamsRepository; // this.teamsRepository = teamsRepository;
this.applicationConfiguration = applicationConfiguration; // this.applicationConfiguration = applicationConfiguration;
} // }
@GET @GET
@Path("/startup") @Path("/startup")
public Response getStartupConfiguration() public Response getStartupConfiguration()
{ {
return Response.ok().entity(applicationConfiguration.getStartupConfiguration()).build(); return null;
// return Response.ok().entity(applicationConfiguration.getStartupConfiguration()).build();
} }
@GET @GET
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment