List of usage examples for org.springframework.security.authentication TestingAuthenticationToken TestingAuthenticationToken
public TestingAuthenticationToken(Object principal, Object credentials)
From source file:at.ac.univie.isc.asio.security.RoleUserServiceTest.java
@Theory public void should_ignore_casing_on_username(final Role role) throws Exception { final String lowerRoleName = role.name().toLowerCase(Locale.ENGLISH); final TestingAuthenticationToken token = new TestingAuthenticationToken(lowerRoleName, "N/A"); final UserDetails user = subject.loadUserDetails(token); assertThat(user.getUsername(), equalTo(role.name())); }
From source file:io.restassured.module.mockmvc.SecuredControllerTest.java
@Test public void spring_security_authentication_authentication_works() { RestAssuredMockMvc.given().standaloneSetup(new SecuredController()).auth() .authentication(new TestingAuthenticationToken( new User("authorized_user", "password", Collections.<GrantedAuthority>emptyList()), "")) .param("name", "Johan").when().get("/springSecurityGreeting").then().statusCode(200) .body("content", equalTo("Hello, Johan!")); }
From source file:nl.ctrlaltdev.harbinger.whitelist.WhiteListTest.java
@Test public void shouldWhitelistAnd() { request.setRemoteAddr("8.8.8.8"); Evidence ev = new Evidence(new Evidence(request), new TestingAuthenticationToken("user", "")); assertTrue(WhiteListBuilder.create().and().ip("8.8.8.8").user("user").end().build().isWhitelisted(ev)); assertFalse(WhiteListBuilder.create().and().ip("8.8.8.9").user("user").end().build().isWhitelisted(ev)); assertFalse(WhiteListBuilder.create().and().ip("8.8.8.8").user("abuser").end().build().isWhitelisted(ev)); assertFalse(WhiteListBuilder.create().and().ip("8.8.8.9").user("abuser").end().build().isWhitelisted(ev)); }
From source file:com.jayway.restassured.module.mockmvc.SecuredControllerTest.java
@Test public void spring_security_authentication_authentication_works() { given().standaloneSetup(new SecuredController()).auth() .authentication(new TestingAuthenticationToken( new User("authorized_user", "password", Collections.<GrantedAuthority>emptyList()), "")) .param("name", "Johan").when().get("/springSecurityGreeting").then().statusCode(200) .body("content", equalTo("Hello, Johan!")); }
From source file:org.cloudfoundry.identity.uaa.oauth.TokenAdminEndpointsTests.java
@Test public void testListTokensForOAuth2User() throws Exception { Mockito.when(tokenServices.findTokensByUserName("marissa")) .thenReturn(Collections.<OAuth2AccessToken>singleton(new DefaultOAuth2AccessToken("FOO"))); Collection<OAuth2AccessToken> tokens = endpoints.listTokensForUser("marissa", new OAuth2Authentication(authorizationRequest, new TestingAuthenticationToken("marissa", "")), false);/*from w ww. j av a 2 s .c o m*/ assertEquals(1, tokens.size()); assertNotNull(tokens.iterator().next().getAdditionalInformation().get(JwtTokenEnhancer.TOKEN_ID)); }
From source file:nl.ctrlaltdev.harbinger.whitelist.WhiteListParserTest.java
@Test public void shouldParseAnd() { MockHttpServletRequest request = new MockHttpServletRequest(); Evidence ev = new Evidence(new Evidence(request), new TestingAuthenticationToken("user", "")); assertTrue(parser.parse("and(user:user,ip:127.0.0.1)").isWhitelisted(ev)); assertFalse(parser.parse("and(user:nasi,ip:127.0.0.1)").isWhitelisted(ev)); assertFalse(parser.parse("and(user:user,ip:127.0.0.2)").isWhitelisted(ev)); assertFalse(parser.parse("and(user:nasi,ip:127.0.0.2)").isWhitelisted(ev)); }
From source file:at.ac.univie.isc.asio.security.RoleUserServiceTest.java
@Theory public void should_set_password_to__NA(final Role role) { final TestingAuthenticationToken token = new TestingAuthenticationToken(role.name(), "N/A"); final UserDetails user = subject.loadUserDetails(token); assertThat(user.getPassword(), equalTo("N/A")); }
From source file:eu.openanalytics.rsb.component.AuthenticatedResultResourceTestCase.java
@Before public void prepareTest() { testResultPayload = RandomStringUtils.randomAlphanumeric(25 + new RandomDataGenerator().nextInt(0, 25)); when(securityContext.getUserPrincipal()).thenReturn(new TestingAuthenticationToken(TEST_USER_NAME, null)); resultResource = new ResultResource(); resultResource.setResultStore(resultStore); resultResource.setSecurityContext(securityContext); }
From source file:fr.keemto.web.config.ConnectionRepositoryConfigTest.java
@Test public void shouldCreateAnObservableConnectionRepository() { 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(); repo.findAllConnections();//from w w w . jav a2s.c om assertThat(repo, instanceOf(ObservableConnectionRepository.class)); assertThat(((ObservableConnectionRepository) repo).getInterceptor(), equalTo(interceptor)); verify(connectionRepository).findAllConnections(); }
From source file:at.ac.univie.isc.asio.security.RoleUserServiceTest.java
@SuppressWarnings("unchecked") @Theory/*from w w w . ja v a2 s . c om*/ public void should_add_role_to_authorities(final Role role) { final TestingAuthenticationToken token = new TestingAuthenticationToken(role.name(), "N/A"); final UserDetails user = subject.loadUserDetails(token); assertThat((Iterable<GrantedAuthority>) user.getAuthorities(), hasItem(equalTo(role))); }