Java Code Examples for org.springframework.security.authentication.AuthenticationProvider#authenticate()

The following examples show how to use org.springframework.security.authentication.AuthenticationProvider#authenticate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleHashUtil.java    From Roothub with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
	Class<? extends Authentication> toTest = authentication.getClass();
	Authentication result = null;
	for (AuthenticationProvider provider : providers) {
		if (!provider.supports(toTest)) {
			continue;
		}
		// 调用认证提供者进行认证,如果 result 不为 null ,说明认证通过
		result = provider.authenticate(authentication);
		if (result != null) {
			break;
		}
	}
	if (result == null) {
		throw new ProviderNotFoundException("ProviderManager.providerNotFound");
	}
	return result;
}
 
Example 2
Source File: FakeAuthenticationProviderTest.java    From springboot-angular-atmosphere-quickstart with Apache License 2.0 4 votes vote down vote up
@Test
public void arbitraryCasedNameReturnsValidAuthentication() {
  AuthenticationProvider provider = createProvider();
  Authentication authentication = provider.authenticate(createAuthenticationTokenWithUserAndPw("AdMiN", "adm1n"));
  Assert.assertNotNull(authentication);
}
 
Example 3
Source File: FakeAuthenticationProviderTest.java    From springboot-angular-atmosphere-quickstart with Apache License 2.0 4 votes vote down vote up
@Test
public void validPasswordReturnsValidAuthentication() {
  AuthenticationProvider provider = createProvider();
  Authentication authentication = provider.authenticate(createAuthenticationTokenWithUserAndPw("admin", "adm1n"));
  Assert.assertNotNull(authentication);
}
 
Example 4
Source File: FakeAuthenticationProviderTest.java    From springboot-angular-atmosphere-quickstart with Apache License 2.0 4 votes vote down vote up
@Test(expected = BadCredentialsException.class)
public void invalidPasswordRaises() {
  AuthenticationProvider provider = createProvider();
  provider.authenticate(createAuthenticationTokenWithUserAndPw("admin", "admin"));
}
 
Example 5
Source File: FakeAuthenticationProviderTest.java    From springboot-angular-atmosphere-quickstart with Apache License 2.0 4 votes vote down vote up
@Test(expected = BadCredentialsException.class)
public void invalidUserRaises() {
  AuthenticationProvider provider = createProvider();
  provider.authenticate(createAuthenticationTokenWithUserAndPw("admon", "adm1n"));
}