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
2b5924d5
Commit
2b5924d5
authored
Mar 20, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checking if not already subbmited flag - stub
parent
592b3bee
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
3 deletions
+32
-3
SolutionsRepository.java
...ers/krakyournet/ctf/repositories/SolutionsRepository.java
+21
-0
TasksRepository.java
...phoners/krakyournet/ctf/repositories/TasksRepository.java
+11
-3
No files found.
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/SolutionsRepository.java
View file @
2b5924d5
package
com
.
telephoners
.
krakyournet
.
ctf
.
repositories
;
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.tasks.Task
;
...
...
@@ -9,7 +10,9 @@ import javax.inject.Inject;
import
javax.inject.Singleton
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.function.Function
;
import
java.util.function.Predicate
;
import
java.util.stream.Collectors
;
@Singleton
...
...
@@ -62,4 +65,22 @@ public class SolutionsRepository implements Repository
.
map
(
solution
->
solution
.
getFlag
().
getDescription
()).
collect
(
Collectors
.
toList
())
));
}
//todo: use datastore filter
public
boolean
exists
(
Solution
solution
)
{
//todo: refactor, ugly ;(
String
value
=
solution
.
getFlag
().
getValue
();
Optional
<
Solution
>
matchedSolution
=
getAll
().
stream
()
.
filter
(
new
Predicate
<
Solution
>()
{
@Override
public
boolean
test
(
Solution
solution
)
{
return
solution
.
getFlag
().
getValue
().
equals
(
value
);
}
})
.
findFirst
();
return
matchedSolution
.
isPresent
();
}
}
\ No newline at end of file
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/TasksRepository.java
View file @
2b5924d5
...
...
@@ -151,6 +151,11 @@ public class TasksRepository implements Repository
return
encodedHash
;
}
private
boolean
isAlreadySubmittedSolution
(
Solution
solution
)
{
return
solutionsRepository
.
exists
(
solution
);
}
public
boolean
checkHash
(
User
user
,
String
hashValue
)
{
//todo: refactor
...
...
@@ -161,12 +166,15 @@ public class TasksRepository implements Repository
Pair
<
Task
,
Flag
>
taskFlagPair
=
taskFlagPairOptional
.
get
();
Task
task
=
taskFlagPair
.
getKey
();
Flag
flag
=
taskFlagPair
.
getValue
();
Optional
<
Team
>
team
=
teamsRepository
.
getTeamByUser
(
user
);
if
(
team
.
isPresent
())
{
solutionsRepository
.
add
(
new
Solution
(
team
.
get
(),
task
,
flag
));
//todo
//todo: combine ifs
Solution
solution
=
new
Solution
(
team
.
get
(),
task
,
hashValue
);
//todo: conflict, solution stores task flag, should store hashValue!!
if
(!
isAlreadySubmittedSolution
(
solution
))
{
solutionsRepository
.
add
(
solution
);
return
true
;
}
}
return
false
;
}
...
...
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