@Test public void configurationAuthentication_ShouldSetAuthenticationToSecurityContext() { AuthenticationUtil.configureAuthentication(ROLE); Authentication currentAuthentication = SecurityContextHolder.getContext().getAuthentication(); assertThat(currentAuthentication.getAuthorities()).hasSize(1); assertThat(currentAuthentication.getAuthorities().iterator().next().getAuthority()).isEqualTo(ROLE); User principal = (User) currentAuthentication.getPrincipal(); assertThat(principal.getAuthorities()).hasSize(1); assertThat(principal.getAuthorities().iterator().next().getAuthority()).isEqualTo(ROLE); }
public static void configureAuthentication(String role) { Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(role); Authentication authentication = new UsernamePasswordAuthenticationToken( USERNAME, role, authorities ); SecurityContextHolder.getContext().setAuthentication(authentication); }
AuthenticationUtil { public static void configureAuthentication(String role) { Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(role); Authentication authentication = new UsernamePasswordAuthenticationToken( USERNAME, role, authorities ); SecurityContextHolder.getContext().setAuthentication(authentication); } }
AuthenticationUtil { public static void configureAuthentication(String role) { Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(role); Authentication authentication = new UsernamePasswordAuthenticationToken( USERNAME, role, authorities ); SecurityContextHolder.getContext().setAuthentication(authentication); } private  AuthenticationUtil(); }
AuthenticationUtil { public static void configureAuthentication(String role) { Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(role); Authentication authentication = new UsernamePasswordAuthenticationToken( USERNAME, role, authorities ); SecurityContextHolder.getContext().setAuthentication(authentication); } private  AuthenticationUtil(); static void clearAuthentication(); static void configureAuthentication(String role); }
AuthenticationUtil { public static void configureAuthentication(String role) { Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(role); Authentication authentication = new UsernamePasswordAuthenticationToken( USERNAME, role, authorities ); SecurityContextHolder.getContext().setAuthentication(authentication); } private  AuthenticationUtil(); static void clearAuthentication(); static void configureAuthentication(String role);  }