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
5326152a
Commit
5326152a
authored
Apr 09, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
headers handling
parent
4c82e88b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
14 deletions
+64
-14
TaskRequestContext.java
...oners/krakyournet/ctf/beans/tasks/TaskRequestContext.java
+13
-0
TaskResponse.java
...telephoners/krakyournet/ctf/beans/tasks/TaskResponse.java
+7
-6
TaskResource.java
...m/telephoners/krakyournet/ctf/resources/TaskResource.java
+44
-8
No files found.
service/src/main/java/com/telephoners/krakyournet/ctf/beans/tasks/TaskRequestContext.java
View file @
5326152a
...
...
@@ -2,12 +2,15 @@ package com.telephoners.krakyournet.ctf.beans.tasks;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
java.util.Map
;
public
class
TaskRequestContext
{
private
String
httpMethod
;
//todo: use class
private
User
user
;
private
String
path
;
private
String
body
;
private
Map
<
String
,
String
>
headers
;
public
TaskRequestContext
withHttpMethod
(
String
httpMethod
)
{
...
...
@@ -32,6 +35,11 @@ public class TaskRequestContext
return
this
;
}
public
TaskRequestContext
withHeaders
(
Map
<
String
,
String
>
headers
)
{
this
.
headers
=
headers
;
return
this
;
}
public
String
getHttpMethod
()
{
return
httpMethod
;
...
...
@@ -51,4 +59,9 @@ public class TaskRequestContext
{
return
body
;
}
public
Map
<
String
,
String
>
getHeaders
()
{
return
headers
;
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/beans/tasks/TaskResponse.java
View file @
5326152a
package
com
.
telephoners
.
krakyournet
.
ctf
.
beans
.
tasks
;
import
java.util.Map
;
public
class
TaskResponse
{
private
String
text
;
private
String
kynHeader
;
private
Map
<
String
,
String
>
headers
;
public
TaskResponse
(
String
text
,
String
kynHeader
)
public
TaskResponse
(
String
text
,
Map
<
String
,
String
>
headers
)
{
this
.
text
=
text
;
this
.
kynHeader
=
kynHeader
;
this
.
headers
=
headers
;
}
public
String
getText
()
{
return
text
;
}
public
String
getKynHeader
()
public
Map
<
String
,
String
>
getHeaders
()
{
return
kynHeader
;
return
headers
;
}
}
\ No newline at end of file
service/src/main/java/com/telephoners/krakyournet/ctf/resources/TaskResource.java
View file @
5326152a
package
com
.
telephoners
.
krakyournet
.
ctf
.
resources
;
import
com.google.common.collect.Sets
;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
com.telephoners.krakyournet.ctf.beans.tasks.Task
;
import
com.telephoners.krakyournet.ctf.beans.tasks.TaskRequestContext
;
...
...
@@ -17,15 +18,20 @@ import javax.ws.rs.Path;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.container.ContainerRequestContext
;
import
javax.ws.rs.core.Context
;
import
javax.ws.rs.core.MultivaluedMap
;
import
javax.ws.rs.core.Response
;
import
java.io.IOException
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.function.Consumer
;
import
java.util.stream.Collectors
;
@Singleton
@Path
(
value
=
"/task"
)
public
class
TaskResource
{
private
final
TasksRepository
tasksRepository
;
private
static
final
S
tring
KYN_HEADER_NAME
=
"KYN_2016"
;
//todo, move to configuration
private
static
final
S
et
<
String
>
PROXIED_HEADERS
=
Sets
.
newHashSet
(
"KYN_2016"
,
"EY_HEADER"
,
"Content-Type"
);
//todo: move to conf
@Inject
public
TaskResource
(
TasksRepository
tasksRepository
)
...
...
@@ -55,6 +61,16 @@ public class TaskResource
}
*/
private
Map
<
String
,
String
>
extractProxiedHeaders
(
MultivaluedMap
<
String
,
String
>
headers
)
{
return
headers
.
entrySet
()
.
stream
()
.
filter
(
header
->
PROXIED_HEADERS
.
contains
(
header
.
getKey
()))
.
collect
(
Collectors
.
toMap
(
Map
.
Entry
::
getKey
,
entry
->
entry
.
getValue
().
get
(
0
)
//todo: check
));
}
@Path
(
"{task_level}/{path: .*}"
)
@GET
public
Response
getTaskGet
(
@Auth
User
user
,
...
...
@@ -67,15 +83,23 @@ public class TaskResource
if
(
query
!=
null
)
{
fullPath
+=
query
;
}
Map
<
String
,
String
>
headers
=
extractProxiedHeaders
(
containerRequestContext
.
getHeaders
());
//todo: inline
TaskRequestContext
taskRequestContext
=
new
TaskRequestContext
()
.
withHttpMethod
(
"POST"
)
.
withUser
(
user
)
.
withPath
(
fullPath
)
;
.
withPath
(
fullPath
)
.
withHeaders
(
headers
);
TaskResponse
taskResponse
=
getTaskResponse
(
taskLevel
,
taskRequestContext
);
//todo: headers
return
Response
.
ok
().
entity
(
taskResponse
.
getText
()).
build
();
Response
.
ResponseBuilder
responseBuilder
=
Response
.
ok
()
.
entity
(
taskResponse
.
getText
());
taskResponse
.
getHeaders
().
entrySet
()
.
stream
()
.
forEach
(
headerEntry
->
responseBuilder
.
header
(
headerEntry
.
getKey
(),
headerEntry
.
getValue
()));
return
responseBuilder
.
build
();
}
@Path
(
"{task_level}/{path: .*}"
)
...
...
@@ -92,13 +116,25 @@ public class TaskResource
}
String
body
=
StreamUtils
.
readStream
(
containerRequestContext
.
getEntityStream
());
//todo: TaskContextFrom
Map
<
String
,
String
>
headers
=
extractProxiedHeaders
(
containerRequestContext
.
getHeaders
());
//todo: inline
TaskRequestContext
taskRequestContext
=
new
TaskRequestContext
()
.
withHttpMethod
(
"POST"
)
.
withUser
(
user
)
.
withPath
(
fullPath
)
.
withBody
(
body
);
.
withBody
(
body
)
.
withHeaders
(
headers
);
TaskResponse
taskResponse
=
getTaskResponse
(
taskLevel
,
taskRequestContext
);
//todo: hedaers
return
Response
.
ok
().
entity
(
taskResponse
.
getText
()).
build
();
Response
.
ResponseBuilder
responseBuilder
=
Response
.
ok
()
.
entity
(
taskResponse
.
getText
());
taskResponse
.
getHeaders
().
entrySet
()
.
stream
()
.
forEach
(
headerEntry
->
responseBuilder
.
header
(
headerEntry
.
getKey
(),
headerEntry
.
getValue
()));
return
responseBuilder
.
build
();
}
}
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