Search in sources :

Example 11 with AfterReturning

use of org.aspectj.lang.annotation.AfterReturning in project entando-core by entando.

the class UserProfileManager method updateProfile.

@AfterReturning(pointcut = "execution(* com.agiletec.aps.system.services.user.IUserManager.updateUser(..)) && args(user,..)")
@CacheEvict(value = ICacheInfoManager.DEFAULT_CACHE_NAME, key = "'UserProfile_'.concat(#user.username)")
public void updateProfile(Object user) {
    if (user != null) {
        UserDetails userDetails = (UserDetails) user;
        Object profile = userDetails.getProfile();
        if (null != profile) {
            try {
                this.updateProfile(userDetails.getUsername(), (IUserProfile) profile);
            } catch (Throwable t) {
                logger.error("Error updating profile to user {}", userDetails.getUsername(), t);
            }
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) CacheEvict(org.springframework.cache.annotation.CacheEvict) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 12 with AfterReturning

use of org.aspectj.lang.annotation.AfterReturning in project profile by craftercms.

the class RefreshCurrentAuthenticationOnProfileUpdateAspect method refreshCurrentAuthentication.

@AfterReturning(value = "execution(* org.craftercms.profile.api.services.ProfileService.updateProfile(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.verifyProfile(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.enableProfile(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.disableProfile(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.addRoles(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.removeRoles(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.updateAttributes(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.removeAttributes(..)) || " + "execution(* org.craftercms.profile.api.services.ProfileService.changePassword(..))", returning = "updatedProfile")
public void refreshCurrentAuthentication(Profile updatedProfile) {
    Authentication auth = SecurityUtils.getCurrentAuthentication();
    if (auth != null) {
        Profile profile = auth.getProfile();
        if (profile.equals(updatedProfile)) {
            String ticket = auth.getTicket();
            auth = new DefaultAuthentication(ticket, updatedProfile);
            // Put updated authentication in cache
            authenticationCache.putAuthentication(auth);
            // Update current authentication object
            SecurityUtils.setCurrentAuthentication(auth);
        }
    }
}
Also used : DefaultAuthentication(org.craftercms.security.authentication.impl.DefaultAuthentication) Authentication(org.craftercms.security.authentication.Authentication) DefaultAuthentication(org.craftercms.security.authentication.impl.DefaultAuthentication) Profile(org.craftercms.profile.api.Profile) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 13 with AfterReturning

use of org.aspectj.lang.annotation.AfterReturning in project paascloud-master by paascloud.

the class BindingResultAop method doAfter.

/**
 * Do after.
 *
 * @param joinPoint the join point
 */
@AfterReturning(pointcut = "validateAnnotation()")
public void doAfter(final JoinPoint joinPoint) {
    String methodName = joinPoint.getSignature().getName();
    Object target = joinPoint.getTarget();
    // 得到拦截的方法
    Method method = getMethodByClassAndName(target.getClass(), methodName);
    Object[] objects = joinPoint.getArgs();
    // 方法的参数
    assert method != null;
    ValidateAnnotation annotation = (ValidateAnnotation) getAnnotationByMethod(method, ValidateAnnotation.class);
    if (annotation != null) {
        BindingResult bindingResult = null;
        for (Object arg : objects) {
            if (arg instanceof BindingResult) {
                bindingResult = (BindingResult) arg;
            }
        }
        if (bindingResult != null && bindingResult.hasErrors()) {
            String errorInfo = bindingResult.getFieldError().getDefaultMessage();
            throw new IllegalArgumentException(errorInfo);
        }
    }
}
Also used : BindingResult(org.springframework.validation.BindingResult) Method(java.lang.reflect.Method) ValidateAnnotation(com.paascloud.core.annotation.ValidateAnnotation) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 14 with AfterReturning

use of org.aspectj.lang.annotation.AfterReturning in project entando-core by entando.

the class UserProfileManagerAspect method updateProfile.

@AfterReturning(pointcut = "execution(* com.agiletec.aps.system.services.user.IUserManager.updateUser(..)) && args(user,..)")
public void updateProfile(Object user) {
    if (user != null) {
        UserDetails userDetails = (UserDetails) user;
        Object profile = userDetails.getProfile();
        if (null != profile) {
            try {
                this.getUserProfileManager().updateProfile(userDetails.getUsername(), (IUserProfile) profile);
            } catch (Throwable t) {
                logger.error("Error updating profile to user {}", userDetails.getUsername(), t);
            }
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 15 with AfterReturning

use of org.aspectj.lang.annotation.AfterReturning in project entando-core by entando.

the class UserProfileManagerAspect method addProfile.

@AfterReturning(pointcut = "execution(* com.agiletec.aps.system.services.user.IUserManager.addUser(..)) && args(user,..)")
public void addProfile(Object user) {
    if (user != null) {
        UserDetails userDetails = (UserDetails) user;
        Object profile = userDetails.getProfile();
        if (null != profile) {
            try {
                this.getUserProfileManager().addProfile(userDetails.getUsername(), (IUserProfile) profile);
            } catch (Throwable t) {
                logger.error("Error adding profile on user {}", userDetails.getUsername(), t);
            }
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Aggregations

AfterReturning (org.aspectj.lang.annotation.AfterReturning)16 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 AbstractUser (com.agiletec.aps.system.services.user.AbstractUser)2 User (com.topcom.cms.domain.User)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JoinPoint (org.aspectj.lang.JoinPoint)2 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)2 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)2 ValidateAnnotation (com.paascloud.core.annotation.ValidateAnnotation)1 BaseEntityModel (com.topcom.cms.base.model.BaseEntityModel)1 LoginLog (com.topcom.cms.domain.LoginLog)1 OperationLog (com.topcom.cms.domain.OperationLog)1 OperationRecord (com.weibo.model.OperationRecord)1 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 HashSet (java.util.HashSet)1 AfterThrowing (org.aspectj.lang.annotation.AfterThrowing)1 Profile (org.craftercms.profile.api.Profile)1 Authentication (org.craftercms.security.authentication.Authentication)1 DefaultAuthentication (org.craftercms.security.authentication.impl.DefaultAuthentication)1