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
1667b9c3
Commit
1667b9c3
authored
Apr 05, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
header passing stub
parent
e78511c8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
7 deletions
+12
-7
Task.java
...ava/com/telephoners/krakyournet/ctf/beans/tasks/Task.java
+1
-1
TextTask.java
...com/telephoners/krakyournet/ctf/beans/tasks/TextTask.java
+1
-1
WebTask.java
.../com/telephoners/krakyournet/ctf/beans/tasks/WebTask.java
+6
-4
TaskResource.java
...m/telephoners/krakyournet/ctf/resources/TaskResource.java
+4
-1
No files found.
service/src/main/java/com/telephoners/krakyournet/ctf/beans/tasks/Task.java
View file @
1667b9c3
...
@@ -37,7 +37,7 @@ public abstract class Task
...
@@ -37,7 +37,7 @@ public abstract class Task
{
{
}
}
public
abstract
String
getTextForUser
(
User
user
,
String
path
)
throws
IOException
;
public
abstract
String
getTextForUser
(
User
user
,
String
path
,
String
kynHeaderValue
)
throws
IOException
;
public
String
getName
()
public
String
getName
()
{
{
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/beans/tasks/TextTask.java
View file @
1667b9c3
...
@@ -23,7 +23,7 @@ public class TextTask extends Task
...
@@ -23,7 +23,7 @@ public class TextTask extends Task
{
{
}
}
public
String
getTextForUser
(
User
user
,
String
path
)
public
String
getTextForUser
(
User
user
,
String
path
,
String
kynHeaderValue
)
{
{
return
text
;
return
text
;
}
}
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/beans/tasks/WebTask.java
View file @
1667b9c3
...
@@ -33,11 +33,11 @@ public class WebTask extends Task
...
@@ -33,11 +33,11 @@ public class WebTask extends Task
{
{
}
}
public
String
getTextForUser
(
User
user
,
String
path
)
throws
IOException
public
String
getTextForUser
(
User
user
,
String
path
,
String
kynHeaderValue
)
throws
IOException
{
{
// String url = URL_JOINER.join(getUrl(), path); //todo: rethink
// String url = URL_JOINER.join(getUrl(), path); //todo: rethink
String
url
=
getUrl
()
+
path
;
String
url
=
getUrl
()
+
path
;
return
StreamUtils
.
readStream
(
proxyRequest
(
url
,
user
));
return
StreamUtils
.
readStream
(
proxyRequest
(
url
,
user
,
kynHeaderValue
));
}
}
public
String
getUrl
()
public
String
getUrl
()
...
@@ -50,13 +50,15 @@ public class WebTask extends Task
...
@@ -50,13 +50,15 @@ public class WebTask extends Task
this
.
url
=
url
;
this
.
url
=
url
;
}
}
private
InputStream
proxyRequest
(
String
url
,
User
user
)
throws
IOException
private
InputStream
proxyRequest
(
String
url
,
User
user
,
String
kynHeaderValue
)
throws
IOException
{
{
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
HttpGet
httpget
=
new
HttpGet
(
url
);
HttpGet
httpget
=
new
HttpGet
(
url
);
httpget
.
setHeader
(
"CTF-User"
,
user
.
getName
());
httpget
.
setHeader
(
"CTF-User"
,
user
.
getName
());
//todo: is it necessary?
httpget
.
setHeader
(
"KYN_2016"
,
kynHeaderValue
);
//todo: move to configuration
CloseableHttpResponse
execute
=
httpClient
.
execute
(
httpget
);
CloseableHttpResponse
execute
=
httpClient
.
execute
(
httpget
);
HttpEntity
entity
=
execute
.
getEntity
();
HttpEntity
entity
=
execute
.
getEntity
();
return
entity
.
getContent
();
return
entity
.
getContent
();
//todo: back to user
}
}
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/resources/TaskResource.java
View file @
1667b9c3
...
@@ -20,6 +20,8 @@ import java.io.IOException;
...
@@ -20,6 +20,8 @@ import java.io.IOException;
@Path
(
value
=
"/task"
)
@Path
(
value
=
"/task"
)
public
class
TaskResource
public
class
TaskResource
{
{
private
static
final
String
KYN_HEADER_NAME
=
"KYN_2016"
;
//todo
private
final
TasksRepository
tasksRepository
;
private
final
TasksRepository
tasksRepository
;
@Inject
@Inject
...
@@ -39,10 +41,11 @@ public class TaskResource
...
@@ -39,10 +41,11 @@ public class TaskResource
//todo: refactor, path not necessary in textTasks
//todo: refactor, path not necessary in textTasks
ContainerRequest
context
=
(
ContainerRequest
)
containerRequestContext
;
ContainerRequest
context
=
(
ContainerRequest
)
containerRequestContext
;
String
query
=
context
.
getRequestUri
().
getQuery
();
String
query
=
context
.
getRequestUri
().
getQuery
();
String
kynHeaderValue
=
context
.
getHeaderString
(
KYN_HEADER_NAME
);
String
fullPath
=
path
;
String
fullPath
=
path
;
if
(
query
!=
null
)
{
//todo: refactor
if
(
query
!=
null
)
{
//todo: refactor
fullPath
=
fullPath
+
"?"
+
query
;
fullPath
=
fullPath
+
"?"
+
query
;
}
}
return
Response
.
ok
().
entity
(
task
.
getTextForUser
(
user
,
fullPath
)).
build
();
return
Response
.
ok
().
entity
(
task
.
getTextForUser
(
user
,
fullPath
,
kynHeaderValue
)).
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