- private AuthenticationManager authenticationManager;
- private String systemKey = KernelConstants.DEFAULT_SECURITY_KEY;
-
- protected void logInAsAnonymous() {
- // TODO Better deal with anonymous authentication
- try {
- List<SimpleGrantedAuthority> anonAuthorities = Collections
- .singletonList(new SimpleGrantedAuthority(
- KernelConstants.ANONYMOUS_USER));
- UserDetails anonUser = new User("anonymous", "", true, true, true,
- true, anonAuthorities);
- AnonymousAuthenticationToken anonToken = new AnonymousAuthenticationToken(
- systemKey, anonUser, anonAuthorities);
- Authentication authentication = authenticationManager
- .authenticate(anonToken);
- SecurityContextHolder.getContext()
- .setAuthentication(authentication);
- } catch (Exception e) {
- throw new CmsException("Cannot authenticate", e);
- }
- }