本文整理了Java中org.springframework.security.authentication.AuthenticationProvider
类的一些代码示例,展示了AuthenticationProvider
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AuthenticationProvider
类的具体详情如下:
包路径:org.springframework.security.authentication.AuthenticationProvider
类名称:AuthenticationProvider
[英]Indicates a class can process a specific org.springframework.security.core.Authentication implementation.
[中]指示类可以处理特定组织。springframework。安全果心身份验证实现。
代码示例来源:origin: spring-projects/spring-security
private AuthenticationProvider createProviderWhichThrows(
final AuthenticationException e) {
AuthenticationProvider provider = mock(AuthenticationProvider.class);
when(provider.supports(any(Class.class))).thenReturn(true);
when(provider.authenticate(any(Authentication.class))).thenThrow(e);
return provider;
}
代码示例来源:origin: geoserver/geoserver
/**
* Does the actual authentication.
*
* <p>Subclasses should override this method, the default implementation simply delegages to the
* underlying {@link AuthenticationProvider#authenticate(Authentication)}.
*
* <p>This method does not need to worry about handling any {@link AuthenticationException},
* they should be thrown back.
*/
protected Authentication doAuthenticate(
Authentication authentication, HttpServletRequest request)
throws AuthenticationException {
return authProvider.authenticate(authentication);
}
}
代码示例来源:origin: stackoverflow.com
Scanner scan = new Scanner(System.in);
AuthenticationProvider authProvider = new AuthenticationProvider();
authProvider.addAuthentication("D3", "R4");
System.out.print("The co-ordinates that your after: ");
String userInput = scan.nextLine();
System.out.print(authProvider.authenticate(userInput));
代码示例来源:origin: apache/kylin
@Override
public boolean supports(Class<?> authentication) {
return authenticationProvider.supports(authentication);
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void providerWithShaPasswordEncoderWorks() throws Exception {
appContext = new InMemoryXmlApplicationContext(
" <authentication-manager>"
+ " <authentication-provider>"
+ " <password-encoder ref='passwordEncoder'/>"
+ " <user-service>"
+ " <user name='bob' password='{SSHA}PpuEwfdj7M1rs0C2W4ssSM2XEN/Y6S5U' authorities='ROLE_A' />"
+ " </user-service>"
+ " </authentication-provider>"
+ " </authentication-manager>"
+ " <b:bean id='passwordEncoder' class='"
+ LdapShaPasswordEncoder.class.getName() + "'/>");
getProvider().authenticate(bob);
}
代码示例来源:origin: geoserver/geoserver
@Override
public boolean supports(Class<? extends Object> authentication, HttpServletRequest request) {
return authProvider.supports(authentication);
}
代码示例来源:origin: spring-projects/spring-security
private AuthenticationProvider createProviderWhichReturns(final Authentication a) {
AuthenticationProvider provider = mock(AuthenticationProvider.class);
when(provider.supports(any(Class.class))).thenReturn(true);
when(provider.authenticate(any(Authentication.class))).thenReturn(a);
return provider;
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void providerWithMd5PasswordEncoderWorks() throws Exception {
appContext = new InMemoryXmlApplicationContext(
" <authentication-manager>"
+ " <authentication-provider>"
+ " <password-encoder ref='passwordEncoder'/>"
+ " <user-service>"
+ " <user name='bob' password='12b141f35d58b8b3a46eea65e6ac179e' authorities='ROLE_A' />"
+ " </user-service>"
+ " </authentication-provider>"
+ " </authentication-manager>"
+ " <b:bean id='passwordEncoder' class='"
+ MessageDigestPasswordEncoder.class.getName() + "'>"
+ " <b:constructor-arg value='MD5'/>"
+ " </b:bean>");
getProvider().authenticate(bob);
}
代码示例来源:origin: org.openengsb.framework/org.openengsb.framework.security
@Override
public boolean apply(AuthenticationProvider input) {
return input.supports(authentication);
}
});
代码示例来源:origin: spring-projects/spring-security
@Test
public void getAuthenticationWhenAuthenticationProviderBeanThenUsed() throws Exception {
this.spring.register(AuthenticationProviderBeanConfig.class).autowire();
AuthenticationProvider ap = this.spring.getContext().getBean(AuthenticationProvider.class);
AuthenticationManager am = this.spring.getContext().getBean(AuthenticationConfiguration.class).getAuthenticationManager();
when(ap.supports(any())).thenReturn(true);
when(ap.authenticate(any())).thenReturn(TestAuthentication.authenticatedUser());
am.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
}
代码示例来源:origin: apache/kylin
} else {
try {
authed = authenticationProvider.authenticate(authentication);
代码示例来源:origin: spring-projects/spring-security
@Test
public void getAuthenticationWhenAuthenticationProviderAndUserDetailsBeanThenAuthenticationProviderUsed() throws Exception {
this.spring.register(AuthenticationProviderBeanAndUserDetailsServiceConfig.class).autowire();
AuthenticationProvider ap = this.spring.getContext().getBean(AuthenticationProvider.class);
AuthenticationManager am = this.spring.getContext().getBean(AuthenticationConfiguration.class).getAuthenticationManager();
when(ap.supports(any())).thenReturn(true);
when(ap.authenticate(any())).thenReturn(TestAuthentication.authenticatedUser());
am.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void passwordIsBase64EncodedWhenBase64IsEnabled() throws Exception {
appContext = new InMemoryXmlApplicationContext(
" <authentication-manager>"
+ " <authentication-provider>"
+ " <password-encoder ref='passwordEncoder'/>"
+ " <user-service>"
+ " <user name='bob' password='ErFB811YuLOkbupl5qwXng==' authorities='ROLE_A' />"
+ " </user-service>"
+ " </authentication-provider>"
+ " </authentication-manager>"
+ " <b:bean id='passwordEncoder' class='"
+ MessageDigestPasswordEncoder.class.getName() + "'>"
+ " <b:constructor-arg value='MD5'/>"
+ " <b:property name='encodeHashAsBase64' value='true'/>"
+ " </b:bean>");
getProvider().authenticate(bob);
}
代码示例来源:origin: spring-projects/spring-security
if (!provider.supports(toTest)) {
continue;
result = provider.authenticate(authentication);
代码示例来源:origin: spring-projects/spring-security
@Test
public void externalUserServiceRefWorks() throws Exception {
appContext = new InMemoryXmlApplicationContext(
" <authentication-manager>"
+ " <authentication-provider user-service-ref='myUserService' />"
+ " </authentication-manager>"
+ " <user-service id='myUserService'>"
+ " <user name='bob' password='{noop}bobspassword' authorities='ROLE_A' />"
+ " </user-service>");
getProvider().authenticate(bob);
}
代码示例来源:origin: org.springframework.security/spring-security-core
if (!provider.supports(toTest)) {
continue;
result = provider.authenticate(authentication);
代码示例来源:origin: spring-projects/spring-security
@Test
public void providerWithBCryptPasswordEncoderWorks() throws Exception {
setContext(" <authentication-provider>"
+ " <password-encoder hash='bcrypt'/>"
+ " <user-service>"
+ " <user name='bob' password='$2a$05$dRmjl1T05J7rvCPD2NgsHesCEJHww3pdmesUhjM3PD4m/gaEYyx/G' authorities='ROLE_A' />"
+ " </user-service>" + " </authentication-provider>");
getProvider().authenticate(bob);
}
代码示例来源:origin: org.openengsb.framework/org.openengsb.framework.security
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
Iterator<AuthenticationProvider> serviceIterator =
utilsService.getServiceIterator(providers, AuthenticationProvider.class);
AuthenticationException lastException = null;
LOGGER.debug("iterating {} authenticationProviderServices", providers.size());
while (serviceIterator.hasNext()) {
AuthenticationProvider provider = serviceIterator.next();
if (provider.supports(authentication.getClass())) {
LOGGER.info("attempting authentication using provider {}", provider.getClass());
try {
return provider.authenticate(authentication);
} catch (AuthenticationException e) {
lastException = e;
}
}
}
if (lastException == null) {
lastException =
new ProviderNotFoundException("No AuthenticationProvider found, that supports "
+ authentication.getClass());
}
throw lastException;
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void worksWithEmbeddedUserService() {
setContext(" <authentication-provider>"
+ " <user-service>"
+ " <user name='bob' password='{noop}bobspassword' authorities='ROLE_A' />"
+ " </user-service>" + " </authentication-provider>");
getProvider().authenticate(bob);
}
代码示例来源:origin: openl-tablets/openl-tablets
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
if (!delegate.supports(authentication.getClass())) {
return null;
}
try {
AuthenticationHolder.setAuthentication(authentication);
Authentication delegatedAuth = delegate.authenticate(authentication);
if (!groupsAreManagedInStudio) {
return delegatedAuth;
}
if (delegatedAuth != null) {
UserDetails userDetails = authenticationUserDetailsService.loadUserDetails(delegatedAuth);
Collection<? extends GrantedAuthority> authorities = userDetails.getAuthorities();
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
delegatedAuth.getPrincipal(),
delegatedAuth.getCredentials(),
authorities);
authenticationToken.setDetails(userDetails);
return authenticationToken;
}
return null;
} finally {
AuthenticationHolder.clear();
}
}
内容来源于网络,如有侵权,请联系作者删除!