本文整理了Java中org.springframework.security.authentication.DisabledException
类的一些代码示例,展示了DisabledException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DisabledException
类的具体详情如下:
包路径:org.springframework.security.authentication.DisabledException
类名称:DisabledException
[英]Thrown if an authentication request is rejected because the account is disabled. Makes no assertion as to whether or not the credentials were valid.
[中]如果由于帐户被禁用而拒绝身份验证请求,则引发。不断言凭据是否有效。
代码示例来源:origin: spring-projects/spring-security
public void check(UserDetails user) {
if (!user.isAccountNonLocked()) {
logger.debug("User account is locked");
throw new LockedException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.locked",
"User account is locked"));
}
if (!user.isEnabled()) {
logger.debug("User account is disabled");
throw new DisabledException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.disabled",
"User is disabled"));
}
if (!user.isAccountNonExpired()) {
logger.debug("User account is expired");
throw new AccountExpiredException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.expired",
"User account has expired"));
}
}
}
代码示例来源:origin: zhangxd1989/springboot-dubbox
/**
* Handle business exception map.
*
* @param ex the ex
* @return the map
*/
@ExceptionHandler(DisabledException.class)
@ResponseStatus(HttpStatus.FORBIDDEN)
public Map<String, Object> handleBusinessException(DisabledException ex) {
//用户被停用
return makeErrorMessage(ReturnCode.DISABLED_USER, "User Disabled", ex.getMessage());
}
代码示例来源:origin: org.springframework.security/spring-security-core
public void check(UserDetails user) {
if (!user.isAccountNonLocked()) {
logger.debug("User account is locked");
throw new LockedException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.locked",
"User account is locked"));
}
if (!user.isEnabled()) {
logger.debug("User account is disabled");
throw new DisabledException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.disabled",
"User is disabled"));
}
if (!user.isAccountNonExpired()) {
logger.debug("User account is expired");
throw new AccountExpiredException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.expired",
"User account has expired"));
}
}
}
代码示例来源:origin: jtalks-org/jcommune
/**
* {@inheritDoc}
*/
@Override
public AuthenticationStatus authenticate(LoginUserDto loginUserDto, HttpServletRequest request,
HttpServletResponse response) throws UnexpectedErrorException, NoConnectionException {
AuthenticationStatus result;
JCUser user;
try {
user = getByUsername(loginUserDto.getUserName());
result = authenticateDefault(user, loginUserDto.getPassword(), loginUserDto.isRememberMe(), request, response);
} catch (NotFoundException e) {
LOGGER.info("User was not found during login process, username = {}, IP={}",
loginUserDto.getUserName(), loginUserDto.getClientIp());
result = authenticateByPluginAndUpdateUserInfo(loginUserDto, true, request, response);
} catch(DisabledException e) {
LOGGER.info("DisabledException: username = {}, IP={}, message={}",
new String[]{loginUserDto.getUserName(), loginUserDto.getClientIp(), e.getMessage()});
result = AuthenticationStatus.NOT_ENABLED;
} catch (AuthenticationException e) {
LOGGER.info("AuthenticationException: username = {}, IP={}, message={}",
new String[]{loginUserDto.getUserName(), loginUserDto.getClientIp(), e.getMessage()});
result = authenticateByPluginAndUpdateUserInfo(loginUserDto, false, request, response);
}
return result;
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void testRejectsNullAuthentication() {
AuthenticationException exception = new DisabledException("TEST");
try {
new AuthenticationFailureDisabledEvent(null, exception);
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
}
}
代码示例来源:origin: com.holon-platform.core/holon-spring-security
@Override
public Authentication authenticate(T authenticationToken) throws AuthenticationException {
if (authenticationToken == null) {
throw new InvalidTokenException("Null authentication token");
}
org.springframework.security.core.Authentication authentication = getAuthentication(authenticationToken);
if (authentication == null) {
throw new InvalidTokenException("Invalid authentication token: missing Spring Security Authentication");
}
try {
authentication = authenticationManager.authenticate(authentication);
} catch (UsernameNotFoundException e) {
throw new UnknownAccountException(e.getMessage());
} catch (BadCredentialsException e) {
throw new InvalidCredentialsException(e.getMessage());
} catch (CredentialsExpiredException | AccountExpiredException e) {
throw new ExpiredCredentialsException(e.getMessage());
} catch (DisabledException e) {
throw new DisabledAccountException(e.getMessage());
} catch (LockedException e) {
throw new LockedAccountException(e.getMessage());
} catch (Exception e) {
throw new UnexpectedAuthenticationException(e.getMessage(), e);
}
return SpringSecurityAuthentication.create(authentication);
}
代码示例来源:origin: spring-projects/spring-security
private void raiseExceptionForErrorCode(int code, NamingException exception) {
String hexString = Integer.toHexString(code);
Throwable cause = new ActiveDirectoryAuthenticationException(hexString,
exception.getMessage(), exception);
switch (code) {
case PASSWORD_EXPIRED:
throw new CredentialsExpiredException(messages.getMessage(
"LdapAuthenticationProvider.credentialsExpired",
"User credentials have expired"), cause);
case ACCOUNT_DISABLED:
throw new DisabledException(messages.getMessage(
"LdapAuthenticationProvider.disabled", "User is disabled"), cause);
case ACCOUNT_EXPIRED:
throw new AccountExpiredException(messages.getMessage(
"LdapAuthenticationProvider.expired", "User account has expired"),
cause);
case ACCOUNT_LOCKED:
throw new LockedException(messages.getMessage(
"LdapAuthenticationProvider.locked", "User account is locked"), cause);
default:
throw badCredentials(cause);
}
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void testAbstractAuthenticationFailureEvent() {
Authentication auth = getAuthentication();
AuthenticationException exception = new DisabledException("TEST");
AbstractAuthenticationFailureEvent event = new AuthenticationFailureDisabledEvent(
auth, exception);
assertThat(event.getAuthentication()).isEqualTo(auth);
assertThat(event.getException()).isEqualTo(exception);
}
代码示例来源:origin: spring-projects/spring-security
publisher.publishAuthenticationFailure(new AccountExpiredException("", cause), a);
publisher.publishAuthenticationFailure(new ProviderNotFoundException(""), a);
publisher.publishAuthenticationFailure(new DisabledException(""), a);
publisher.publishAuthenticationFailure(new DisabledException("", cause), a);
publisher.publishAuthenticationFailure(new LockedException(""), a);
publisher.publishAuthenticationFailure(new LockedException("", cause), a);
代码示例来源:origin: spring-projects/spring-security
public void check(UserDetails user) {
if (!user.isAccountNonLocked()) {
throw new LockedException(messages.getMessage(
"AccountStatusUserDetailsChecker.locked", "User account is locked"));
}
if (!user.isEnabled()) {
throw new DisabledException(messages.getMessage(
"AccountStatusUserDetailsChecker.disabled", "User is disabled"));
}
if (!user.isAccountNonExpired()) {
throw new AccountExpiredException(
messages.getMessage("AccountStatusUserDetailsChecker.expired",
"User account has expired"));
}
if (!user.isCredentialsNonExpired()) {
throw new CredentialsExpiredException(messages.getMessage(
"AccountStatusUserDetailsChecker.credentialsExpired",
"User credentials have expired"));
}
}
}
代码示例来源:origin: org.springframework.security/spring-security-core
public void check(UserDetails user) {
if (!user.isAccountNonLocked()) {
throw new LockedException(messages.getMessage(
"AccountStatusUserDetailsChecker.locked", "User account is locked"));
}
if (!user.isEnabled()) {
throw new DisabledException(messages.getMessage(
"AccountStatusUserDetailsChecker.disabled", "User is disabled"));
}
if (!user.isAccountNonExpired()) {
throw new AccountExpiredException(
messages.getMessage("AccountStatusUserDetailsChecker.expired",
"User account has expired"));
}
if (!user.isCredentialsNonExpired()) {
throw new CredentialsExpiredException(messages.getMessage(
"AccountStatusUserDetailsChecker.credentialsExpired",
"User credentials have expired"));
}
}
}
代码示例来源:origin: org.eclipse.hudson/hudson-core
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
AuthenticationManager m = delegate; // fix the reference we are working with
if (m == null) {
throw new DisabledException("Authentication service is still not ready yet");
} else {
return m.authenticate(authentication);
}
}
代码示例来源:origin: org.molgenis/molgenis-security
@Override
public void check(UserDetails userDetails) {
if (!userDetails.isEnabled()) {
throw new DisabledException(
messages.getMessage("AccountStatusUserDetailsChecker.disabled", "User is not active")
+ ' '
+ userDetails.toString());
}
}
}
代码示例来源:origin: liuht777/Taroco
/**
* 通过 Username 加载用户详情
*
* @param username 用户名
* @return UserDetails
* @throws UsernameNotFoundException 用户没找到
*/
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// 查询用户信息,包含角色列表
UserVO userVo = userService.findUserByUsername(username);
if (userVo == null) {
throw new UsernameNotFoundException("用户名/密码错误");
}
if (CommonConstant.DEL_FLAG.equals(userVo.getDelFlag())) {
throw new DisabledException("用户: " + username + " 不可用");
}
return new UserDetailsImpl(userVo);
}
代码示例来源:origin: craftingjava/springuni-particles
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String username = authentication.getName();
String password = (String) authentication.getCredentials();
try {
User user = userService.login(username, password);
Collection<GrantedAuthority> authorities = user.getAuthorities()
.stream()
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toSet());
return new UsernamePasswordAuthenticationToken(user.getId(), null, authorities);
} catch (NoSuchUserException e) {
throw new UsernameNotFoundException(e.getMessage(), e);
} catch (UnconfirmedUserException e) {
throw new DisabledException(e.getMessage(), e);
}
}
代码示例来源:origin: synyx/urlaubsverwaltung
@Override
public Authentication authenticate(Authentication authentication) {
StandardPasswordEncoder encoder = new StandardPasswordEncoder();
String username = authentication.getName();
String rawPassword = authentication.getCredentials().toString();
Optional<Person> userOptional = personService.getPersonByLogin(username);
if (!userOptional.isPresent()) {
LOG.info("No user found for username '" + username + "'");
throw new UsernameNotFoundException("No authentication possible for user = " + username);
}
Person person = userOptional.get();
if (person.hasRole(Role.INACTIVE)) {
LOG.info("User '" + username + "' has been deactivated and can not sign in therefore");
throw new DisabledException("User '" + username + "' has been deactivated");
}
Collection<Role> permissions = person.getPermissions();
Collection<GrantedAuthority> grantedAuthorities = permissions.stream().map((role) ->
new SimpleGrantedAuthority(role.name())).collect(Collectors.toList());
String userPassword = person.getPassword();
if (encoder.matches(rawPassword, userPassword)) {
LOG.info("User '" + username + "' has signed in with roles: " + grantedAuthorities);
return new UsernamePasswordAuthenticationToken(username, userPassword, grantedAuthorities);
} else {
LOG.info("User '" + username + "' has tried to sign in with a wrong password");
throw new BadCredentialsException("The provided password is wrong");
}
}
代码示例来源:origin: it.geosolutions.geostore/geostore-rest-impl
throw new DisabledException(USER_NOT_FOUND_MSG);
代码示例来源:origin: com.holon-platform.core/holon-spring-security
@SuppressWarnings("unchecked")
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
if (authentication == null) {
throw new AuthenticationServiceException("Null Authentication");
}
if (!TypeUtils.isAssignable(authenticationType, authentication.getClass())) {
return null;
}
com.holonplatform.auth.Authentication authc;
try {
authc = authenticator.authenticate(converter.apply((A) authentication));
} catch (com.holonplatform.auth.exceptions.UnknownAccountException e) {
throw new UsernameNotFoundException("Unknown account", e);
} catch (com.holonplatform.auth.exceptions.InvalidCredentialsException e) {
throw new BadCredentialsException("Invalid credentials", e);
} catch (com.holonplatform.auth.exceptions.ExpiredCredentialsException e) {
throw new CredentialsExpiredException("Expired credentials", e);
} catch (com.holonplatform.auth.exceptions.DisabledAccountException e) {
throw new DisabledException("Disabled account", e);
} catch (com.holonplatform.auth.exceptions.LockedAccountException e) {
throw new LockedException("Locked account", e);
} catch (com.holonplatform.auth.exceptions.AuthenticationException e) {
throw new InternalAuthenticationServiceException("Internal authentication error", e);
}
return new SpringSecurityAuthenticationAdapter(authc);
}
代码示例来源:origin: org.springframework.security/org.springframework.security.core
public void check(UserDetails user) {
if (!user.isAccountNonLocked()) {
logger.debug("User account is locked");
throw new LockedException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.locked",
"User account is locked"), user);
}
if (!user.isEnabled()) {
logger.debug("User account is disabled");
throw new DisabledException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.disabled",
"User is disabled"), user);
}
if (!user.isAccountNonExpired()) {
logger.debug("User account is expired");
throw new AccountExpiredException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.expired",
"User account has expired"), user);
}
}
}
代码示例来源:origin: osiam/server
throw new DisabledException("The user with the username '" + username + "' is disabled!");
内容来源于网络,如有侵权,请联系作者删除!