use of org.springframework.security.authentication.AnonymousAuthenticationToken in project ORCID-Source by ORCID.
the class IdentifierApiServiceDelegatorTest method init.
@Before
public void init() {
// setup security context
ArrayList<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
roles.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS"));
Authentication auth = new AnonymousAuthenticationToken("anonymous", "anonymous", roles);
SecurityContextHolder.getContext().setAuthentication(auth);
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project ORCID-Source by ORCID.
the class PublicV2ApiServiceDelegatorTest method before.
@Before
public void before() {
ArrayList<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
roles.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS"));
Authentication auth = new AnonymousAuthenticationToken("anonymous", "anonymous", roles);
SecurityContextHolder.getContext().setAuthentication(auth);
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project cxf by apache.
the class SpringOAuthAuthenticationFilter method doFilter.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
List<String> authorities = (List<String>) request.getAttribute(OAUTH_AUTHORITIES);
List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
if (authorities != null) {
for (String authority : authorities) {
grantedAuthorities.add(new SimpleGrantedAuthority(authority));
}
Authentication auth = new AnonymousAuthenticationToken(UUID.randomUUID().toString(), req.getUserPrincipal(), grantedAuthorities);
SecurityContextHolder.getContext().setAuthentication(auth);
}
chain.doFilter(req, resp);
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project ORCID-Source by ORCID.
the class PublicV3ApiServiceDelegatorTest method before.
@Before
public void before() {
ArrayList<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
roles.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS"));
Authentication auth = new AnonymousAuthenticationToken("anonymous", "anonymous", roles);
SecurityContextHolder.getContext().setAuthentication(auth);
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project jhipster-sample-app-websocket by jhipster.
the class WebsocketConfiguration method defaultHandshakeHandler.
private DefaultHandshakeHandler defaultHandshakeHandler() {
return new DefaultHandshakeHandler() {
@Override
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map<String, Object> attributes) {
Principal principal = request.getPrincipal();
if (principal == null) {
Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.ANONYMOUS));
principal = new AnonymousAuthenticationToken("WebsocketConfiguration", "anonymous", authorities);
}
return principal;
}
};
}
Aggregations