List of usage examples for org.springframework.security.authentication AnonymousAuthenticationToken AnonymousAuthenticationToken
private AnonymousAuthenticationToken(Integer keyHash, Object principal, Collection<? extends GrantedAuthority> authorities)
From source file:com.github.persapiens.jsfboot.security.AuthenticationFactory.java
public static Authentication anonymous(String... authorities) { return new AnonymousAuthenticationToken("anonymous", "anonymous", grantedAuthorities(authorities)); }
From source file:com.netflix.spinnaker.fiat.shared.FiatAuthenticationFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Authentication auth = AuthenticatedRequest.getSpinnakerUser() .map(username -> (Authentication) new PreAuthenticatedAuthenticationToken(username, null, new ArrayList<>())) .orElseGet(() -> new AnonymousAuthenticationToken("anonymous", "anonymous", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"))); val ctx = SecurityContextHolder.createEmptyContext(); ctx.setAuthentication(auth);//from www. j a va2 s.co m SecurityContextHolder.setContext(ctx); log.debug("Set SecurityContext to user: {}", auth.getPrincipal().toString()); chain.doFilter(request, response); }
From source file:org.cloudfoundry.identity.uaa.oauth.token.TokenKeyEndpointTests.java
@Test(expected = AccessDeniedException.class) public void sharedSecretCannotBeAnonymouslyRetrievedFromTokenKeyEndpoint() throws Exception { signerProvider.setVerifierKey("someKey"); assertEquals("{alg=HMACSHA256, value=someKey}", tokenEnhancer.getKey(new AnonymousAuthenticationToken("anon", "anonymousUser", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"))).toString()); }
From source file:com.devicehive.websockets.WebSocketAuthenticationManager.java
public HiveAuthentication authenticateAnonymous(HiveAuthentication.HiveAuthDetails details) { AnonymousAuthenticationToken authenticationToken = new AnonymousAuthenticationToken( UUID.randomUUID().toString(), "anonymousUser", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS")); HiveAuthentication authentication = (HiveAuthentication) authenticationManager .authenticate(authenticationToken); authentication.setDetails(details);// w w w .jav a 2 s. c o m return authentication; }
From source file:demo.oauth.server.spring.SpringOAuthAuthenticationFilter.java
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<GrantedAuthority>(); if (authorities != null) { for (String authority : authorities) { grantedAuthorities.add(new GrantedAuthorityImpl(authority)); }//from w ww . ja v a 2s .c o m Authentication auth = new AnonymousAuthenticationToken(UUID.randomUUID().toString(), req.getUserPrincipal(), grantedAuthorities); SecurityContextHolder.getContext().setAuthentication(auth); } chain.doFilter(req, resp); }
From source file:com.datapine.service.impl.ItemServiceImplTest.java
/** * Before tests.// ww w. ja v a 2s .c o m */ @Before public final void before() { SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken("key", "test user", Collections.singleton(new SimpleGrantedAuthority("ROLE_USER")))); }
From source file:de.randi2.aspects.RightAndRolesAspects.java
/** * This around advice grant the rights for an new domain object and register * a new user with his special rights. It matches all executions of save * methods in the de.randi2.dao package. * /*from ww w . ja va 2 s. c o m*/ * @param pjp * the proceeding join point * @throws Throwable */ @Around("execution(public void de.randi2.dao.*.create*(de.randi2.model.AbstractDomainObject))") @Transactional(propagation = Propagation.REQUIRED) public void afterSaveNewDomainObject(ProceedingJoinPoint pjp) throws Throwable { pjp.proceed(); for (Object o : pjp.getArgs()) { // special case for self registration if (SecurityContextHolder.getContext().getAuthentication().getPrincipal().equals("anonymousUser") && o instanceof Login) { SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken( "anonymousUser", o, new ArrayList<GrantedAuthority>(((Login) o).getAuthorities()))); } Login login = (Login) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); //extra method for login objects is necessary, because of site - login relationship if (!(o instanceof Login)) { logger.debug("Register Object (" + o.getClass().getSimpleName() + " id=" + ((AbstractDomainObject) o).getId() + ")"); roleAndRights.grantRights(((AbstractDomainObject) o), trialSiteDao.get(login.getPerson())); } } }
From source file:com.vdenotaris.spring.boot.security.saml.web.CommonTestSupport.java
public MockHttpSession mockAnonymousHttpSession() { MockHttpSession mockSession = new MockHttpSession(); SecurityContext mockSecurityContext = mock(SecurityContext.class); AnonymousAuthenticationToken principal = new AnonymousAuthenticationToken(ANONYMOUS_USER_KEY, ANONYMOUS_USER_PRINCIPAL, AUTHORITIES); when(mockSecurityContext.getAuthentication()).thenReturn(principal); SecurityContextHolder.setContext(mockSecurityContext); mockSession.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, mockSecurityContext);//from w w w. j a va 2 s.c o m return mockSession; }
From source file:nl.ctrlaltdev.harbinger.evidence.EvidenceCollectorTest.java
@Test public void shouldEnhanceWithUser() { SecurityContextHolder.setContext(new SecurityContextImpl()); SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken("key", "user", Collections.singletonList(new SimpleGrantedAuthority("x")))); evidence = collector.enhanceAndStore(evidence); assertEquals("user", evidence.getUser()); }
From source file:com.trenako.web.security.SpringSecurityContextTests.java
private Authentication anonymousAuthToken() { return new AnonymousAuthenticationToken("123456", "anonymousUser", authorities("ROLE_ANONYMOUS")); }