-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate web server to sechub server #3648
- Loading branch information
Showing
71 changed files
with
848 additions
and
1,131 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
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
2 changes: 1 addition & 1 deletion
2
...encryption/AES256EncryptionException.java → ...g/security/AES256EncryptionException.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
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
79 changes: 79 additions & 0 deletions
79
...ring/src/main/java/com/mercedesbenz/sechub/spring/security/CookieAccessTokenResolver.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,79 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.spring.security; | ||
|
||
import java.util.Arrays; | ||
import java.util.Base64; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.security.oauth2.server.resource.web.BearerTokenResolver; | ||
|
||
import jakarta.servlet.http.Cookie; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
|
||
/** | ||
* {@code CookieTokenResolver} implements {@link BearerTokenResolver} to provide | ||
* custom Bearer Token resolution. The encrypted access token is read from the | ||
* cookies and decrypted using {@link AES256Encryption}. Note that the access | ||
* token is expected in {@link Base64} encoded format. | ||
* | ||
* @see BearerTokenResolver | ||
* @see AES256Encryption | ||
* | ||
* @author hamidonos | ||
*/ | ||
class CookieAccessTokenResolver implements BearerTokenResolver { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(CookieAccessTokenResolver.class); | ||
private static final String MISSING_ACCESS_TOKEN_VALUE = "missing-access-token"; | ||
private static final Base64.Decoder DECODER = Base64.getDecoder(); | ||
|
||
private final AES256Encryption aes256Encryption; | ||
|
||
CookieAccessTokenResolver(AES256Encryption aes256Encryption) { | ||
this.aes256Encryption = aes256Encryption; | ||
} | ||
|
||
@Override | ||
public String resolve(HttpServletRequest request) { | ||
Cookie[] cookies = request.getCookies(); | ||
|
||
if (cookies == null) { | ||
LOG.debug("No cookies found in the request"); | ||
|
||
/* | ||
* If the access token cookie is not found, we return a constant string to | ||
* indicate that the access token is missing. We do this because we want to pass | ||
* exception handling further down the chain. Spring does not provide a way to | ||
* wrap exceptions around custom BearerTokenResolver classes effectively. This | ||
* is a good practice because it allows us to handle the missing access token in | ||
* a more controlled manner. | ||
*/ | ||
return MISSING_ACCESS_TOKEN_VALUE; | ||
} | ||
|
||
/* @formatter:off */ | ||
String accessToken = Arrays | ||
.stream(cookies) | ||
.filter(cookie -> AbstractSecurityConfiguration.ACCESS_TOKEN.equals(cookie.getName())) | ||
.map(Cookie::getValue) | ||
.findFirst() | ||
.orElse(null); | ||
/* @formatter:on */ | ||
|
||
if (accessToken == null) { | ||
LOG.debug("Request is missing the 'access_token' cookie"); | ||
/* same here */ | ||
return MISSING_ACCESS_TOKEN_VALUE; | ||
} | ||
|
||
try { | ||
byte[] jwtBytes = DECODER.decode(accessToken); | ||
return aes256Encryption.decrypt(jwtBytes); | ||
} catch (Exception e) { | ||
LOG.debug("Failed to decrypt the access token cookie", e); | ||
/* same here */ | ||
return MISSING_ACCESS_TOKEN_VALUE; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...-spring/src/main/java/com/mercedesbenz/sechub/spring/security/LoginClassicProperties.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.spring.security; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = LoginClassicProperties.PREFIX) | ||
public class LoginClassicProperties { | ||
|
||
static final String PREFIX = "sechub.security.login.classic"; | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...ain/java/com/mercedesbenz/sechub/spring/security/LoginClassicPropertiesConfiguration.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,12 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.spring.security; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableConfigurationProperties(LoginClassicProperties.class) | ||
@ConditionalOnProperty(prefix = AbstractSecurityConfiguration.LOGIN_PROPERTIES_PREFIX, name = "enabled", havingValue = "true") | ||
class LoginClassicPropertiesConfiguration { | ||
} |
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.