List of usage examples for org.springframework.security.authentication TestingAuthenticationToken TestingAuthenticationToken
public TestingAuthenticationToken(Object principal, Object credentials)
From source file:be.dnsbelgium.rate.spring.security.LeakyBucketVoterTest.java
@Before public void setup() { SecurityContext context = new SecurityContextImpl(); context.setAuthentication(new TestingAuthenticationToken(USERNAME, null)); SecurityContextHolder.setContext(context); keyFactory = new UsernameLeakyBucketKeyFactory(); }
From source file:com.github.lothar.security.acl.grant.GrantEvaluatorTest.java
@Before public void init() { authentication = new TestingAuthenticationToken("fake principal", "fake credentials"); }
From source file:at.ac.univie.isc.asio.security.AuthToolsTest.java
@Test public void should_yield_undefined_if_unexpected_details_type_found() throws Exception { final TestingAuthenticationToken authentication = new TestingAuthenticationToken("test", "password"); authentication.setDetails("no delegated credentials"); context.setAuthentication(authentication); assertThat(AuthTools.findIdentity(context), equalTo(Identity.undefined())); }
From source file:org.hobsoft.contacts.server.controller.PageControllerAdviceTest.java
@Test public void getUserWithAuthenticationReturnsUser() { User user = newUser();//from www . ja v a 2 s.c o m Principal principal = new TestingAuthenticationToken(user, null); User actual = advice.getUser(principal); assertThat(actual, is(user)); }
From source file:at.ac.univie.isc.asio.security.RoleUserServiceTest.java
@Theory public void should_yield_set_username_to_role_name(final Role role) { final TestingAuthenticationToken token = new TestingAuthenticationToken(role.name(), "N/A"); final UserDetails user = subject.loadUserDetails(token); assertThat(user.getUsername(), equalTo(role.name())); }
From source file:at.ac.univie.isc.asio.security.WhoamiResourceTest.java
@Test public void should_include_identity_if_present() throws Exception { final TestingAuthenticationToken auth = new TestingAuthenticationToken("name", "password"); auth.setDetails(new DelegatedCredentialsDetails(Identity.from("test-login", "test-secret"))); when(security.getAuthentication()).thenReturn(auth); final AuthInfo response = subject.getAuthInfo(); assertThat(response.getName(), equalTo("test-login")); assertThat(response.getSecret(), equalTo("test-secret")); }
From source file:at.ac.univie.isc.asio.security.HttpMethodRestrictionFilterTest.java
@Test public void should_ignore_non__GET__request() throws Exception { final TestingAuthenticationToken token = new TestingAuthenticationToken("user", "secret"); setAuthentication(token);//from w w w . j a va2 s . c om request.setMethod(HttpMethod.POST.name()); subject.doFilter(request, response, chain); assertThat(getAuthentication(), Matchers.<Authentication>sameInstance(token)); }
From source file:nl.ctrlaltdev.harbinger.whitelist.WhiteListTest.java
@Test public void shouldWhiteListUser() { Evidence ev = new Evidence(new Evidence(request), new TestingAuthenticationToken("user", "")); assertTrue(new UserWhiteList("user").isWhitelisted(ev)); assertFalse(new UserWhiteList("anonymous").isWhitelisted(ev)); }
From source file:fr.keemto.web.config.ConnectionRepositoryConfigTest.java
@Test public void shouldCreateAConnectionRepositoryWithPrincipal() { ConnectionRepository connectionRepository = mock(ConnectionRepository.class); when(usersConnectionRepository.createConnectionRepository("user")).thenReturn(connectionRepository); TestingAuthenticationToken principal = new TestingAuthenticationToken("user", null); SecurityContextHolder.getContext().setAuthentication(principal); ConnectionRepository repo = connectionRepositoryConfig.connectionRepository(); verify(usersConnectionRepository).createConnectionRepository("user"); }
From source file:nl.ctrlaltdev.harbinger.whitelist.WhiteListParserTest.java
@Test public void shouldParseUser() { MockHttpServletRequest request = new MockHttpServletRequest(); Evidence ev = new Evidence(new Evidence(request), new TestingAuthenticationToken("user", "")); assertTrue(parser.parse("user:user").isWhitelisted(ev)); assertFalse(parser.parse("user:nasi").isWhitelisted(ev)); }