当前位置: 首页>>代码示例>>Java>>正文


Java UsernamePasswordAuthenticationToken.getCredentials方法代码示例

本文整理汇总了Java中org.springframework.security.authentication.UsernamePasswordAuthenticationToken.getCredentials方法的典型用法代码示例。如果您正苦于以下问题:Java UsernamePasswordAuthenticationToken.getCredentials方法的具体用法?Java UsernamePasswordAuthenticationToken.getCredentials怎么用?Java UsernamePasswordAuthenticationToken.getCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.authentication.UsernamePasswordAuthenticationToken的用法示例。


在下文中一共展示了UsernamePasswordAuthenticationToken.getCredentials方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: additionalAuthenticationChecks

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; //导入方法依赖的package包/类
/**
 * Implementation of an abstract method defined in the base class. The
 * additionalAuthenticationChecks() method is called by authenticate()
 * method of the base class after the invocation of retrieveUser() method.
 */
@Override
protected void additionalAuthenticationChecks(UserDetails userDetails,
											  UsernamePasswordAuthenticationToken authentication)
		throws AuthenticationException {
	if (authentication.getCredentials() == null) {
		logger.warn("Authentication failed: no credentials provided");
		throw new BadCredentialsException(messages.getMessage(
				"AbstractUserDetailsAuthenticationProvider.badCredentials",
				"Bad credentials"), null);
	}

	String presentedPassword = authentication.getCredentials().toString();

	if (!passwordEncoder.matches(presentedPassword, userDetails.getPassword())) {
		logger.warn("Authentication failed: password does not match stored value");
		throw new BadCredentialsException(messages.getMessage("UserDetailsAuthenticationProviderImpl.badCredentials",
															  "Bad credentials"), null);
	}
}
 
开发者ID:melthaw,项目名称:spring-backend-boilerplate,代码行数:25,代码来源:UserDetailsAuthenticationProviderImpl.java

示例2: preChecks

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; //导入方法依赖的package包/类
private void preChecks(UsernamePasswordAuthenticationToken authentication)throws AuthenticationException{
	boolean useCaptcha=Configure.getBoolean("bdf2.useCaptchaForLogin");
	if(useCaptcha){
		String key=ContextHolder.getRequest().getParameter("captcha_");
		if(StringUtils.isNotEmpty(key)){
			String sessionkey=(String)ContextHolder.getHttpSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
			if(sessionkey==null){
				throw new BadCredentialsException("验证码过期");
			}else if(!sessionkey.equals(key)){
				throw new BadCredentialsException("验证码不正确");					
			}
		}else{
			throw new BadCredentialsException("验证码不能为空");					
		}
	}
	if (authentication.getPrincipal() == null) {
		throw new BadCredentialsException("Username can not be null");
	}
	if (authentication.getCredentials() == null) {
		throw new BadCredentialsException("password can not be null");
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:23,代码来源:DefaultFrameworkService.java

示例3: additionalAuthenticationChecks

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; //导入方法依赖的package包/类
@Override
protected void additionalAuthenticationChecks(final UserDetails userDetails, final UsernamePasswordAuthenticationToken token)
        throws AuthenticationException {
    if (token.getCredentials() == null || userDetails.getPassword() == null) {
        throw new BadCredentialsException("Credentials may not be null.");
    }
    if (!passwordEncoder.matches((String) token.getCredentials(), userDetails.getPassword())) {
        throw new BadCredentialsException("Invalid credentials.");
    }
}
 
开发者ID:zeldan,项目名称:spring-boot-oauth2-password-flow,代码行数:11,代码来源:AccountAuthenticationProvider.java


注:本文中的org.springframework.security.authentication.UsernamePasswordAuthenticationToken.getCredentials方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。