argos/dmp-backend/web/src/main/java/eu/eudat/controllers/PrincipalController.java

75 lines
3.1 KiB
Java
Raw Normal View History

2024-02-13 08:53:33 +01:00
package eu.eudat.controllers;
2023-10-11 16:53:12 +02:00
2024-01-09 17:28:04 +01:00
import eu.eudat.audit.AuditableAction;
2024-02-08 10:04:38 +01:00
import eu.eudat.models.Account;
import eu.eudat.models.AccountBuilder;
2023-10-11 16:53:12 +02:00
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
import gr.cite.commons.web.oidc.principal.MyPrincipal;
import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
2024-02-01 16:46:28 +01:00
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
2023-10-11 16:53:12 +02:00
import javax.management.InvalidApplicationException;
2023-10-11 16:53:12 +02:00
@RestController
@RequestMapping(value = { "/api/principal/" })
public class PrincipalController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PrincipalController.class));
private final AuditService auditService;
private final CurrentPrincipalResolver currentPrincipalResolver;
private final AccountBuilder accountBuilder;
@Autowired
public PrincipalController(
CurrentPrincipalResolver currentPrincipalResolver,
AccountBuilder accountBuilder,
AuditService auditService) {
this.currentPrincipalResolver = currentPrincipalResolver;
this.accountBuilder = accountBuilder;
this.auditService = auditService;
}
@RequestMapping(path = "me", method = RequestMethod.GET )
2024-01-09 17:28:04 +01:00
public Account me(FieldSet fieldSet) throws InvalidApplicationException {
2023-10-11 16:53:12 +02:00
logger.debug("me");
if (fieldSet == null || fieldSet.isEmpty()) {
fieldSet = new BaseFieldSet(
Account._isAuthenticated,
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._subject),
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._userId),
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._name),
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._scope),
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._client),
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._issuedAt),
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._notBefore),
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._authenticatedAt),
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._expiresAt),
BaseFieldSet.asIndexer(Account._principal, Account.PrincipalInfo._more),
2023-11-29 16:41:15 +01:00
BaseFieldSet.asIndexer(Account._profile, Account.UserProfileInfo._avatarUrl),
BaseFieldSet.asIndexer(Account._profile, Account.UserProfileInfo._language),
BaseFieldSet.asIndexer(Account._profile, Account.UserProfileInfo._culture),
BaseFieldSet.asIndexer(Account._profile, Account.UserProfileInfo._timezone),
Account._roles,
Account._permissions);
2023-10-11 16:53:12 +02:00
}
MyPrincipal principal = this.currentPrincipalResolver.currentPrincipal();
Account me = this.accountBuilder.build(fieldSet, principal);
2024-01-09 17:28:04 +01:00
this.auditService.track(AuditableAction.Principal_Lookup);
2023-10-11 16:53:12 +02:00
//auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
2024-01-09 17:28:04 +01:00
return me;
2023-10-11 16:53:12 +02:00
}
}