-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
15 changed files
with
443 additions
and
40 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
40 changes: 40 additions & 0 deletions
40
...-web-server/src/main/java/com/mercedesbenz/sechub/webserver/security/PortAccessGuard.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,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.webserver.security; | ||
|
||
import java.io.IOException; | ||
|
||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* Filter which checks if the request is targeting the allowed port. If not, it | ||
* will return a <code>403 Forbidden</code> response. | ||
* | ||
* @author hamidonos | ||
*/ | ||
class PortAccessGuard extends OncePerRequestFilter { | ||
|
||
private final int allowedPort; | ||
|
||
public PortAccessGuard(int allowedPort) { | ||
this.allowedPort = allowedPort; | ||
} | ||
|
||
@Override | ||
/* @formatter:off */ | ||
protected void doFilterInternal(HttpServletRequest request, | ||
@SuppressWarnings("NullableProblems") HttpServletResponse response, | ||
@SuppressWarnings("NullableProblems") FilterChain filterChain) throws ServletException, IOException { | ||
/* @formatter:on */ | ||
int requestPort = request.getServerPort(); | ||
if (allowedPort != requestPort) { | ||
response.sendError(HttpServletResponse.SC_FORBIDDEN); | ||
return; | ||
} | ||
filterChain.doFilter(request, response); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...er/src/main/java/com/mercedesbenz/sechub/webserver/server/ManagementServerProperties.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,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.webserver.server; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.bind.ConstructorBinding; | ||
|
||
@ConfigurationProperties(prefix = ManagementServerProperties.PREFIX) | ||
public final class ManagementServerProperties { | ||
|
||
static final String PREFIX = "management.server"; | ||
|
||
private final int port; | ||
|
||
@ConstructorBinding | ||
ManagementServerProperties(int port) { | ||
this.port = port; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...b-web-server/src/main/java/com/mercedesbenz/sechub/webserver/server/ServerProperties.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,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.webserver.server; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.bind.ConstructorBinding; | ||
|
||
@ConfigurationProperties(prefix = ServerProperties.PREFIX) | ||
public final class ServerProperties { | ||
|
||
static final String PREFIX = "server"; | ||
|
||
private final int port; | ||
|
||
@ConstructorBinding | ||
ServerProperties(int port) { | ||
this.port = port; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...src/main/java/com/mercedesbenz/sechub/webserver/server/ServerPropertiesConfiguration.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,11 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.webserver.server; | ||
|
||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableConfigurationProperties({ ServerProperties.class, ManagementServerProperties.class }) | ||
public class ServerPropertiesConfiguration { | ||
|
||
} |
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
Oops, something went wrong.