-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support to disable spring security web filters (#279)
- Loading branch information
Showing
4 changed files
with
77 additions
and
35 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
59 changes: 59 additions & 0 deletions
59
server/src/main/java/org/eclipse/jifa/server/configurer/SecurityCryptoConfigurer.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,59 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
********************************************************************************/ | ||
package org.eclipse.jifa.server.configurer; | ||
|
||
import com.nimbusds.jose.jwk.JWKSet; | ||
import com.nimbusds.jose.jwk.RSAKey; | ||
import com.nimbusds.jose.jwk.source.ImmutableJWKSet; | ||
import org.eclipse.jifa.server.ConfigurationAccessor; | ||
import org.eclipse.jifa.server.service.CipherService; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.security.oauth2.jwt.JwtDecoder; | ||
import org.springframework.security.oauth2.jwt.JwtEncoder; | ||
import org.springframework.security.oauth2.jwt.JwtTimestampValidator; | ||
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder; | ||
import org.springframework.security.oauth2.jwt.NimbusJwtEncoder; | ||
import java.time.Duration; | ||
|
||
import static org.eclipse.jifa.server.enums.Role.MASTER; | ||
import static org.eclipse.jifa.server.enums.Role.STANDALONE_WORKER; | ||
|
||
@Configuration | ||
public class SecurityCryptoConfigurer extends ConfigurationAccessor { | ||
|
||
@Bean | ||
public JwtEncoder jwtEncoder(CipherService cipherService) { | ||
RSAKey jwk = new RSAKey.Builder(cipherService.getPublicKey()).privateKey(cipherService.getPrivateKey()).build(); | ||
return new NimbusJwtEncoder(new ImmutableJWKSet<>(new JWKSet(jwk))); | ||
} | ||
|
||
@Bean | ||
@Primary | ||
public JwtDecoder jwtDecoder(CipherService cipherService) { | ||
NimbusJwtDecoder decoder = NimbusJwtDecoder.withPublicKey(cipherService.getPublicKey()).build(); | ||
|
||
if (getRole() == MASTER || getRole() == STANDALONE_WORKER) { | ||
decoder.setJwtValidator(new JwtTimestampValidator(Duration.ZERO)); | ||
} | ||
return decoder; | ||
} | ||
|
||
@Bean | ||
public PasswordEncoder passwordEncoder() { | ||
return new BCryptPasswordEncoder(); | ||
} | ||
} |
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