@Test public void create() throws IOException { RoleGrantedAuthority applicationReaderRoleAuthority = new RoleGrantedAuthority(GrantedAuthorityTarget.APPLICATION, "reader"); RoleGrantedAuthority projectAdminRoleAuthority = new RoleGrantedAuthority(new GrantedAuthorityTarget("project", Type.PROJECT), "admin"); when(userStore.getUserAuthorities(UserStore.ANONYMOUS_USER_LOGIN_NAME)) .thenReturn(Lists.newArrayList(applicationReaderRoleAuthority, projectAdminRoleAuthority)); PermissionGrantedAuthority applicationViewAuthority = new PermissionGrantedAuthority(applicationReaderRoleAuthority.getTarget(), Permission.VIEW); PermissionGrantedAuthority projectAdminAuthority = new PermissionGrantedAuthority(projectAdminRoleAuthority.getTarget(), Permission.ADMIN); when(userStore.toPermissionGrantedAuthorities(applicationReaderRoleAuthority)) .thenReturn(Collections.singleton(applicationViewAuthority)); when(userStore.toPermissionGrantedAuthorities(projectAdminRoleAuthority)) .thenReturn(Collections.singleton(projectAdminAuthority)); String key = "key"; AbstractAuthenticationToken authentication = factory.create(key); assertEquals(key.hashCode(), ((AnonymousAuthenticationToken) authentication).getKeyHash()); assertSame(UserStore.ANONYMOUS_USER_LOGIN_NAME, authentication.getPrincipal()); assertTrue(authentication.getAuthorities().contains(applicationViewAuthority)); assertTrue(authentication.getAuthorities().contains(projectAdminAuthority)); }
public AnonymousAuthenticationToken create(String key) throws IOException { List<RoleGrantedAuthority> userAuthorities = userStore.getUserAuthorities(UserStore.ANONYMOUS_USER_LOGIN_NAME); Set<GrantedAuthority> authorities = Sets.newHashSet(); for (RoleGrantedAuthority rga : userAuthorities) { authorities.addAll(userStore.toPermissionGrantedAuthorities(rga)); } authorities.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS")); return new AnonymousAuthenticationToken(key, UserStore.ANONYMOUS_USER_LOGIN_NAME, authorities); }
DocumentrAnonymousAuthenticationFactory { public AnonymousAuthenticationToken create(String key) throws IOException { List<RoleGrantedAuthority> userAuthorities = userStore.getUserAuthorities(UserStore.ANONYMOUS_USER_LOGIN_NAME); Set<GrantedAuthority> authorities = Sets.newHashSet(); for (RoleGrantedAuthority rga : userAuthorities) { authorities.addAll(userStore.toPermissionGrantedAuthorities(rga)); } authorities.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS")); return new AnonymousAuthenticationToken(key, UserStore.ANONYMOUS_USER_LOGIN_NAME, authorities); } }
DocumentrAnonymousAuthenticationFactory { public AnonymousAuthenticationToken create(String key) throws IOException { List<RoleGrantedAuthority> userAuthorities = userStore.getUserAuthorities(UserStore.ANONYMOUS_USER_LOGIN_NAME); Set<GrantedAuthority> authorities = Sets.newHashSet(); for (RoleGrantedAuthority rga : userAuthorities) { authorities.addAll(userStore.toPermissionGrantedAuthorities(rga)); } authorities.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS")); return new AnonymousAuthenticationToken(key, UserStore.ANONYMOUS_USER_LOGIN_NAME, authorities); }  }
DocumentrAnonymousAuthenticationFactory { public AnonymousAuthenticationToken create(String key) throws IOException { List<RoleGrantedAuthority> userAuthorities = userStore.getUserAuthorities(UserStore.ANONYMOUS_USER_LOGIN_NAME); Set<GrantedAuthority> authorities = Sets.newHashSet(); for (RoleGrantedAuthority rga : userAuthorities) { authorities.addAll(userStore.toPermissionGrantedAuthorities(rga)); } authorities.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS")); return new AnonymousAuthenticationToken(key, UserStore.ANONYMOUS_USER_LOGIN_NAME, authorities); }  AnonymousAuthenticationToken create(String key); }
DocumentrAnonymousAuthenticationFactory { public AnonymousAuthenticationToken create(String key) throws IOException { List<RoleGrantedAuthority> userAuthorities = userStore.getUserAuthorities(UserStore.ANONYMOUS_USER_LOGIN_NAME); Set<GrantedAuthority> authorities = Sets.newHashSet(); for (RoleGrantedAuthority rga : userAuthorities) { authorities.addAll(userStore.toPermissionGrantedAuthorities(rga)); } authorities.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS")); return new AnonymousAuthenticationToken(key, UserStore.ANONYMOUS_USER_LOGIN_NAME, authorities); }  AnonymousAuthenticationToken create(String key);  }