Search in sources :

Example 1 with CoreProperties

use of io.jmix.core.CoreProperties in project jmix by jmix-framework.

the class AnonymousConfigurer method initAnonymous.

protected void initAnonymous(HttpSecurity http) {
    try {
        ApplicationContext applicationContext = http.getSharedObject(ApplicationContext.class);
        CoreProperties coreProperties = applicationContext.getBean(CoreProperties.class);
        UserRepository userRepository = applicationContext.getBean(UserRepository.class);
        http.anonymous(anonymousConfigurer -> {
            anonymousConfigurer.key(coreProperties.getAnonymousAuthenticationTokenKey());
            anonymousConfigurer.principal(userRepository.getAnonymousUser());
            Collection<? extends GrantedAuthority> anonymousAuthorities = userRepository.getAnonymousUser().getAuthorities();
            if (!anonymousAuthorities.isEmpty()) {
                anonymousConfigurer.authorities(new ArrayList<>(userRepository.getAnonymousUser().getAuthorities()));
            }
        });
    } catch (Exception e) {
        throw new RuntimeException("Error while init security", e);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) CoreProperties(io.jmix.core.CoreProperties) UserRepository(io.jmix.core.security.UserRepository)

Aggregations

CoreProperties (io.jmix.core.CoreProperties)1 UserRepository (io.jmix.core.security.UserRepository)1 ApplicationContext (org.springframework.context.ApplicationContext)1