Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
VOSpace INAF
vospace-rest
Commits
0b93e662
Commit
0b93e662
authored
Oct 08, 2021
by
Nicola Fulvio Calabria
Browse files
Allowed external http and https targets for LinkNodes
parent
d0823b94
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/it/inaf/oats/vospace/BaseNodeController.java
View file @
0b93e662
...
@@ -19,11 +19,11 @@ public abstract class BaseNodeController {
...
@@ -19,11 +19,11 @@ public abstract class BaseNodeController {
@Autowired
@Autowired
private
HttpServletRequest
servletRequest
;
private
HttpServletRequest
servletRequest
;
@Value
(
"${vospace-authority}"
)
@Value
(
"${vospace-authority}"
)
protected
String
authority
;
protected
String
authority
;
protected
String
getPath
()
{
protected
String
getPath
()
{
String
requestURL
=
servletRequest
.
getRequestURL
().
toString
();
String
requestURL
=
servletRequest
.
getRequestURL
().
toString
();
try
{
try
{
return
NodeUtils
.
getPathFromRequestURLString
(
requestURL
);
return
NodeUtils
.
getPathFromRequestURLString
(
requestURL
);
...
@@ -35,7 +35,7 @@ public abstract class BaseNodeController {
...
@@ -35,7 +35,7 @@ public abstract class BaseNodeController {
protected
String
getParentPath
(
String
path
)
{
protected
String
getParentPath
(
String
path
)
{
return
NodeUtils
.
getParentPath
(
path
);
return
NodeUtils
.
getParentPath
(
path
);
}
}
protected
void
validateAndCheckPayloadURIConsistence
(
Node
node
)
{
protected
void
validateAndCheckPayloadURIConsistence
(
Node
node
)
{
// Get Node path (and validates it too)
// Get Node path (and validates it too)
String
decodedURIPathFromNode
=
URIUtils
.
returnVosPathFromNodeURI
(
node
.
getUri
(),
this
.
authority
);
String
decodedURIPathFromNode
=
URIUtils
.
returnVosPathFromNodeURI
(
node
.
getUri
(),
this
.
authority
);
...
@@ -45,16 +45,27 @@ public abstract class BaseNodeController {
...
@@ -45,16 +45,27 @@ public abstract class BaseNodeController {
if
(!
decodedURIPathFromNode
.
equals
(
this
.
getPath
()))
{
if
(!
decodedURIPathFromNode
.
equals
(
this
.
getPath
()))
{
throw
new
InvalidURIException
(
decodedURIPathFromNode
,
requestPath
);
throw
new
InvalidURIException
(
decodedURIPathFromNode
,
requestPath
);
}
}
}
}
protected
void
validate
Internal
LinkNode
(
LinkNode
linkNode
)
{
protected
void
validateLinkNode
(
LinkNode
linkNode
)
{
String
target
=
linkNode
.
getTarget
();
String
target
=
linkNode
.
getTarget
();
// I validate it here to add context easily
// I validate it here to add context easily
if
(
target
==
null
)
{
if
(
target
==
null
)
{
throw
new
InvalidArgumentException
(
"LinkNode in payload has no target element specified"
);
throw
new
InvalidArgumentException
(
"LinkNode in payload has no target element specified"
);
}
}
URIUtils
.
returnVosPathFromNodeURI
(
linkNode
.
getTarget
(),
authority
);
if
(
URIUtils
.
isURIInternal
(
target
))
{
URIUtils
.
returnVosPathFromNodeURI
(
linkNode
.
getTarget
(),
authority
);
}
else
{
// Let's discuss if we need to combine this validation with
// protocol endpoints management (URIService, ProtocolType)
// Let's start with http and https only for now
if
(!(
target
.
toLowerCase
().
startsWith
(
"http://"
)
||
target
.
toLowerCase
().
startsWith
(
"https://"
)))
{
throw
new
InvalidArgumentException
(
"LinkNode target malformed or unsupported protocol: "
+
target
);
}
}
}
}
}
}
src/main/java/it/inaf/oats/vospace/CreateNodeController.java
View file @
0b93e662
...
@@ -44,7 +44,7 @@ public class CreateNodeController extends BaseNodeController {
...
@@ -44,7 +44,7 @@ public class CreateNodeController extends BaseNodeController {
private
void
validateInputNode
(
Node
node
)
{
private
void
validateInputNode
(
Node
node
)
{
if
(
node
instanceof
LinkNode
)
{
if
(
node
instanceof
LinkNode
)
{
this
.
validate
Internal
LinkNode
((
LinkNode
)
node
);
this
.
validateLinkNode
((
LinkNode
)
node
);
}
}
}
}
...
...
src/main/java/it/inaf/oats/vospace/SetNodeController.java
View file @
0b93e662
...
@@ -73,7 +73,7 @@ public class SetNodeController extends BaseNodeController {
...
@@ -73,7 +73,7 @@ public class SetNodeController extends BaseNodeController {
if
(
node
instanceof
DataNode
)
{
if
(
node
instanceof
DataNode
)
{
checkViews
((
DataNode
)
node
,
(
DataNode
)
toBeModifiedNode
);
checkViews
((
DataNode
)
node
,
(
DataNode
)
toBeModifiedNode
);
}
else
if
(
node
instanceof
LinkNode
)
{
}
else
if
(
node
instanceof
LinkNode
)
{
this
.
validate
Internal
LinkNode
((
LinkNode
)
node
);
this
.
validateLinkNode
((
LinkNode
)
node
);
}
}
//The service SHOULD throw a HTTP 500 status code including an InternalFault fault
//The service SHOULD throw a HTTP 500 status code including an InternalFault fault
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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