Skip to content

Commit

Permalink
[Gepardec/mega#735] OIDC config for google service account
Browse files Browse the repository at this point in the history
  • Loading branch information
Ollitod committed Sep 23, 2024
1 parent 12f8fce commit 37b5883
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/gepardec/mega/rest/api/MailResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.time.LocalDateTime;

@Path("/mail")
//@Tenant("mega-cron")
@Tenant("mega-cron")
@Tag(name = "MailResource")
@Produces(MediaType.APPLICATION_JSON)
//@SecurityRequirement(name = "mega-cron")
Expand Down Expand Up @@ -67,6 +67,7 @@ public interface MailResource {
@GET
LocalDateTime ping();

@Tenant("google")
@Path("/ping")
@POST
LocalDateTime postPing(@Context HttpHeaders headers);
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/gepardec/mega/rest/impl/MailResourceImpl.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.gepardec.mega.rest.impl;

import com.gepardec.mega.application.exception.UnauthorizedException;
import com.gepardec.mega.notification.mail.ReminderEmailSender;
import com.gepardec.mega.notification.mail.receiver.MailReceiver;
import com.gepardec.mega.rest.api.MailResource;
import jakarta.annotation.security.RolesAllowed;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.jwt.Claim;
import org.eclipse.microprofile.jwt.ClaimValue;
import org.eclipse.microprofile.jwt.Claims;
import org.slf4j.Logger;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -67,10 +70,19 @@ public LocalDateTime ping() {
return LocalDateTime.now();
}

@Inject
@Claim(standard = Claims.email)
ClaimValue<String> email;

@Override
public LocalDateTime postPing(HttpHeaders httpHeaders) {
logger.info("Received POST request");
logger.info("Headers: {}", httpHeaders.getRequestHeaders());
logger.info("Email: {}", email.getValue());

if (!"gepardec-service-mail@mega-260510.iam.gserviceaccount.com".equals(email.getValue())) {
throw new UnauthorizedException("Account not authorized to access this resource.");
}

return LocalDateTime.now();
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ quarkus:
roles:
source: accesstoken
role-claim-path: "resource_access/mega-cron/roles"
google:
auth-server-url: "https://accounts.google.com"
application-type: "service"
token:
issuer: "https://accounts.google.com"

mp:
openapi:
filter: com.gepardec.mega.application.filter.MegaCronSecuritySchemaOASFilter
Expand Down

0 comments on commit 37b5883

Please sign in to comment.