-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luca Bassi
committed
Oct 9, 2024
1 parent
577ec80
commit 63498c9
Showing
30 changed files
with
568 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/java/org/italiangrid/storm/webdav/server/servlet/SciTagFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.italiangrid.storm.webdav.server.servlet; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.italiangrid.storm.webdav.tpc.SciTag; | ||
import org.italiangrid.storm.webdav.tpc.TransferConstants; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class SciTagFilter implements Filter { | ||
|
||
public static final Logger logger = LoggerFactory.getLogger(SciTagFilter.class); | ||
|
||
@Autowired | ||
public SciTagFilter() {} | ||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
logger.debug("Initializing SciTag filter."); | ||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
SciTag scitag = null; | ||
HttpServletRequest req = (HttpServletRequest) request; | ||
if (req.getHeader(TransferConstants.SCITAG_HEADER) != null) { | ||
Optional<String> source = Optional.ofNullable(req.getHeader(TransferConstants.SOURCE_HEADER)); | ||
boolean remoteAddressIsSource = | ||
req.getMethod().equals("PUT") || (req.getMethod().equals("COPY") && source.isPresent()); | ||
// state prot src_ip src_port dst_ip dst_port exp act | ||
// If the active party receives an HTTP-TPC COPY request with a SciTag request header with | ||
// a valid value then the server SHOULD mark the resulting network traffic with the | ||
// experiment ID and activity ID encoded in the value. | ||
int scitagValue = Integer.parseInt(req.getHeader(TransferConstants.SCITAG_HEADER)); | ||
// Valid value is a single positive integer > 64 and <65536 (16bit). Any other value is | ||
// considered invalid. | ||
if (scitagValue > 64 && scitagValue < 65536) { | ||
scitag = new SciTag(scitagValue >> 6, scitagValue & ((1 << 6) - 1), remoteAddressIsSource); | ||
} else { | ||
// If the active party receives an HTTP-TPC COPY request with a SciTag request header | ||
// with an invalid value then the server SHOULD mark the resulting network traffic with | ||
// the 0 as the experiment ID and the activity ID. | ||
scitag = new SciTag(0, 0, remoteAddressIsSource); | ||
} | ||
} | ||
request.setAttribute(SciTag.SCITAG_ATTRIBUTE, scitag); | ||
chain.doFilter(request, response); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
logger.debug("Destroying SciTag filter."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ | |
public class StoRMServlet extends DefaultServlet { | ||
|
||
/** | ||
* | ||
* | ||
*/ | ||
private static final long serialVersionUID = 4204673943980786498L; | ||
|
||
|
@@ -74,6 +74,12 @@ public Resource getResource(String pathInContext) { | |
|
||
} | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
resourceService.doGet(request, response); | ||
Check notice Code scanning / SonarCloud Exceptions should not be thrown from servlet methods Low
Handle the following exceptions that could be thrown by "doGet": ServletException, IOException. See more on SonarCloud
|
||
} | ||
|
||
@Override | ||
protected void doHead(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/org/italiangrid/storm/webdav/tpc/SciTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.italiangrid.storm.webdav.tpc; | ||
|
||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SciTag { | ||
|
||
public static final Logger LOG = LoggerFactory.getLogger(SciTag.class); | ||
public static final String SCITAG_ATTRIBUTE = "scitag"; | ||
|
||
private static final String FLOWD_PIPE_NAME = "/var/run/flowd"; | ||
private final boolean remoteAddressIsSource; | ||
private final int experimentId; | ||
private final int activityId; | ||
private String sourceAddress; | ||
private int sourcePort; | ||
private String destinationAddress; | ||
private int destinationPort; | ||
|
||
public SciTag(int experimentId, int activityId, boolean remoteAddressIsSource) { | ||
this.experimentId = experimentId; | ||
this.activityId = activityId; | ||
this.remoteAddressIsSource = remoteAddressIsSource; | ||
} | ||
|
||
public int experimentId() { | ||
return experimentId; | ||
} | ||
|
||
public int activityId() { | ||
return activityId; | ||
} | ||
|
||
private String flowdEntry() { | ||
return " tcp " + sourceAddress + " " + sourcePort + " " + destinationAddress + " " | ||
+ destinationPort + " " + this.experimentId() + " " + this.activityId() + "\n"; | ||
} | ||
|
||
public void writeStart(String localAddress, int localPort, String remoteAddress, int remotePort) { | ||
if (remoteAddressIsSource) { | ||
this.sourceAddress = remoteAddress; | ||
this.sourcePort = remotePort; | ||
this.destinationAddress = localAddress; | ||
this.destinationPort = localPort; | ||
} else { | ||
this.sourceAddress = localAddress; | ||
this.sourcePort = localPort; | ||
this.destinationAddress = remoteAddress; | ||
this.destinationPort = remotePort; | ||
} | ||
try (RandomAccessFile flowdPipe = new RandomAccessFile(FLOWD_PIPE_NAME, "rw")) { | ||
flowdPipe.writeBytes("start" + this.flowdEntry()); | ||
} catch (IOException e) { | ||
LOG.warn(e.getMessage(), e); | ||
} | ||
} | ||
|
||
public void writeEnd() { | ||
try (RandomAccessFile flowdPipe = new RandomAccessFile(FLOWD_PIPE_NAME, "rw")) { | ||
flowdPipe.writeBytes("end" + this.flowdEntry()); | ||
} catch (IOException e) { | ||
LOG.warn(e.getMessage(), e); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.