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
dcfa536c
Commit
dcfa536c
authored
Mar 09, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use mongodb deployed on vps
parent
dd28388a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
13 deletions
+25
-13
configuration.yml
service/configuration.yml
+1
-1
CTFApplication.java
service/src/main/java/CTFApplication.java
+24
-12
No files found.
service/configuration.yml
View file @
dcfa536c
dbHost
:
localhost
dbHost
:
46.4.242.141
dbPort
:
27017
dbName
:
db
...
...
service/src/main/java/CTFApplication.java
View file @
dcfa536c
...
...
@@ -27,20 +27,23 @@ import java.util.stream.Stream;
/**
* Created by gpietrus on 16.02.16.
*/
public
class
CTFApplication
extends
Application
<
ApplicationConfiguration
>
{
public
class
CTFApplication
extends
Application
<
ApplicationConfiguration
>
{
private
Datastore
datastore
;
private
Injector
injector
;
@Override
public
void
initialize
(
final
Bootstrap
<
ApplicationConfiguration
>
bootstrap
)
{
public
void
initialize
(
final
Bootstrap
<
ApplicationConfiguration
>
bootstrap
)
{
bootstrap
.
addBundle
(
new
AssetsBundle
(
"/assets"
,
"/page"
,
"index.html"
));
Stream
.
of
(
"org.webjars.npm"
,
"org.webjars.bower"
)
.
map
(
WebJarBundle:
:
new
)
.
forEach
(
bootstrap:
:
addBundle
);
}
private
void
registerResources
(
Environment
environment
)
{
private
void
registerResources
(
Environment
environment
)
{
JerseyEnvironment
jersey
=
environment
.
jersey
();
jersey
.
register
(
injector
.
getInstance
(
TeamsResource
.
class
));
jersey
.
register
(
injector
.
getInstance
(
TasksResource
.
class
));
...
...
@@ -49,7 +52,8 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
jersey
.
register
(
injector
.
getInstance
(
TaskResource
.
class
));
}
private
void
registerAuthFeatures
(
Environment
environment
)
{
private
void
registerAuthFeatures
(
Environment
environment
)
{
environment
.
jersey
().
register
(
new
AuthDynamicFeature
(
new
BasicCredentialAuthFilter
.
Builder
<
User
>()
.
setAuthenticator
(
injector
.
getInstance
(
ExampleAuthenticator
.
class
))
...
...
@@ -61,7 +65,8 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
}
@Override
public
void
run
(
ApplicationConfiguration
applicationConfiguration
,
Environment
environment
)
throws
Exception
{
public
void
run
(
ApplicationConfiguration
applicationConfiguration
,
Environment
environment
)
throws
Exception
{
injector
=
createInjector
(
applicationConfiguration
);
registerAdmins
(
applicationConfiguration
);
...
...
@@ -76,29 +81,36 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
}
//todo: remove
public
class
ExampleAuthorizer
implements
Authorizer
<
User
>
{
public
class
ExampleAuthorizer
implements
Authorizer
<
User
>
{
@Override
public
boolean
authorize
(
User
user
,
String
role
)
{
public
boolean
authorize
(
User
user
,
String
role
)
{
return
user
.
getName
().
equals
(
"good-guy"
)
&&
role
.
equals
(
"ADMIN"
);
}
}
private
Injector
createInjector
(
ApplicationConfiguration
applicationConfiguration
)
{
return
Guice
.
createInjector
(
new
AbstractModule
()
{
private
Injector
createInjector
(
ApplicationConfiguration
applicationConfiguration
)
{
return
Guice
.
createInjector
(
new
AbstractModule
()
{
@Override
protected
void
configure
()
{
protected
void
configure
()
{
bind
(
ApplicationConfiguration
.
class
).
toInstance
(
applicationConfiguration
);
//todo: refactor
Morphia
morphia
=
new
Morphia
();
morphia
.
mapPackage
(
"objects.Team"
);
datastore
=
morphia
.
createDatastore
(
new
MongoClient
(),
"db"
);
//todo: db name from conf
datastore
=
morphia
.
createDatastore
(
new
MongoClient
(
applicationConfiguration
.
getDbHost
(),
applicationConfiguration
.
getDbPort
()),
applicationConfiguration
.
getDbName
());
datastore
.
ensureIndexes
();
bind
(
Datastore
.
class
).
toInstance
(
datastore
);
}
});
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
CTFApplication
().
run
(
args
);
}
}
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