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
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) | |
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http.csrf().disable(); | |
http.oauth2ResourceServer() | |
.jwt(); | |
} |
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
@Service | |
@RequiredArgsConstructor | |
public class UserManagementService { | |
private final FirebaseAuth firebaseAuth; | |
public void setUserClaims(String uid, List<Permission> requestedPermissions) throws FirebaseAuthException { | |
List<String> permissions = requestedPermissions | |
.stream() | |
.map(Enum::toString) |
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
public enum Permission { | |
READ, | |
WRITE | |
} |
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
@Configuration | |
public class FirebaseAuthConfig { | |
@Value("classpath:service-account.json") | |
Resource serviceAccount; | |
@Bean | |
FirebaseAuth firebaseAuth() throws IOException { | |
var options = FirebaseOptions.builder() | |
.setCredentials(GoogleCredentials.fromStream(serviceAccount.getInputStream())) |
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
dependencies { | |
// ... | |
implementation 'com.google.firebase:firebase-admin:8.1.0' | |
compileOnly 'org.projectlombok:lombok' | |
annotationProcessor 'org.projectlombok:lombok' | |
// ... | |
} |
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
curl --location --request GET 'http://localhost:8080/app/test' \ | |
--header 'Authorization: Bearer [your JWT token]' \ |
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
@RestController | |
@RequestMapping("/app") | |
public class AppController { | |
@GetMapping(path = "/test") | |
public String test(Principal principal) { | |
return principal.getName(); | |
} | |
} |
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
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://www.googleapis.com/service_accounts/v1/jwk/securetoken%40system.gserviceaccount.com |
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
@Configuration | |
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http.authorizeRequests() | |
.anyRequest() | |
.authenticated(); | |
http.oauth2ResourceServer() |
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
await new Promise(resolve => setTimeout(() => resolve(5), 3000)) |