List of usage examples for org.springframework.security.authentication TestingAuthenticationToken TestingAuthenticationToken
public TestingAuthenticationToken(Object principal, Object credentials)
From source file:nl.ctrlaltdev.harbinger.whitelist.WhiteListTest.java
@Test public void shouldWhitelistOr() { request.setRemoteAddr("8.8.8.8"); Evidence ev = new Evidence(new Evidence(request), new TestingAuthenticationToken("user", "")); assertTrue(WhiteListBuilder.create().or().ip("8.8.8.8").user("user").end().build().isWhitelisted(ev)); assertTrue(WhiteListBuilder.create().or().ip("8.8.8.9").user("user").end().build().isWhitelisted(ev)); assertTrue(WhiteListBuilder.create().or().ip("8.8.8.8").user("abuser").end().build().isWhitelisted(ev)); assertFalse(WhiteListBuilder.create().or().ip("8.8.8.9").user("abuser").end().build().isWhitelisted(ev)); }
From source file:org.cloudfoundry.identity.uaa.oauth.TokenAdminEndpointsTests.java
@Test public void testListTokensForOAuth2UserWithClientId() throws Exception { Mockito.when(tokenServices.findTokensByUserName("marissa")) .thenReturn(Collections.<OAuth2AccessToken>singleton(new DefaultOAuth2AccessToken("FOO"))); Mockito.when(tokenServices.getClientId("FOO")).thenReturn("foo"); Collection<OAuth2AccessToken> tokens = endpoints.listTokensForUser("marissa", new OAuth2Authentication(authorizationRequest, new TestingAuthenticationToken("marissa", "")), false);/*from w ww .ja va 2s . c om*/ assertEquals(1, tokens.size()); assertNotNull(tokens.iterator().next().getAdditionalInformation().get(JwtTokenEnhancer.TOKEN_ID)); }
From source file:nl.surfnet.coin.selfservice.control.BaseControllerTest.java
protected Authentication getAuthentication() { return new TestingAuthenticationToken(coinUser, ""); }
From source file:nl.ctrlaltdev.harbinger.whitelist.WhiteListParserTest.java
@Test public void shouldParseOr() { MockHttpServletRequest request = new MockHttpServletRequest(); Evidence ev = new Evidence(new Evidence(request), new TestingAuthenticationToken("user", "")); assertTrue(parser.parse("or(user:user,ip:127.0.0.1)").isWhitelisted(ev)); assertTrue(parser.parse("or(user:nasi,ip:127.0.0.1)").isWhitelisted(ev)); assertTrue(parser.parse("or(user:user,ip:127.0.0.2)").isWhitelisted(ev)); assertFalse(parser.parse("or(user:nasi,ip:127.0.0.2)").isWhitelisted(ev)); }
From source file:at.ac.univie.isc.asio.security.RoleUserServiceTest.java
@SuppressWarnings("unchecked") @Theory//from ww w . j a va2 s . c o m public void should_add_mapped_authorities(final Role role) { final TestingAuthenticationToken token = new TestingAuthenticationToken(role.name(), "N/A"); final UserDetails user = subject.loadUserDetails(token); final GrantedAuthority[] expected = role.getGrantedAuthorities() .toArray(new GrantedAuthority[role.getGrantedAuthorities().size()]); assertThat((Iterable<GrantedAuthority>) user.getAuthorities(), hasItems(expected)); }
From source file:nl.ctrlaltdev.harbinger.whitelist.WhiteListParserTest.java
@Test public void shouldParseNested() { MockHttpServletRequest request = new MockHttpServletRequest(); Evidence ev = new Evidence(new Evidence(request), new TestingAuthenticationToken("user", "")); DetectionRule rule = new DetectionRule(new String[] { "", "HIGH", "" }); ev = new Evidence(ev, rule, "test", ""); assertTrue(parser.parse("and(or(user:user,ip:127.0.0.1),parameter:test)").isWhitelisted(ev)); assertTrue(parser.parse("and(or(user:nasi,ip:127.0.0.1),parameter:test)").isWhitelisted(ev)); assertTrue(parser.parse("and(or(user:user,ip:127.0.0.2),parameter:test)").isWhitelisted(ev)); assertFalse(parser.parse("and(or(user:nasi,ip:127.0.0.2),parameter:test)").isWhitelisted(ev)); assertFalse(parser.parse("and(or(user:user,ip:127.0.0.1),parameter:yest)").isWhitelisted(ev)); assertFalse(parser.parse("and(or(user:nasi,ip:127.0.0.1),parameter:yest)").isWhitelisted(ev)); assertFalse(parser.parse("and(or(user:user,ip:127.0.0.2),parameter:yest)").isWhitelisted(ev)); assertFalse(parser.parse("and(or(user:nasi,ip:127.0.0.2),parameter:yest)").isWhitelisted(ev)); }
From source file:org.cloudfoundry.identity.uaa.oauth.TokenAdminEndpointsTests.java
@Test public void testListTokensForUser() throws Exception { Collection<OAuth2AccessToken> tokens = endpoints.listTokensForUser("marissa", new TestingAuthenticationToken("marissa", ""), false); assertEquals(0, tokens.size());//from w w w . j av a 2s . c om }
From source file:at.ac.univie.isc.asio.security.RoleUserServiceTest.java
@Test(expected = UsernameNotFoundException.class) public void should_fail_if_given_principal_not_a_role_name() throws Exception { final TestingAuthenticationToken token = new TestingAuthenticationToken("test", "N/A"); subject.loadUserDetails(token);//from w w w .ja va2s. c o m }
From source file:org.cloudfoundry.identity.uaa.oauth.TokenAdminEndpointsTests.java
@Test public void testListTokensForUserId() throws Exception { Mockito.when(scimProvisioning.retrieveUser("12345")) .thenReturn(new ScimUser("12345", "marissa", "Marissa", "Bloggs")); Collection<OAuth2AccessToken> tokens = endpoints.listTokensForUser("12345", new TestingAuthenticationToken("marissa", ""), true); assertEquals(0, tokens.size());//from ww w .j av a2s.c o m }
From source file:org.cloudfoundry.identity.uaa.oauth.TokenAdminEndpointsTests.java
@Test public void testRevokeTokenForUser() throws Exception { Mockito.when(tokenServices.findTokensByUserName("marissa")) .thenReturn(Collections.<OAuth2AccessToken>singleton(new DefaultOAuth2AccessToken("FOO"))); Mockito.when(tokenServices.revokeToken("FOO")).thenReturn(true); SimpleMessage result = endpoints.revokeUserToken("marissa", new StandardPasswordEncoder().encode("FOO"), new TestingAuthenticationToken("marissa", ""), false); assertEquals("ok", result.getStatus()); }