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
0946634c
Commit
0946634c
authored
Mar 08, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
public endpoints stub
parent
bb2009d5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
18 deletions
+43
-18
Task.java
service/src/main/java/objects/tasks/Task.java
+2
-0
TasksRepository.java
service/src/main/java/repositories/TasksRepository.java
+39
-16
TasksResource.java
service/src/main/java/resources/TasksResource.java
+2
-2
No files found.
service/src/main/java/objects/tasks/Task.java
View file @
0946634c
package
objects
.
tasks
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
core.TaskType
;
import
objects.Flag
;
import
org.bson.types.ObjectId
;
...
...
@@ -9,6 +10,7 @@ import org.mongodb.morphia.annotations.Id;
import
java.util.List
;
@Entity
(
"tasks"
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
Task
{
@Id
private
ObjectId
id
;
...
...
service/src/main/java/repositories/TasksRepository.java
View file @
0946634c
...
...
@@ -27,7 +27,8 @@ import java.util.stream.Collectors;
* Created by gpietrus on 20.02.2016.
*/
@Singleton
public
class
TasksRepository
implements
Repository
{
public
class
TasksRepository
implements
Repository
{
private
ApplicationConfiguration
applicationConfiguration
;
private
Datastore
datastore
;
...
...
@@ -39,7 +40,8 @@ public class TasksRepository implements Repository {
@Inject
public
TasksRepository
(
ApplicationConfiguration
applicationConfiguration
,
Datastore
datastore
,
TeamsRepository
teamsRepository
,
SolutionsRepository
solutionsRepository
,
UsersRepository
usersRepository
)
{
UsersRepository
usersRepository
)
{
this
.
applicationConfiguration
=
applicationConfiguration
;
this
.
datastore
=
datastore
;
this
.
teamsRepository
=
teamsRepository
;
...
...
@@ -48,24 +50,35 @@ public class TasksRepository implements Repository {
initialize
();
}
public
Task
get
(
String
taskName
)
{
//todo: task name?
public
Task
get
(
String
taskName
)
{
//todo: task name?
return
datastore
.
createQuery
(
Task
.
class
)
.
filter
(
"name"
,
taskName
)
.
get
();
}
public
Task
get
(
int
level
)
{
public
Task
get
(
int
level
)
{
return
datastore
.
createQuery
(
Task
.
class
)
.
filter
(
"level"
,
level
)
.
get
();
}
public
List
<
Task
>
getAll
()
{
public
List
<
Task
>
getAllPublic
()
{
return
datastore
.
createQuery
(
Task
.
class
)
.
retrievedFields
(
true
,
"name"
,
"level"
)
//todo: move to configuration
.
asList
();
}
public
List
<
Task
>
getAll
()
{
return
datastore
.
createQuery
(
Task
.
class
).
asList
();
}
@Override
public
void
initialize
()
{
public
void
initialize
()
{
List
<
CryptoTaskConfig
>
cryptoTasks
=
applicationConfiguration
.
getCryptoTasks
();
List
<
WebTaskConfig
>
webTasks
=
applicationConfiguration
.
getWebTasks
();
...
...
@@ -99,16 +112,19 @@ public class TasksRepository implements Repository {
)));
}
public
void
add
(
Task
task
)
{
public
void
add
(
Task
task
)
{
datastore
.
save
(
task
);
}
public
void
clean
()
{
public
void
clean
()
{
datastore
.
getCollection
(
Task
.
class
).
drop
();
}
//todo: refactor?
public
Map
<
List
<
String
>,
Integer
>
getUserFlagsHashes
(
String
username
)
{
public
Map
<
List
<
String
>,
Integer
>
getUserFlagsHashes
(
String
username
)
{
return
this
.
getAll
().
stream
()
.
collect
(
Collectors
.
toMap
(
task
->
task
.
getFlags
().
stream
()
...
...
@@ -118,7 +134,8 @@ public class TasksRepository implements Repository {
));
}
public
String
calculateHashValue
(
String
username
,
String
flagValue
)
{
//todo
public
String
calculateHashValue
(
String
username
,
String
flagValue
)
{
//todo
String
combinedStrings
=
salt
+
username
+
flagValue
;
//todo
MessageDigest
md5
=
null
;
//todo: discuss
try
{
...
...
@@ -130,7 +147,8 @@ public class TasksRepository implements Repository {
return
encodedHash
;
}
private
void
acceptSolution
(
String
username
,
Integer
taskLevel
)
{
private
void
acceptSolution
(
String
username
,
Integer
taskLevel
)
{
User
user
=
usersRepository
.
getUserByName
(
username
);
Optional
<
Team
>
team
=
teamsRepository
.
getTeamByUser
(
user
);
Optional
<
Task
>
task
=
getTaskByLevel
(
taskLevel
);
...
...
@@ -139,7 +157,8 @@ public class TasksRepository implements Repository {
}
}
private
Optional
<
Task
>
getTaskByLevel
(
Integer
level
)
{
private
Optional
<
Task
>
getTaskByLevel
(
Integer
level
)
{
return
getAll
().
stream
()
.
filter
(
task
->
task
.
getLevel
()
==
level
)
.
findFirst
();
...
...
@@ -147,7 +166,8 @@ public class TasksRepository implements Repository {
//todo: cleanup
//todo: depracted?
private
void
acceptSolution
(
String
username
,
Task
task
)
{
private
void
acceptSolution
(
String
username
,
Task
task
)
{
User
user
=
usersRepository
.
getUserByName
(
username
);
Optional
<
Team
>
team
=
teamsRepository
.
getTeamByUser
(
user
);
if
(
team
.
isPresent
())
{
...
...
@@ -155,7 +175,8 @@ public class TasksRepository implements Repository {
}
}
private
Optional
<
Integer
>
findTaskLevelByFlag
(
String
username
,
String
flagValue
)
{
private
Optional
<
Integer
>
findTaskLevelByFlag
(
String
username
,
String
flagValue
)
{
return
getUserFlagsHashes
(
username
).
entrySet
()
.
stream
()
.
filter
(
flagsMapEntry
->
flagsMapEntry
.
getKey
().
contains
(
flagValue
))
...
...
@@ -163,7 +184,8 @@ public class TasksRepository implements Repository {
.
findFirst
();
}
public
boolean
checkFlag
(
String
username
,
String
flagValue
)
{
public
boolean
checkFlag
(
String
username
,
String
flagValue
)
{
Optional
<
Integer
>
taskLevel
=
findTaskLevelByFlag
(
username
,
flagValue
);
if
(
taskLevel
.
isPresent
())
{
acceptSolution
(
username
,
taskLevel
.
get
());
...
...
@@ -172,7 +194,8 @@ public class TasksRepository implements Repository {
return
false
;
}
public
Optional
<
List
<
String
>>
getUserTaskFlags
(
String
username
,
Integer
taskLevel
)
{
//todo: task level, task id
public
Optional
<
List
<
String
>>
getUserTaskFlags
(
String
username
,
Integer
taskLevel
)
{
//todo: task level, task id
return
getUserFlagsHashes
(
username
).
entrySet
().
stream
()
.
filter
(
taskEntry
->
taskEntry
.
getValue
().
equals
(
taskLevel
))
.
map
(
listIntegerEntry
->
{
...
...
service/src/main/java/resources/TasksResource.java
View file @
0946634c
...
...
@@ -34,8 +34,8 @@ public class TasksResource
}
@GET
public
List
<
Task
>
getTasks
()
{
return
tasksRepository
.
getAll
();
public
List
<
Task
>
getTasks
Public
()
{
return
tasksRepository
.
getAll
Public
();
}
@GET
...
...
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