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
e6f7e71b
Commit
e6f7e71b
authored
Feb 22, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move to seperate methods
parent
cec1c3d9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
53 deletions
+50
-53
CTFApplication.java
service/src/main/java/CTFApplication.java
+22
-22
Task.java
service/src/main/java/objects/Task.java
+26
-29
TasksRepository.java
service/src/main/java/repositories/TasksRepository.java
+2
-2
No files found.
service/src/main/java/CTFApplication.java
View file @
e6f7e71b
...
@@ -19,7 +19,6 @@ import io.dropwizard.setup.Bootstrap;
...
@@ -19,7 +19,6 @@ import io.dropwizard.setup.Bootstrap;
import
io.dropwizard.setup.Environment
;
import
io.dropwizard.setup.Environment
;
import
objects.Flag
;
import
objects.Flag
;
import
objects.Task
;
import
objects.Task
;
import
objects.Team
;
import
objects.User
;
import
objects.User
;
import
org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature
;
import
org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature
;
import
org.mongodb.morphia.Datastore
;
import
org.mongodb.morphia.Datastore
;
...
@@ -29,7 +28,6 @@ import repositories.TasksRepository;
...
@@ -29,7 +28,6 @@ import repositories.TasksRepository;
import
repositories.TeamsRepository
;
import
repositories.TeamsRepository
;
import
repositories.UsersRepository
;
import
repositories.UsersRepository
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.UUID
;
import
java.util.stream.Stream
;
import
java.util.stream.Stream
;
...
@@ -42,6 +40,8 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -42,6 +40,8 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
private
Datastore
datastore
;
private
Datastore
datastore
;
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
Injector
injector
;
@Override
@Override
public
void
initialize
(
final
Bootstrap
<
ApplicationConfiguration
>
bootstrap
)
public
void
initialize
(
final
Bootstrap
<
ApplicationConfiguration
>
bootstrap
)
...
@@ -59,29 +59,18 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -59,29 +59,18 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
datastore
.
ensureIndexes
();
datastore
.
ensureIndexes
();
}
}
@Override
//todo: cleanup
public
void
run
(
ApplicationConfiguration
applicationConfiguration
,
Environment
environment
)
throws
Exception
{
private
void
initializeTeams
(
ApplicationConfiguration
applicationConfiguration
)
{
initializeMorhpia
();
Injector
injector
=
createInjector
(
applicationConfiguration
,
datastore
);
//REGISTER TEAMS
//todo: clean whole base
TeamsRepository
teamsRepository
=
new
TeamsRepository
(
datastore
);
teamsRepository
.
clean
();
teamsRepository
.
clean
();
applicationConfiguration
.
getTeams
().
forEach
(
team
->
{
applicationConfiguration
.
getTeams
().
forEach
(
team
->
{
team
.
getMembers
().
stream
().
forEach
(
user
->
datastore
.
save
(
user
));
team
.
getMembers
().
stream
().
forEach
(
user
->
datastore
.
save
(
user
));
datastore
.
save
(
team
);
datastore
.
save
(
team
);
});
});
}
//GENERATE TASKS
private
void
intializeTasks
()
{
tasksRepository
.
clean
();
int
numberOfNewTasks
=
20
;
int
numberOfNewTasks
=
20
;
tasksRepository
.
clean
();
for
(
int
i
=
0
;
i
<
numberOfNewTasks
;
i
++)
{
for
(
int
i
=
0
;
i
<
numberOfNewTasks
;
i
++)
{
Task
task
=
new
Task
(
String
.
valueOf
(
UUID
.
randomUUID
()),
i
,
Task
task
=
new
Task
(
String
.
valueOf
(
UUID
.
randomUUID
()),
i
,
i
%
2
==
0
?
TaskType
.
CRYPTO
:
TaskType
.
WEB
,
i
%
2
==
0
?
TaskType
.
CRYPTO
:
TaskType
.
WEB
,
...
@@ -89,15 +78,16 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -89,15 +78,16 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
);
);
tasksRepository
.
add
(
task
);
tasksRepository
.
add
(
task
);
}
}
}
//GENERATE TASKS END
private
void
registerResources
(
Environment
environment
)
{
//REGISTER RESOURCES
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
));
environment
.
jersey
().
register
(
injector
.
getInstance
(
ProxyResource
.
class
));
environment
.
jersey
().
register
(
injector
.
getInstance
(
ProxyResource
.
class
));
environment
.
jersey
().
register
(
injector
.
getInstance
(
SolutionsResource
.
class
));
environment
.
jersey
().
register
(
injector
.
getInstance
(
SolutionsResource
.
class
));
}
private
void
registerAuthFeatures
(
Environment
environment
)
{
//REGISTER AUTH
//REGISTER AUTH
environment
.
jersey
().
register
(
new
AuthDynamicFeature
(
environment
.
jersey
().
register
(
new
AuthDynamicFeature
(
new
BasicCredentialAuthFilter
.
Builder
<
User
>()
new
BasicCredentialAuthFilter
.
Builder
<
User
>()
...
@@ -106,9 +96,19 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
...
@@ -106,9 +96,19 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
.
setRealm
(
"SUPER SECRET STUFF"
)
.
setRealm
(
"SUPER SECRET STUFF"
)
.
buildAuthFilter
()));
.
buildAuthFilter
()));
environment
.
jersey
().
register
(
RolesAllowedDynamicFeature
.
class
);
environment
.
jersey
().
register
(
RolesAllowedDynamicFeature
.
class
);
//If you want to use @Auth to inject a custom Principal type into your resource
environment
.
jersey
().
register
(
new
AuthValueFactoryProvider
.
Binder
<>(
User
.
class
));
environment
.
jersey
().
register
(
new
AuthValueFactoryProvider
.
Binder
<>(
User
.
class
));
}
@Override
public
void
run
(
ApplicationConfiguration
applicationConfiguration
,
Environment
environment
)
throws
Exception
{
//todo: refactor
initializeMorhpia
();
injector
=
createInjector
(
applicationConfiguration
,
datastore
);
initializeTeams
(
applicationConfiguration
);
intializeTasks
();
registerResources
(
environment
);
registerAuthFeatures
(
environment
);
}
}
//todo: move to seperate class
//todo: move to seperate class
...
...
service/src/main/java/objects/Task.java
View file @
e6f7e71b
package
objects
;
package
objects
;
import
com.google.common.collect.ImmutableMap
;
import
core.TaskType
;
import
core.TaskType
;
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.
* Created by gpietrus on 20.02.2016.
*/
*/
@Entity
(
"tasks"
)
public
class
Task
{
public
class
Task
{
@Id
private
ObjectId
id
;
private
String
name
;
private
String
name
;
private
int
level
;
private
int
level
;
private
TaskType
type
;
private
TaskType
t
askT
ype
;
private
Flag
flag
;
private
Flag
flag
;
public
Task
(
Document
document
)
{
public
Task
(
String
name
,
int
level
,
TaskType
type
,
Flag
flag
)
{
this
.
name
=
document
.
get
(
"name"
).
toString
()
;
this
.
flag
=
flag
;
this
.
level
=
(
int
)
document
.
get
(
"level"
)
;
this
.
taskType
=
type
;
this
.
type
=
TaskType
.
valueOf
(
document
.
get
(
"type"
).
toString
())
;
this
.
level
=
level
;
this
.
flag
=
new
Flag
(
document
.
get
(
"flag"
).
toString
())
;
this
.
name
=
name
;
}
}
public
Task
Type
getType
()
{
public
Task
()
{
return
type
;
}
}
public
Task
(
String
name
,
int
level
,
TaskType
type
,
Flag
flag
)
{
public
ObjectId
getId
()
{
this
.
name
=
name
;
return
id
;
this
.
level
=
level
;
this
.
type
=
type
;
this
.
flag
=
flag
;
}
}
public
void
set
Type
(
TaskType
type
)
{
public
void
set
Id
(
ObjectId
id
)
{
this
.
type
=
type
;
this
.
id
=
id
;
}
}
public
String
getName
()
{
public
String
getName
()
{
...
@@ -53,6 +52,14 @@ public class Task {
...
@@ -53,6 +52,14 @@ public class Task {
this
.
level
=
level
;
this
.
level
=
level
;
}
}
public
TaskType
getTaskType
()
{
return
taskType
;
}
public
void
setTaskType
(
TaskType
taskType
)
{
this
.
taskType
=
taskType
;
}
public
Flag
getFlag
()
{
public
Flag
getFlag
()
{
return
flag
;
return
flag
;
}
}
...
@@ -60,14 +67,4 @@ public class Task {
...
@@ -60,14 +67,4 @@ public class Task {
public
void
setFlag
(
Flag
flag
)
{
public
void
setFlag
(
Flag
flag
)
{
this
.
flag
=
flag
;
this
.
flag
=
flag
;
}
}
//todo: refactor mapping
public
Map
<
String
,
Object
>
toMap
()
{
return
ImmutableMap
.<
String
,
Object
>
builder
()
.
put
(
"name"
,
name
)
.
put
(
"level"
,
level
)
.
put
(
"type"
,
type
.
getType
())
.
put
(
"flag"
,
flag
.
getValue
())
.
build
();
}
}
}
service/src/main/java/repositories/TasksRepository.java
View file @
e6f7e71b
...
@@ -47,11 +47,11 @@ public class TasksRepository implements Repository {
...
@@ -47,11 +47,11 @@ public class TasksRepository implements Repository {
}
}
public
void
add
(
Task
task
)
{
public
void
add
(
Task
task
)
{
// mongoDBConnector.addDocument("tasks", new Document(task.toMap())); //todo
datastore
.
save
(
task
);
}
}
public
void
clean
()
{
public
void
clean
()
{
// mongoDBConnector.removeCollection("tasks"); //todo
datastore
.
getCollection
(
Task
.
class
).
drop
();
}
}
public
Map
<
String
,
Task
>
getUserFlagsHashes
(
String
username
)
{
public
Map
<
String
,
Task
>
getUserFlagsHashes
(
String
username
)
{
...
...
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