Skip to content

Instantly share code, notes, and snippets.

View baso53's full-sized avatar
🎃

Sebastijan Grabar baso53

🎃
  • Croatia
View GitHub Profile
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.oauth2ResourceServer()
.jwt();
}
@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)
public enum Permission {
READ,
WRITE
}
@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()))
dependencies {
// ...
implementation 'com.google.firebase:firebase-admin:8.1.0'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// ...
}
curl --location --request GET 'http://localhost:8080/app/test' \
--header 'Authorization: Bearer [your JWT token]' \
@RestController
@RequestMapping("/app")
public class AppController {
@GetMapping(path = "/test")
public String test(Principal principal) {
return principal.getName();
}
}
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://www.googleapis.com/service_accounts/v1/jwk/securetoken%40system.gserviceaccount.com
@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest()
.authenticated();
http.oauth2ResourceServer()
@baso53
baso53 / js-question1.js
Last active June 17, 2021 11:46
JS Interview questions
await new Promise(resolve => setTimeout(() => resolve(5), 3000))