Search in sources :

Example 1 with AuditSection

use of com.salesmanager.core.model.common.audit.AuditSection in project shopizer by shopizer-ecommerce.

the class PersistableAuditAspect method afterReturning.

@AfterReturning(value = "execution(* populate(..))", returning = "result")
public void afterReturning(JoinPoint joinPoint, Object result) {
    try {
        if (result instanceof Auditable) {
            Auditable entity = (Auditable) result;
            AuditSection audit = entity.getAuditSection();
            if (entity.getAuditSection() == null) {
                audit = new AuditSection();
            }
            audit.setDateModified(new Date());
            Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            if (auth != null) {
                if (auth instanceof UsernamePasswordAuthenticationToken) {
                    // api only is captured
                    com.salesmanager.shop.store.security.user.JWTUser user = (com.salesmanager.shop.store.security.user.JWTUser) auth.getPrincipal();
                    audit.setModifiedBy(user.getUsername());
                }
            }
            // TODO put in log audit log trail
            entity.setAuditSection(audit);
        }
    } catch (Throwable e) {
        LOGGER.error("Error while setting audit values" + e.getMessage());
    }
}
Also used : Auditable(com.salesmanager.core.model.common.audit.Auditable) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Date(java.util.Date) Authentication(org.springframework.security.core.Authentication) AuditSection(com.salesmanager.core.model.common.audit.AuditSection) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 2 with AuditSection

use of com.salesmanager.core.model.common.audit.AuditSection in project shopizer by shopizer-ecommerce.

the class JWTAdminServicesImpl method userDetails.

private UserDetails userDetails(String userName, User user, Collection<GrantedAuthority> authorities) {
    AuditSection section = null;
    section = user.getAuditSection();
    Date lastModified = null;
    return new JWTUser(user.getId(), userName, user.getFirstName(), user.getLastName(), user.getAdminEmail(), user.getAdminPassword(), authorities, true, lastModified);
}
Also used : AuditSection(com.salesmanager.core.model.common.audit.AuditSection) JWTUser(com.salesmanager.shop.store.security.user.JWTUser) Date(java.util.Date)

Example 3 with AuditSection

use of com.salesmanager.core.model.common.audit.AuditSection in project shopizer by shopizer-ecommerce.

the class JWTCustomerServicesImpl method userDetails.

@Override
protected UserDetails userDetails(String userName, Customer customer, Collection<GrantedAuthority> authorities) {
    AuditSection section = null;
    section = customer.getAuditSection();
    Date lastModified = null;
    return new JWTUser(customer.getId(), userName, customer.getBilling().getFirstName(), customer.getBilling().getLastName(), customer.getEmailAddress(), customer.getPassword(), authorities, true, lastModified);
}
Also used : AuditSection(com.salesmanager.core.model.common.audit.AuditSection) JWTUser(com.salesmanager.shop.store.security.user.JWTUser) Date(java.util.Date)

Aggregations

AuditSection (com.salesmanager.core.model.common.audit.AuditSection)3 Date (java.util.Date)3 JWTUser (com.salesmanager.shop.store.security.user.JWTUser)2 Auditable (com.salesmanager.core.model.common.audit.Auditable)1 AfterReturning (org.aspectj.lang.annotation.AfterReturning)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1