@Test public void shouldReturnAnEmtpySetOfAuthoritiesIfTheAuthenticationIsNotAnOAuth2Authentication() { when(context.getAuthentication()).thenReturn(testAuthentication); SecurityContextHolder.setContext(context); OAuth2AuthorizationContext ctx = new OAuth2AuthorizationContext(); assertThat(ctx.getAuthorities()).hasSize(0); }
public Set<String> getAuthorities() { OAuth2Authentication oauth = oauth2Authentication(); if (oauth == null) { return new HashSet<String>(); } Collection<GrantedAuthority> authorities = oauth.getAuthorities(); return authorities == null ? new HashSet<String>() : authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toSet()); }
OAuth2AuthorizationContext implements AuthorizationContextProvider { public Set<String> getAuthorities() { OAuth2Authentication oauth = oauth2Authentication(); if (oauth == null) { return new HashSet<String>(); } Collection<GrantedAuthority> authorities = oauth.getAuthorities(); return authorities == null ? new HashSet<String>() : authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toSet()); } }
OAuth2AuthorizationContext implements AuthorizationContextProvider { public Set<String> getAuthorities() { OAuth2Authentication oauth = oauth2Authentication(); if (oauth == null) { return new HashSet<String>(); } Collection<GrantedAuthority> authorities = oauth.getAuthorities(); return authorities == null ? new HashSet<String>() : authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toSet()); } OAuth2AuthorizationContext(); }
OAuth2AuthorizationContext implements AuthorizationContextProvider { public Set<String> getAuthorities() { OAuth2Authentication oauth = oauth2Authentication(); if (oauth == null) { return new HashSet<String>(); } Collection<GrantedAuthority> authorities = oauth.getAuthorities(); return authorities == null ? new HashSet<String>() : authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toSet()); } OAuth2AuthorizationContext(); boolean isAuthenticated(); Set<String> getScopes(); Set<String> getAuthorities(); Set<String> getRoles(); String getUsername(); }
OAuth2AuthorizationContext implements AuthorizationContextProvider { public Set<String> getAuthorities() { OAuth2Authentication oauth = oauth2Authentication(); if (oauth == null) { return new HashSet<String>(); } Collection<GrantedAuthority> authorities = oauth.getAuthorities(); return authorities == null ? new HashSet<String>() : authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toSet()); } OAuth2AuthorizationContext(); boolean isAuthenticated(); Set<String> getScopes(); Set<String> getAuthorities(); Set<String> getRoles(); String getUsername();  }