Controlling concurrent user access
Concurrent access control can also be feasible in AOP since we can improvise the authentication process through the @Aspect interception. If aspects can communicate with each other through session attributes, we can utilize the existing session of the application to count the number of user accesses per account.
Getting started
Update LoginAuthAspect in order to manage the number of allowable user access privileges an account can utilize.
How to do it...
Without using Spring Security, let us simulate concurrent user control by using AOP and following these steps:
- Create a
@BeanofMaptype that will hold all usernames that are currently logged in to the application. Inject thisMapinSpringContextConfig:
Configuration
@EnableWebMvc
@EnableAspectJAutoProxy
@ComponentScan(basePackages="org.packt.aop.transaction")
public class SpringContextConfig {
@Bean
public Map<String,Integer> authStore(){
return new HashMap<>();
}
} - Update...