Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
CTF
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grzegorz
CTF
Commits
1d59a411
Commit
1d59a411
authored
Feb 23, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lots of fixes
parent
2f110b49
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
69 deletions
+45
-69
CTFApplication.java
service/src/main/java/CTFApplication.java
+2
-2
SolutionsResource.java
service/src/main/java/api/SolutionsResource.java
+5
-7
Solution.java
service/src/main/java/objects/Solution.java
+15
-21
TasksRepository.java
service/src/main/java/repositories/TasksRepository.java
+12
-3
TeamsRepository.java
service/src/main/java/repositories/TeamsRepository.java
+6
-9
UsersRepository.java
service/src/main/java/repositories/UsersRepository.java
+5
-27
No files found.
service/src/main/java/CTFApplication.java
View file @
1d59a411
...
...
@@ -134,7 +134,6 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
}
//todo: inject dbonnector
private
Injector
createInjector
(
ApplicationConfiguration
applicationConfiguration
,
Datastore
datastore
)
{
return
Guice
.
createInjector
(
new
AbstractModule
()
{
@Override
...
...
@@ -145,7 +144,8 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
teamsRepository
=
new
TeamsRepository
(
datastore
);
usersRepository
=
new
UsersRepository
(
datastore
,
teamsRepository
);
SolutionsRepository
solutionsRepository
=
new
SolutionsRepository
(
datastore
);
tasksRepository
=
new
TasksRepository
(
applicationConfiguration
,
datastore
,
teamsRepository
,
solutionsRepository
);
tasksRepository
=
new
TasksRepository
(
applicationConfiguration
,
datastore
,
teamsRepository
,
solutionsRepository
,
usersRepository
);
bind
(
TeamsRepository
.
class
).
toInstance
(
teamsRepository
);
bind
(
TasksRepository
.
class
).
toInstance
(
tasksRepository
);
...
...
service/src/main/java/api/SolutionsResource.java
View file @
1d59a411
...
...
@@ -9,9 +9,6 @@ import javax.ws.rs.Path;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.MediaType
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
* Created by gpietrus on 16.02.16.
...
...
@@ -30,9 +27,10 @@ public class SolutionsResource {
@GET
@Path
(
"/all"
)
//todo: refactor mapping
public
Map
<
String
,
List
<
String
>>
getTeamsSolutions
()
{
public
List
<
Solution
>
getTeamsSolutions
()
{
return
solutionsRepository
.
getAll
();
//todo: general refactor
return
solutionsRepository
.
getAll
()
/*
return solutionsRepository.getAll()
.stream()
.collect(Collectors.groupingBy(new Function<Solution, String>() {
@Override
...
...
@@ -45,9 +43,9 @@ public class SolutionsResource {
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().stream()
.
map
(
Solution:
:
getTeam
Id
)
.map(Solution::getTeam)
.collect(Collectors.toList())
));
));
*/
}
}
service/src/main/java/objects/Solution.java
View file @
1d59a411
package
objects
;
import
com.google.common.collect.ImmutableMap
;
import
org.bson.Document
;
import
org.bson.types.ObjectId
;
import
org.mongodb.morphia.annotations.Entity
;
import
java.util.Map
;
import
org.mongodb.morphia.annotations.Id
;
/**
* Created by gpietrus on 20.02.2016.
*/
@Entity
(
"solutions"
)
public
class
Solution
{
@Id
private
ObjectId
id
;
private
String
taskName
;
private
String
teamId
;
private
Team
team
;
public
Solution
(
String
teamId
,
String
taskName
)
{
this
.
team
Id
=
teamId
;
public
Solution
(
Team
team
,
String
taskName
)
{
this
.
team
=
team
;
this
.
taskName
=
taskName
;
}
public
Solution
()
{}
public
Solution
()
{
}
public
String
getTaskName
(
)
{
return
taskName
;
public
void
setTaskName
(
String
taskName
)
{
this
.
taskName
=
taskName
;
}
public
String
getTeamId
(
)
{
return
teamId
;
public
void
setTeam
(
Team
team
)
{
this
.
team
=
team
;
}
public
Solution
(
Document
document
)
{
this
.
taskName
=
document
.
get
(
"taskName"
).
toString
();
//todo: refactor mapping
this
.
teamId
=
document
.
get
(
"teamId"
).
toString
();
public
String
getTaskName
()
{
return
taskName
;
}
//todo: refactor mapping
public
Map
<
String
,
String
>
toMap
()
{
return
ImmutableMap
.<
String
,
String
>
builder
()
.
put
(
"teamId"
,
teamId
)
.
put
(
"taskName"
,
taskName
)
.
build
();
public
Team
getTeam
()
{
return
team
;
}
}
service/src/main/java/repositories/TasksRepository.java
View file @
1d59a411
package
repositories
;
import
core.ApplicationConfiguration
;
import
objects.Solution
;
import
objects.Task
;
import
objects.Team
;
import
objects.User
;
import
org.apache.commons.codec.binary.Hex
;
import
org.mongodb.morphia.Datastore
;
...
...
@@ -23,15 +26,18 @@ public class TasksRepository implements Repository {
private
Datastore
datastore
;
private
TeamsRepository
teamsRepository
;
private
SolutionsRepository
solutionsRepository
;
private
UsersRepository
usersRepository
;
private
String
salt
=
"SECURE_SALT"
;
//todo
@Inject
public
TasksRepository
(
ApplicationConfiguration
applicationConfiguration
,
Datastore
datastore
,
TeamsRepository
teamsRepository
,
SolutionsRepository
solutionsRepository
)
{
TeamsRepository
teamsRepository
,
SolutionsRepository
solutionsRepository
,
UsersRepository
usersRepository
)
{
this
.
applicationConfiguration
=
applicationConfiguration
;
this
.
datastore
=
datastore
;
this
.
teamsRepository
=
teamsRepository
;
this
.
solutionsRepository
=
solutionsRepository
;
this
.
usersRepository
=
usersRepository
;
}
public
void
get
(
UUID
uuid
)
{
...
...
@@ -71,8 +77,11 @@ public class TasksRepository implements Repository {
}
private
void
acceptSolution
(
String
username
,
Task
task
)
{
//todo: getname, of get id?
// solutionsRepository.add(new Solution(teamsRepository.getTeamByUser(username).getName(), task.getName())); //tidod
User
user
=
usersRepository
.
getUserByName
(
username
);
Optional
<
Team
>
team
=
teamsRepository
.
getTeamByUser
(
user
);
if
(
team
.
isPresent
())
{
solutionsRepository
.
add
(
new
Solution
(
team
.
get
(),
task
.
getName
()));
}
}
private
boolean
compareHash
(
String
hash
,
String
username
)
throws
Exception
{
...
...
service/src/main/java/repositories/TeamsRepository.java
View file @
1d59a411
package
repositories
;
import
objects.Team
;
import
objects.User
;
import
org.mongodb.morphia.Datastore
;
import
javax.inject.Inject
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.UUID
;
/**
...
...
@@ -19,15 +21,10 @@ public class TeamsRepository implements Repository {
this
.
datastore
=
datastore
;
}
public
Team
getTeamByUser
(
String
username
)
{
return
null
;
/* return getAll().stream()
.filter(team -> team.getMembers().stream()
.map(User::getName)
.collect(Collectors.toList())
.contains(username))
.findFirst()
.get();*/
public
Optional
<
Team
>
getTeamByUser
(
User
user
)
{
return
datastore
.
createQuery
(
Team
.
class
).
asList
().
stream
()
.
filter
(
team
->
team
.
getMembers
().
contains
(
user
))
.
findFirst
();
}
public
void
get
(
UUID
uuid
)
{
...
...
service/src/main/java/repositories/UsersRepository.java
View file @
1d59a411
...
...
@@ -29,15 +29,11 @@ public class UsersRepository implements Repository {
}
}
// public Optional<User> get(String username) {
// Optional<User> userOptional = teamsRepository.getAll()
// .stream()
// .map(Team::getMembers)
// .flatMap(Collection::stream)
// .filter(user -> user.getName().equals(username))
// .findFirst();
// return userOptional;
// }
public
User
getUserByName
(
String
username
)
{
return
datastore
.
createQuery
(
User
.
class
)
.
field
(
"name"
).
equal
(
username
)
.
get
();
}
public
User
authenticateUser
(
BasicCredentials
basicCredentials
)
{
...
...
@@ -51,22 +47,4 @@ public class UsersRepository implements Repository {
public
List
getAll
()
{
return
null
;
}
// public void get(UUID uuid) {
// }
// public List<User> getAll() {
// return mongoDBConnector.getCollection("users")
// .stream()
// .map((Function<Document, User>) User::new)
// .collect(Collectors.toList());
// }
// public void add(User user) {
// mongoDBConnector.addDocument("users", new Document(user.toMap()));
// }
// public void clean() {
// mongoDBConnector.removeCollection("users");
// }
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment