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
8fc4f6f4
Commit
8fc4f6f4
authored
Feb 23, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
group solutions
parent
8d174e5d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
11 deletions
+22
-11
CTFApplication.java
service/src/main/java/CTFApplication.java
+13
-4
SolutionsResource.java
service/src/main/java/api/SolutionsResource.java
+8
-7
SolutionsRepository.java
service/src/main/java/repositories/SolutionsRepository.java
+1
-0
No files found.
service/src/main/java/CTFApplication.java
View file @
8fc4f6f4
...
@@ -41,6 +41,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -41,6 +41,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
private
UsersRepository
usersRepository
;
//todo: refactor to injects
private
UsersRepository
usersRepository
;
//todo: refactor to injects
private
TasksRepository
tasksRepository
;
//todo: refactor to injects
private
TasksRepository
tasksRepository
;
//todo: refactor to injects
private
TeamsRepository
teamsRepository
;
private
TeamsRepository
teamsRepository
;
private
SolutionsRepository
solutionsRepository
;
private
Injector
injector
;
private
Injector
injector
;
@Override
@Override
...
@@ -68,7 +69,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -68,7 +69,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
});
});
}
}
private
void
intializeTasks
()
{
private
void
in
i
tializeTasks
()
{
int
numberOfNewTasks
=
20
;
int
numberOfNewTasks
=
20
;
tasksRepository
.
clean
();
tasksRepository
.
clean
();
for
(
int
i
=
0
;
i
<
numberOfNewTasks
;
i
++)
{
for
(
int
i
=
0
;
i
<
numberOfNewTasks
;
i
++)
{
...
@@ -80,6 +81,10 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -80,6 +81,10 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
}
}
}
}
private
void
initializeSolutions
()
{
solutionsRepository
.
clean
();
}
private
void
registerResources
(
Environment
environment
)
{
private
void
registerResources
(
Environment
environment
)
{
environment
.
jersey
().
register
(
injector
.
getInstance
(
TeamsResource
.
class
));
environment
.
jersey
().
register
(
injector
.
getInstance
(
TeamsResource
.
class
));
environment
.
jersey
().
register
(
injector
.
getInstance
(
TasksResource
.
class
));
environment
.
jersey
().
register
(
injector
.
getInstance
(
TasksResource
.
class
));
...
@@ -105,7 +110,8 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -105,7 +110,8 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
injector
=
createInjector
(
applicationConfiguration
,
datastore
);
injector
=
createInjector
(
applicationConfiguration
,
datastore
);
initializeTeams
(
applicationConfiguration
);
initializeTeams
(
applicationConfiguration
);
intializeTasks
();
initializeTasks
();
initializeSolutions
();
registerResources
(
environment
);
registerResources
(
environment
);
registerAuthFeatures
(
environment
);
registerAuthFeatures
(
environment
);
}
}
...
@@ -122,8 +128,11 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -122,8 +128,11 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
@Override
@Override
public
com
.
google
.
common
.
base
.
Optional
<
User
>
authenticate
(
BasicCredentials
credentials
)
throws
AuthenticationException
{
public
com
.
google
.
common
.
base
.
Optional
<
User
>
authenticate
(
BasicCredentials
credentials
)
throws
AuthenticationException
{
User
user
=
usersRepository
.
authenticateUser
(
credentials
);
User
user
=
usersRepository
.
authenticateUser
(
credentials
);
if
(
user
!=
null
)
{
return
Optional
.
of
(
user
);
return
Optional
.
of
(
user
);
}
}
return
Optional
.
absent
();
}
}
}
public
class
ExampleAuthorizer
implements
Authorizer
<
User
>
{
public
class
ExampleAuthorizer
implements
Authorizer
<
User
>
{
...
@@ -143,7 +152,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -143,7 +152,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
//todo: refactor?
//todo: refactor?
teamsRepository
=
new
TeamsRepository
(
datastore
);
teamsRepository
=
new
TeamsRepository
(
datastore
);
usersRepository
=
new
UsersRepository
(
datastore
,
teamsRepository
);
usersRepository
=
new
UsersRepository
(
datastore
,
teamsRepository
);
SolutionsRepository
solutionsRepository
=
new
SolutionsRepository
(
datastore
);
solutionsRepository
=
new
SolutionsRepository
(
datastore
);
tasksRepository
=
new
TasksRepository
(
applicationConfiguration
,
datastore
,
teamsRepository
,
solutionsRepository
,
tasksRepository
=
new
TasksRepository
(
applicationConfiguration
,
datastore
,
teamsRepository
,
solutionsRepository
,
usersRepository
);
usersRepository
);
...
...
service/src/main/java/api/SolutionsResource.java
View file @
8fc4f6f4
...
@@ -9,6 +9,9 @@ import javax.ws.rs.Path;
...
@@ -9,6 +9,9 @@ import javax.ws.rs.Path;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.MediaType
;
import
java.util.List
;
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.
* Created by gpietrus on 16.02.16.
...
@@ -26,11 +29,8 @@ public class SolutionsResource {
...
@@ -26,11 +29,8 @@ public class SolutionsResource {
@GET
@GET
@Path
(
"/all"
)
@Path
(
"/all"
)
//todo: refactor mapping
public
Map
<
String
,
List
<
String
>>
getTeamsSolutions
()
{
public
List
<
Solution
>
getTeamsSolutions
()
{
return
solutionsRepository
.
getAll
()
return
solutionsRepository
.
getAll
();
//todo: general refactor
/*return solutionsRepository.getAll()
.
stream
()
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
new
Function
<
Solution
,
String
>()
{
.
collect
(
Collectors
.
groupingBy
(
new
Function
<
Solution
,
String
>()
{
@Override
@Override
...
@@ -43,9 +43,10 @@ public class SolutionsResource {
...
@@ -43,9 +43,10 @@ public class SolutionsResource {
.
collect
(
Collectors
.
toMap
(
.
collect
(
Collectors
.
toMap
(
Map
.
Entry
::
getKey
,
Map
.
Entry
::
getKey
,
entry
->
entry
.
getValue
().
stream
()
entry
->
entry
.
getValue
().
stream
()
.map(
Solution::getTeam
)
.
map
(
solution
->
solution
.
getTeam
().
getName
()
)
.
collect
(
Collectors
.
toList
())
.
collect
(
Collectors
.
toList
())
));*/
));
}
}
}
}
service/src/main/java/repositories/SolutionsRepository.java
View file @
8fc4f6f4
...
@@ -27,6 +27,7 @@ public class SolutionsRepository implements Repository {
...
@@ -27,6 +27,7 @@ public class SolutionsRepository implements Repository {
public
void
add
(
Solution
solution
)
{
//todo
public
void
add
(
Solution
solution
)
{
//todo
datastore
.
save
(
solution
);
//todo: error handling?
datastore
.
save
(
solution
);
//todo: error handling?
//todo: do not add if already exists
}
}
public
void
clean
()
{
public
void
clean
()
{
...
...
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