Search in sources :

Example 6 with EsupPapercutContext

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);
            }
        }
    }
}
Also used : PayPapercutTransactionLog(org.esupportail.papercut.domain.PayPapercutTransactionLog) EsupPapercutContext(org.esupportail.papercut.config.EsupPapercutContext) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 7 with EsupPapercutContext

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) EsupPapercutContext(org.esupportail.papercut.config.EsupPapercutContext) HashSet(java.util.HashSet)

Aggregations

EsupPapercutContext (org.esupportail.papercut.config.EsupPapercutContext)7 PayPapercutTransactionLog (org.esupportail.papercut.domain.PayPapercutTransactionLog)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JSONSerializer (flexjson.JSONSerializer)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 IzlyPayForm (org.esupportail.papercut.domain.IzlyPayForm)1 PayBoxForm (org.esupportail.papercut.domain.PayBoxForm)1 UserPapercutInfos (org.esupportail.papercut.domain.UserPapercutInfos)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 ServletRequestBindingException (org.springframework.web.bind.ServletRequestBindingException)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1