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
17f11a8b
Commit
17f11a8b
authored
Nov 11, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove or mock morphia stuff
parent
5cca4c3f
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
39 additions
and
155 deletions
+39
-155
UserAuthenticator.java
...m/telephoners/krakyournet/ctf/auth/UserAuthenticator.java
+4
-3
Flag.java
...main/java/com/telephoners/krakyournet/ctf/beans/Flag.java
+2
-4
Solution.java
.../java/com/telephoners/krakyournet/ctf/beans/Solution.java
+0
-6
Team.java
...main/java/com/telephoners/krakyournet/ctf/beans/Team.java
+0
-33
User.java
...main/java/com/telephoners/krakyournet/ctf/beans/User.java
+0
-27
Task.java
...ava/com/telephoners/krakyournet/ctf/beans/tasks/Task.java
+0
-33
TextTask.java
...com/telephoners/krakyournet/ctf/beans/tasks/TextTask.java
+0
-2
WebTask.java
.../com/telephoners/krakyournet/ctf/beans/tasks/WebTask.java
+0
-2
PurgeDatabaseCommand.java
...honers/krakyournet/ctf/commands/PurgeDatabaseCommand.java
+2
-3
Repository.java
.../telephoners/krakyournet/ctf/repositories/Repository.java
+5
-9
SolutionsRepository.java
...ers/krakyournet/ctf/repositories/SolutionsRepository.java
+8
-6
TasksRepository.java
...phoners/krakyournet/ctf/repositories/TasksRepository.java
+7
-11
TeamsRepository.java
...phoners/krakyournet/ctf/repositories/TeamsRepository.java
+4
-9
UsersRepository.java
...phoners/krakyournet/ctf/repositories/UsersRepository.java
+7
-7
No files found.
service/src/main/java/com/telephoners/krakyournet/ctf/auth/UserAuthenticator.java
View file @
17f11a8b
package
com
.
telephoners
.
krakyournet
.
ctf
.
auth
;
package
com
.
telephoners
.
krakyournet
.
ctf
.
auth
;
import
com.google.common.base.Optional
;
import
com.google.inject.Inject
;
import
com.google.inject.Inject
;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
com.telephoners.krakyournet.ctf.repositories.UsersRepository
;
import
com.telephoners.krakyournet.ctf.repositories.UsersRepository
;
...
@@ -19,12 +18,14 @@ public class UserAuthenticator implements Authenticator<BasicCredentials, User>
...
@@ -19,12 +18,14 @@ public class UserAuthenticator implements Authenticator<BasicCredentials, User>
}
}
@Override
@Override
public
Optional
<
User
>
authenticate
(
BasicCredentials
credentials
)
throws
AuthenticationException
public
java
.
util
.
Optional
<
User
>
authenticate
(
BasicCredentials
credentials
)
throws
AuthenticationException
{
{
return
null
;
/*
User user = usersRepository.authenticateUser(credentials);
User user = usersRepository.authenticateUser(credentials);
if (user != null) {
if (user != null) {
return Optional.of(user);
return Optional.of(user);
}
}
return
Optional
.
absent
();
return Optional.absent();
*/
}
}
}
}
\ No newline at end of file
service/src/main/java/com/telephoners/krakyournet/ctf/beans/Flag.java
View file @
17f11a8b
package
com
.
telephoners
.
krakyournet
.
ctf
.
beans
;
package
com
.
telephoners
.
krakyournet
.
ctf
.
beans
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
public
class
Flag
{
public
class
Flag
{
private
String
value
;
private
String
value
;
private
String
description
;
private
String
description
;
...
@@ -16,12 +14,12 @@ public class Flag {
...
@@ -16,12 +14,12 @@ public class Flag {
this
.
points
=
points
;
this
.
points
=
points
;
}
}
@JsonProperty
(
access
=
JsonProperty
.
Access
.
WRITE_ONLY
)
//
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
public
String
getValue
()
{
public
String
getValue
()
{
return
value
;
return
value
;
}
}
@JsonProperty
(
access
=
JsonProperty
.
Access
.
WRITE_ONLY
)
//
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
public
void
setValue
(
String
value
)
{
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
this
.
value
=
value
;
}
}
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/beans/Solution.java
View file @
17f11a8b
package
com
.
telephoners
.
krakyournet
.
ctf
.
beans
;
package
com
.
telephoners
.
krakyournet
.
ctf
.
beans
;
import
com.telephoners.krakyournet.ctf.beans.tasks.Task
;
import
com.telephoners.krakyournet.ctf.beans.tasks.Task
;
import
org.bson.types.ObjectId
;
import
org.joda.time.Instant
;
import
org.joda.time.Instant
;
import
org.mongodb.morphia.annotations.Entity
;
import
org.mongodb.morphia.annotations.Id
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
@Entity
(
"solutions"
)
public
class
Solution
public
class
Solution
{
{
@Id
private
ObjectId
id
;
private
Task
task
;
private
Task
task
;
private
Team
team
;
private
Team
team
;
private
Flag
flag
;
private
Flag
flag
;
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/beans/Team.java
View file @
17f11a8b
...
@@ -2,21 +2,13 @@ package com.telephoners.krakyournet.ctf.beans;
...
@@ -2,21 +2,13 @@ package com.telephoners.krakyournet.ctf.beans;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
org.bson.types.ObjectId
;
import
org.mongodb.morphia.annotations.Entity
;
import
org.mongodb.morphia.annotations.Id
;
import
org.mongodb.morphia.annotations.Reference
;
import
java.util.List
;
import
java.util.List
;
@Entity
(
"teams"
)
public
class
Team
{
public
class
Team
{
@Id
private
ObjectId
id
;
private
String
name
;
private
String
name
;
private
String
description
;
private
String
description
;
@Reference
private
List
<
User
>
members
;
private
List
<
User
>
members
;
@JsonCreator
@JsonCreator
...
@@ -50,29 +42,4 @@ public class Team {
...
@@ -50,29 +42,4 @@ public class Team {
public
List
<
User
>
getMembers
()
{
public
List
<
User
>
getMembers
()
{
return
members
;
return
members
;
}
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
Team
team
=
(
Team
)
o
;
if
(
id
!=
null
?
!
id
.
equals
(
team
.
id
)
:
team
.
id
!=
null
)
return
false
;
if
(
name
!=
null
?
!
name
.
equals
(
team
.
name
)
:
team
.
name
!=
null
)
return
false
;
if
(
description
!=
null
?
!
description
.
equals
(
team
.
description
)
:
team
.
description
!=
null
)
return
false
;
return
members
!=
null
?
members
.
equals
(
team
.
members
)
:
team
.
members
==
null
;
}
@Override
public
int
hashCode
()
{
int
result
=
id
!=
null
?
id
.
hashCode
()
:
0
;
result
=
31
*
result
+
(
name
!=
null
?
name
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
description
!=
null
?
description
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
members
!=
null
?
members
.
hashCode
()
:
0
);
return
result
;
}
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/beans/User.java
View file @
17f11a8b
...
@@ -2,16 +2,10 @@ package com.telephoners.krakyournet.ctf.beans;
...
@@ -2,16 +2,10 @@ package com.telephoners.krakyournet.ctf.beans;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
org.bson.types.ObjectId
;
import
org.mongodb.morphia.annotations.Entity
;
import
org.mongodb.morphia.annotations.Id
;
import
java.security.Principal
;
import
java.security.Principal
;
@Entity
(
"users"
)
public
class
User
implements
Principal
{
public
class
User
implements
Principal
{
@Id
private
ObjectId
id
;
private
String
name
;
private
String
name
;
private
String
password
;
private
String
password
;
private
String
email
;
private
String
email
;
...
@@ -44,27 +38,6 @@ public class User implements Principal {
...
@@ -44,27 +38,6 @@ public class User implements Principal {
return
name
;
return
name
;
}
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
User
user
=
(
User
)
o
;
if
(
name
!=
null
?
!
name
.
equals
(
user
.
name
)
:
user
.
name
!=
null
)
return
false
;
if
(
password
!=
null
?
!
password
.
equals
(
user
.
password
)
:
user
.
password
!=
null
)
return
false
;
return
email
!=
null
?
email
.
equals
(
user
.
email
)
:
user
.
email
==
null
;
}
@Override
public
int
hashCode
()
{
int
result
=
name
!=
null
?
name
.
hashCode
()
:
0
;
result
=
31
*
result
+
(
password
!=
null
?
password
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
email
!=
null
?
email
.
hashCode
()
:
0
);
return
result
;
}
public
void
setName
(
String
name
)
{
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
this
.
name
=
name
;
}
}
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/beans/tasks/Task.java
View file @
17f11a8b
...
@@ -4,20 +4,14 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
...
@@ -4,20 +4,14 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.telephoners.krakyournet.ctf.beans.Flag
;
import
com.telephoners.krakyournet.ctf.beans.Flag
;
import
com.telephoners.krakyournet.ctf.helpers.PublicProperty
;
import
com.telephoners.krakyournet.ctf.helpers.PublicProperty
;
import
org.bson.types.ObjectId
;
import
org.mongodb.morphia.annotations.Entity
;
import
org.mongodb.morphia.annotations.Id
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response
;
import
java.net.URISyntaxException
;
import
java.net.URISyntaxException
;
import
java.util.List
;
import
java.util.List
;
@Entity
(
"tasks"
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
abstract
class
Task
public
abstract
class
Task
{
{
@Id
private
ObjectId
id
;
@PublicProperty
@PublicProperty
private
String
name
;
private
String
name
;
@PublicProperty
@PublicProperty
...
@@ -78,33 +72,6 @@ public abstract class Task
...
@@ -78,33 +72,6 @@ public abstract class Task
this
.
description
=
description
;
this
.
description
=
description
;
}
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
Task
task
=
(
Task
)
o
;
if
(
level
!=
task
.
level
)
return
false
;
if
(
id
!=
null
?
!
id
.
equals
(
task
.
id
)
:
task
.
id
!=
null
)
return
false
;
if
(
name
!=
null
?
!
name
.
equals
(
task
.
name
)
:
task
.
name
!=
null
)
return
false
;
if
(
description
!=
null
?
!
description
.
equals
(
task
.
description
)
:
task
.
description
!=
null
)
return
false
;
return
flags
!=
null
?
flags
.
equals
(
task
.
flags
)
:
task
.
flags
==
null
;
}
@Override
public
int
hashCode
()
{
int
result
=
id
!=
null
?
id
.
hashCode
()
:
0
;
result
=
31
*
result
+
(
name
!=
null
?
name
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
description
!=
null
?
description
.
hashCode
()
:
0
);
result
=
31
*
result
+
level
;
result
=
31
*
result
+
(
flags
!=
null
?
flags
.
hashCode
()
:
0
);
return
result
;
}
@JsonIgnore
@JsonIgnore
public
abstract
Response
getTaskResponse
()
throws
URISyntaxException
;
public
abstract
Response
getTaskResponse
()
throws
URISyntaxException
;
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/beans/tasks/TextTask.java
View file @
17f11a8b
...
@@ -3,12 +3,10 @@ package com.telephoners.krakyournet.ctf.beans.tasks;
...
@@ -3,12 +3,10 @@ package com.telephoners.krakyournet.ctf.beans.tasks;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.telephoners.krakyournet.ctf.beans.Flag
;
import
com.telephoners.krakyournet.ctf.beans.Flag
;
import
org.mongodb.morphia.annotations.Entity
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response
;
import
java.util.List
;
import
java.util.List
;
@Entity
(
"tasks"
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
TextTask
extends
Task
public
class
TextTask
extends
Task
{
{
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/beans/tasks/WebTask.java
View file @
17f11a8b
...
@@ -3,14 +3,12 @@ package com.telephoners.krakyournet.ctf.beans.tasks;
...
@@ -3,14 +3,12 @@ package com.telephoners.krakyournet.ctf.beans.tasks;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.telephoners.krakyournet.ctf.beans.Flag
;
import
com.telephoners.krakyournet.ctf.beans.Flag
;
import
org.mongodb.morphia.annotations.Entity
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response
;
import
java.net.URI
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.net.URISyntaxException
;
import
java.util.List
;
import
java.util.List
;
@Entity
(
"tasks"
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
WebTask
extends
Task
public
class
WebTask
extends
Task
{
{
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/commands/PurgeDatabaseCommand.java
View file @
17f11a8b
...
@@ -7,7 +7,6 @@ import com.telephoners.krakyournet.ctf.modules.ApplicationModule;
...
@@ -7,7 +7,6 @@ import com.telephoners.krakyournet.ctf.modules.ApplicationModule;
import
io.dropwizard.cli.ConfiguredCommand
;
import
io.dropwizard.cli.ConfiguredCommand
;
import
io.dropwizard.setup.Bootstrap
;
import
io.dropwizard.setup.Bootstrap
;
import
net.sourceforge.argparse4j.inf.Namespace
;
import
net.sourceforge.argparse4j.inf.Namespace
;
import
org.mongodb.morphia.Datastore
;
public
class
PurgeDatabaseCommand
extends
ConfiguredCommand
<
ApplicationConfiguration
>
public
class
PurgeDatabaseCommand
extends
ConfiguredCommand
<
ApplicationConfiguration
>
{
{
...
@@ -23,7 +22,7 @@ public class PurgeDatabaseCommand extends ConfiguredCommand<ApplicationConfigura
...
@@ -23,7 +22,7 @@ public class PurgeDatabaseCommand extends ConfiguredCommand<ApplicationConfigura
protected
void
run
(
Bootstrap
<
ApplicationConfiguration
>
bootstrap
,
Namespace
namespace
,
ApplicationConfiguration
applicationConfiguration
)
throws
Exception
protected
void
run
(
Bootstrap
<
ApplicationConfiguration
>
bootstrap
,
Namespace
namespace
,
ApplicationConfiguration
applicationConfiguration
)
throws
Exception
{
{
Injector
injector
=
Guice
.
createInjector
(
new
ApplicationModule
(
applicationConfiguration
));
Injector
injector
=
Guice
.
createInjector
(
new
ApplicationModule
(
applicationConfiguration
));
Datastore
datastore
=
injector
.
getInstance
(
Datastore
.
class
);
//
Datastore datastore = injector.getInstance(Datastore.class);
datastore
.
getDB
().
dropDatabase
();
//
datastore.getDB().dropDatabase();
}
}
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/Repository.java
View file @
17f11a8b
package
com
.
telephoners
.
krakyournet
.
ctf
.
repositories
;
package
com
.
telephoners
.
krakyournet
.
ctf
.
repositories
;
import
org.mongodb.morphia.Datastore
;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.ParameterizedType
;
import
java.util.List
;
import
java.util.List
;
public
abstract
class
Repository
<
T
>
public
abstract
class
Repository
<
T
>
{
{
protected
final
Datastore
datastore
;
@Inject
@Inject
public
Repository
(
Datastore
datastore
)
public
Repository
()
{
{
this
.
datastore
=
datastore
;
}
}
public
void
add
(
T
item
)
public
void
add
(
T
item
)
{
{
datastore
.
save
(
item
);
//
datastore.save(item);
}
}
public
List
<
T
>
getAll
()
public
List
<
T
>
getAll
()
{
{
return
datastore
.
createQuery
(
getRepositoryType
()).
asList
();
return
null
;
// return datastore.createQuery(getRepositoryType()).asList();
}
}
public
void
clean
()
public
void
clean
()
{
{
datastore
.
getCollection
(
getRepositoryType
()).
drop
();
//
datastore.getCollection(getRepositoryType()).drop();
}
}
Class
getRepositoryType
()
Class
getRepositoryType
()
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/SolutionsRepository.java
View file @
17f11a8b
...
@@ -5,7 +5,6 @@ import com.telephoners.krakyournet.ctf.beans.Solution;
...
@@ -5,7 +5,6 @@ import com.telephoners.krakyournet.ctf.beans.Solution;
import
com.telephoners.krakyournet.ctf.beans.Team
;
import
com.telephoners.krakyournet.ctf.beans.Team
;
import
com.telephoners.krakyournet.ctf.beans.tasks.Task
;
import
com.telephoners.krakyournet.ctf.beans.tasks.Task
;
import
com.telephoners.krakyournet.ctf.exceptions.SolutionAlreadySubmittedException
;
import
com.telephoners.krakyournet.ctf.exceptions.SolutionAlreadySubmittedException
;
import
org.mongodb.morphia.Datastore
;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
javax.inject.Singleton
;
import
javax.inject.Singleton
;
...
@@ -20,15 +19,15 @@ public class SolutionsRepository extends Repository<Solution>
...
@@ -20,15 +19,15 @@ public class SolutionsRepository extends Repository<Solution>
private
final
TasksRepository
tasksRepository
;
private
final
TasksRepository
tasksRepository
;
@Inject
@Inject
public
SolutionsRepository
(
TasksRepository
tasksRepository
,
public
SolutionsRepository
(
TasksRepository
tasksRepository
)
Datastore
datastore
)
{
{
super
(
datastore
);
this
.
tasksRepository
=
tasksRepository
;
this
.
tasksRepository
=
tasksRepository
;
}
}
public
Map
<
Integer
,
List
<
Flag
>>
getTeamSolutions
(
Team
team
)
public
Map
<
Integer
,
List
<
Flag
>>
getTeamSolutions
(
Team
team
)
{
{
return
null
;
/*
//todo: do not identify team by name? conflict in team ids?
//todo: do not identify team by name? conflict in team ids?
return datastore.createQuery(Solution.class)
return datastore.createQuery(Solution.class)
.filter("team.name", team.getName()).asList()
.filter("team.name", team.getName()).asList()
...
@@ -47,17 +46,20 @@ public class SolutionsRepository extends Repository<Solution>
...
@@ -47,17 +46,20 @@ public class SolutionsRepository extends Repository<Solution>
taskSolutions -> taskSolutions.getKey().getLevel(),
taskSolutions -> taskSolutions.getKey().getLevel(),
taskSolutions -> taskSolutions.getValue().stream()
taskSolutions -> taskSolutions.getValue().stream()
.map(Solution::getFlag).collect(Collectors.toList())
.map(Solution::getFlag).collect(Collectors.toList())
));
)); */
}
}
private
boolean
isAlreadySubmittedSolution
(
Solution
solution
)
private
boolean
isAlreadySubmittedSolution
(
Solution
solution
)
{
{
return
false
;
/*
List<Solution> solutions = datastore.find(Solution.class)
List<Solution> solutions = datastore.find(Solution.class)
.filter("flag.value", solution.getFlag().getValue()) //todo: do not filter by field
.filter("flag.value", solution.getFlag().getValue()) //todo: do not filter by field
.filter("team.name", solution.getTeam().getName()) //todo: whole object instead
.filter("team.name", solution.getTeam().getName()) //todo: whole object instead
.asList();
.asList();
return !solutions
return !solutions
.
isEmpty
();
.isEmpty();
*/
}
}
public
List
<
Integer
>
getCompletedTasks
(
Team
team
)
public
List
<
Integer
>
getCompletedTasks
(
Team
team
)
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/TasksRepository.java
View file @
17f11a8b
package
com
.
telephoners
.
krakyournet
.
ctf
.
repositories
;
package
com
.
telephoners
.
krakyournet
.
ctf
.
repositories
;
import
com.sun.tools.javac.util.List
;
import
com.telephoners.krakyournet.ctf.beans.tasks.Task
;
import
com.telephoners.krakyournet.ctf.beans.tasks.Task
;
import
com.telephoners.krakyournet.ctf.exceptions.TaskNotFoundException
;
import
com.telephoners.krakyournet.ctf.helpers.DBObjectUtils
;
import
org.mongodb.morphia.Datastore
;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
javax.inject.Singleton
;
import
javax.inject.Singleton
;
import
java.util.List
;
@Singleton
@Singleton
public
class
TasksRepository
extends
Repository
<
Task
>
public
class
TasksRepository
extends
Repository
<
Task
>
{
{
private
final
Datastore
datastore
;
@Inject
@Inject
public
TasksRepository
(
Datastore
datastore
)
public
TasksRepository
()
{
{
super
(
datastore
);
this
.
datastore
=
datastore
;
}
}
public
Task
getByLevel
(
int
level
)
public
Task
getByLevel
(
int
level
)
{
{
return
null
;
/*
return datastore.createQuery(Task.class)
return datastore.createQuery(Task.class)
.filter("level", level)
.filter("level", level)
.asList()
.asList()
.stream()
.stream()
.findFirst()
.findFirst()
.
orElseThrow
(
TaskNotFoundException:
:
new
);
.orElseThrow(TaskNotFoundException::new);
*/
}
}
public
List
<
Task
>
getAllPublic
()
public
List
<
Task
>
getAllPublic
()
{
{
return
null
;
/*
return datastore.createQuery(Task.class)
return datastore.createQuery(Task.class)
.order("level")
.order("level")
.retrievedFields(true, DBObjectUtils.getPublicFields(Task.class))
.retrievedFields(true, DBObjectUtils.getPublicFields(Task.class))
.
asList
();
.asList();
*/
}
}
}
}
\ No newline at end of file
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/TeamsRepository.java
View file @
17f11a8b
...
@@ -2,8 +2,6 @@ package com.telephoners.krakyournet.ctf.repositories;
...
@@ -2,8 +2,6 @@ package com.telephoners.krakyournet.ctf.repositories;
import
com.telephoners.krakyournet.ctf.beans.Team
;
import
com.telephoners.krakyournet.ctf.beans.Team
;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
com.telephoners.krakyournet.ctf.exceptions.TeamNotFoundException
;
import
org.mongodb.morphia.Datastore
;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
javax.inject.Singleton
;
import
javax.inject.Singleton
;
...
@@ -11,25 +9,22 @@ import javax.inject.Singleton;
...
@@ -11,25 +9,22 @@ import javax.inject.Singleton;
@Singleton
@Singleton
public
class
TeamsRepository
extends
Repository
<
Team
>
public
class
TeamsRepository
extends
Repository
<
Team
>
{
{
private
final
Datastore
datastore
;
private
final
UsersRepository
usersRepository
;
private
final
UsersRepository
usersRepository
;
@Inject
@Inject
public
TeamsRepository
(
Datastore
datastore
,
public
TeamsRepository
(
UsersRepository
usersRepository
)
UsersRepository
usersRepository
)
{
{
super
(
datastore
);
this
.
datastore
=
datastore
;
this
.
usersRepository
=
usersRepository
;
this
.
usersRepository
=
usersRepository
;
}
}
public
Team
getTeamByUser
(
User
user
)
public
Team
getTeamByUser
(
User
user
)
{
{
return
null
;
/*
return datastore.createQuery(Team.class).asList().stream()
return datastore.createQuery(Team.class).asList().stream()
.filter(team -> team.getMembers().contains(user))
.filter(team -> team.getMembers().contains(user))
.findFirst()
.findFirst()
.
orElseThrow
(
TeamNotFoundException:
:
new
);
.orElseThrow(TeamNotFoundException::new);
*/
}
}
public
Team
getTeamByUserName
(
String
username
)
public
Team
getTeamByUserName
(
String
username
)
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/UsersRepository.java
View file @
17f11a8b
...
@@ -3,11 +3,8 @@ package com.telephoners.krakyournet.ctf.repositories;
...
@@ -3,11 +3,8 @@ package com.telephoners.krakyournet.ctf.repositories;
import
com.google.inject.Inject
;
import
com.google.inject.Inject
;
import
com.google.inject.Singleton
;
import
com.google.inject.Singleton
;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
com.telephoners.krakyournet.ctf.exceptions.UserNotFoundException
;
import
com.telephoners.krakyournet.ctf.providers.MessageDigestProvider
;
import
com.telephoners.krakyournet.ctf.providers.MessageDigestProvider
;
import
io.dropwizard.auth.basic.BasicCredentials
;
import
io.dropwizard.auth.basic.BasicCredentials
;
import
org.apache.commons.codec.binary.Hex
;
import
org.mongodb.morphia.Datastore
;
@Singleton
@Singleton
public
class
UsersRepository
extends
Repository
<
User
>
public
class
UsersRepository
extends
Repository
<
User
>
...
@@ -15,27 +12,30 @@ public class UsersRepository extends Repository<User>
...
@@ -15,27 +12,30 @@ public class UsersRepository extends Repository<User>
private
final
MessageDigestProvider
messageDigestProvider
;
private
final
MessageDigestProvider
messageDigestProvider
;
@Inject
@Inject
public
UsersRepository
(
Datastore
datastore
,
MessageDigestProvider
messageDigestProvider
)
public
UsersRepository
(
MessageDigestProvider
messageDigestProvider
)
{
{
super
(
datastore
);
this
.
messageDigestProvider
=
messageDigestProvider
;
this
.
messageDigestProvider
=
messageDigestProvider
;
}
}
public
User
getUserByName
(
String
username
)
public
User
getUserByName
(
String
username
)
{
{
return
null
;
/*
return datastore.createQuery(User.class)
return datastore.createQuery(User.class)
.field("name").equal(username)
.field("name").equal(username)
.asList()
.asList()
.stream()
.stream()
.findFirst()
.findFirst()
.
orElseThrow
(
UserNotFoundException:
:
new
);
.orElseThrow(UserNotFoundException::new);
*/
}
}
public
User
authenticateUser
(
BasicCredentials
basicCredentials
)
public
User
authenticateUser
(
BasicCredentials
basicCredentials
)
{
{
return
null
;
/*
return datastore.createQuery(User.class)
return datastore.createQuery(User.class)
.field("name").equal(basicCredentials.getUsername())
.field("name").equal(basicCredentials.getUsername())
.field("password").equal(Hex.encodeHexString(messageDigestProvider.getMessageDigest().digest(basicCredentials.getPassword().getBytes())))
.field("password").equal(Hex.encodeHexString(messageDigestProvider.getMessageDigest().digest(basicCredentials.getPassword().getBytes())))
.
get
();
.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