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.AuthToolsTest.java
@Test public void should_find_identity_in_authentication_details() throws Exception { final TestingAuthenticationToken authentication = new TestingAuthenticationToken("test", "password"); authentication.setDetails(new DelegatedCredentialsDetails(Identity.from("user", "password"))); context.setAuthentication(authentication); assertThat(AuthTools.findIdentity(context), equalTo(Identity.from("user", "password"))); }
From source file:at.ac.univie.isc.asio.security.WhoamiResourceTest.java
@Test public void should_provide_authentication_principal_name() throws Exception { when(security.getAuthentication()).thenReturn(new TestingAuthenticationToken("test-name", "password")); final AuthInfo response = subject.getAuthInfo(); assertThat(response.getLogin(), equalTo("test-name")); }
From source file:utils.AbstractTest.java
public void authenticate(String username) { UserDetails userDetails;/*from w ww . j a va 2s . co m*/ TestingAuthenticationToken authenticationToken; SecurityContext context; if (username == null) authenticationToken = null; else { userDetails = loginService.loadUserByUsername(username); authenticationToken = new TestingAuthenticationToken(userDetails, null); } context = SecurityContextHolder.getContext(); context.setAuthentication(authenticationToken); }
From source file:utilities.AbstractTest.java
public void authenticate(final String username) { UserDetails userDetails;/* ww w.j a v a 2 s. c o m*/ TestingAuthenticationToken authenticationToken; SecurityContext context; if (username == null) authenticationToken = null; else { userDetails = this.loginService.loadUserByUsername(username); authenticationToken = new TestingAuthenticationToken(userDetails, null); } context = SecurityContextHolder.getContext(); context.setAuthentication(authenticationToken); }
From source file:com.springsource.greenhouse.signin.AccountExposingHandlerInterceptorTest.java
@Before public void setup() { interceptor = new AccountExposingHandlerInterceptor(); account = new Account(1L, "Joe", "Schmoe", "joe@schmoe.com", "joe", "file://pic.jpg", new UriTemplate("http://localhost:8080/members/{profileKey}")); TestingAuthenticationToken authentication = new TestingAuthenticationToken(account, "password"); SecurityContextHolder.getContext().setAuthentication(authentication); }
From source file:at.ac.univie.isc.asio.security.WhoamiResourceTest.java
@Test public void should_omit_delegated_credentials_if_not_instance_of_identity() throws Exception { final TestingAuthenticationToken auth = new TestingAuthenticationToken("name", "password"); auth.setDetails("not delegated credentials"); when(security.getAuthentication()).thenReturn(auth); final AuthInfo response = subject.getAuthInfo(); assertThat(response.getName(), nullValue()); assertThat(response.getSecret(), nullValue()); }
From source file:org.zalando.stups.oauth2.spring.client.AccessTokenUtilsTest.java
@Test public void testNonOAuth2Authentication() throws Exception { SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("foo", "bar")); assertThat(getAccessTokenFromSecurityContext().isPresent()).isFalse(); }
From source file:nl.surfnet.coin.selfservice.filter.SpringSecurityUtil.java
public static void setAuthentication(CoinUser coinUser) { final TestingAuthenticationToken token = new TestingAuthenticationToken(coinUser, ""); token.setAuthenticated(true);//from w w w.ja v a2 s . co m SecurityContextHolder.getContext().setAuthentication(token); }
From source file:at.ac.univie.isc.asio.security.AuthToolsTest.java
@Test public void should_yield_undefined_if_authentication_has_no_details() throws Exception { context.setAuthentication(new TestingAuthenticationToken("user", "password")); assertThat(AuthTools.findIdentity(context), equalTo(Identity.undefined())); }
From source file:at.ac.univie.isc.asio.security.RoleUserServiceTest.java
@Theory public void should_yield_identical_users_from_both_service_contracts(final Role role) { final UserDetails by_username = subject.loadUserByUsername(role.name()); final TestingAuthenticationToken token = new TestingAuthenticationToken(role.name(), "N/A"); final UserDetails by_token = subject.loadUserDetails(token); assertThat(by_username, equalTo(by_token)); }