use of org.esupportail.papercut.config.EsupPapercutContext in project esup-papercut by EsupPortail.
the class AnonymizeService method anonymizeOldTransactions.
@Scheduled(fixedDelay = 3600000)
public void anonymizeOldTransactions() {
Collection<EsupPapercutContext> availableContexts = esupPapercutConfig.getContexts().values();
for (EsupPapercutContext availableContext : availableContexts) {
if (availableContext.getAnonymization().isEnabled()) {
log.debug("anonymizeOldTransactions called for context : " + availableContext);
List<PayPapercutTransactionLog> transactionLogs = payPapercutTransactionLogRepository.findAllByTransactionDateBeforeAndUidIsNotLike(Date.from(Instant.now().minus(Duration.ofDays(availableContext.getAnonymization().getOldDaysTransactionsLogs()))), "anonymized");
for (PayPapercutTransactionLog transactionLog : transactionLogs) {
anonymizeOneService.anonymize(transactionLog.getId());
}
if (transactionLogs.size() > 0) {
log.info(transactionLogs.size() + " old transactionLogs anonymized for context : " + availableContext);
}
}
}
}
use of org.esupportail.papercut.config.EsupPapercutContext in project esup-papercut by EsupPortail.
the class ContextUserDetailsService method loadUserDetails.
@Override
protected UserDetails loadUserDetails(Assertion assertion) {
Map<String, Set<GrantedAuthority>> contextAuthorities = new HashMap<String, Set<GrantedAuthority>>();
Map<String, String> contextUids = new HashMap<String, String>();
Map<String, String> contextEmails = new HashMap<String, String>();
List<String> availableContexts = new ArrayList<String>();
for (String contextKey : config.getContexts().keySet()) {
EsupPapercutContext context = config.getContext(contextKey);
Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
for (String adminRuleKey : context.getEsupPapercutCasAttributeRuleAdmin().keySet()) {
for (String attributeValue : getAttrValuesAsList(assertion.getPrincipal().getAttributes().get(adminRuleKey))) {
String adminRuleRegex = context.getEsupPapercutCasAttributeRuleAdmin().get(adminRuleKey);
if (attributeValue.matches(adminRuleRegex)) {
authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
break;
}
}
}
for (String managerRuleKey : context.getEsupPapercutCasAttributeRuleManager().keySet()) {
for (String attributeValue : getAttrValuesAsList(assertion.getPrincipal().getAttributes().get(managerRuleKey))) {
String managerRuleRegex = context.getEsupPapercutCasAttributeRuleManager().get(managerRuleKey);
if (attributeValue.matches(managerRuleRegex)) {
authorities.add(new SimpleGrantedAuthority("ROLE_MANAGER"));
break;
}
}
}
for (String userRuleKey : context.getEsupPapercutCasAttributeRuleUser().keySet()) {
for (String attributeValue : getAttrValuesAsList(assertion.getPrincipal().getAttributes().get(userRuleKey))) {
String userRuleRegex = context.getEsupPapercutCasAttributeRuleUser().get(userRuleKey);
if (attributeValue.matches(userRuleRegex)) {
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
break;
}
}
}
if (!authorities.isEmpty()) {
availableContexts.add(contextKey);
}
contextAuthorities.put(contextKey, authorities);
if (context.getPapercutUserUidAttr() != null && !context.getPapercutUserUidAttr().isEmpty() && assertion.getPrincipal().getAttributes().get(context.getPapercutUserUidAttr()) != null) {
contextUids.put(contextKey, (String) assertion.getPrincipal().getAttributes().get(context.getPapercutUserUidAttr()));
}
if (context.getUserEmail() != null && !context.getUserEmail().isEmpty() && assertion.getPrincipal().getAttributes().get(context.getUserEmail()) != null) {
contextEmails.put(contextKey, (String) assertion.getPrincipal().getAttributes().get(context.getUserEmail()));
}
}
ContextUserDetails contextUserDetails = new ContextUserDetails(assertion.getPrincipal().getName(), contextAuthorities, contextUids, contextEmails, availableContexts);
return contextUserDetails;
}
Aggregations