
org.jresearch.commons.flexess.aop.AutoUserAspect Maven / Gradle / Ivy
package org.jresearch.commons.flexess.aop;
import java.text.MessageFormat;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.jresearch.commons.base.manager.api.IUserManager;
import org.jresearch.commons.base.manager.api.obj.IUser;
import org.jresearch.flexess.client.IAuthorizationManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
@Aspect
public class AutoUserAspect {
@Autowired
private IUserManager userManager;
@Autowired
private IAuthorizationManager authorizationManager;
@Before("execution(public * *(..)) && @annotation(context)")
public void updateUserContext(Runas context) {
String name = context.userName();
Assert.notNull(name);
IUser user = userManager.findUser(name);
if (user != null) {
authorizationManager.initUserContext(user.getId().toString());
} else {
throw new IllegalStateException(MessageFormat.format("Unable to find the user for the context {0} ", name)); //$NON-NLS-1$
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy