List of usage examples for org.springframework.security.authentication BadCredentialsException BadCredentialsException
public BadCredentialsException(String msg)
BadCredentialsException
with the specified message. From source file:shionn.blog.security.AuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { User user = session.getMapper(AuthenticationDao.class).readUser((String) authentication.getPrincipal()); if (user == null) { throw new BadCredentialsException("TODO msg"); } else if (checkPassword((UsernamePasswordAuthenticationToken) authentication, user)) { authentication = new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), AuthorityUtils.createAuthorityList("ROLE_ADMIN")); } else {//from w ww .j a v a 2s.c om throw new BadCredentialsException("TODO msg"); } return authentication; }
From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalAuthenticationProviderImpl.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = authentication.getName(); if (StringUtils.isBlank(username)) { log.error("Username is null or empty"); throw new BadCredentialsException(messages .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad Credentials")); }/*from w w w . ja v a 2s . co m*/ String password = authentication.getCredentials() != null ? authentication.getCredentials().toString() : null; if (StringUtils.isBlank(password)) { log.error("Password is null or empty"); throw new BadCredentialsException(messages .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad Credentials")); } log.debug("Get Information about User {} from the Resource Service", username); OwncloudLocalUserData.User user = localDataService.getUser(username); if (user == null) { log.error("User {} has not been found", username); throw new BadCredentialsException(messages .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad Credentials")); } if (!user.isEnabled()) { log.error("User {} is disabled", username); throw new DisabledException( messages.getMessage("AbstractUserDetailsAuthenticationProvider.disabled", "Disabled")); } if (!StringUtils.equals(password, user.getPassword())) { log.error("Wrong Password of User {}", username); throw new BadCredentialsException(messages .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad Credentials")); } log.debug("Set a new UsernamePasswordAuthenticationToken with User {} to the SecurityContextHolder", username); SecurityContextHolder.getContext() .setAuthentication(new UsernamePasswordAuthenticationToken(username, password)); log.info("User {} has been successfully authenticated. Get Information from UserDetailsService", username); OwncloudUserDetails owncloudUserDetails = (OwncloudUserDetails) userDetailsService .loadUserByUsername(username); log.trace("Set the Password of User {} to the Authentication Object", username); owncloudUserDetails.setPassword(password); return new UsernamePasswordAuthenticationToken(owncloudUserDetails, password, grantedAuthoritiesMappingService.mapGrantedAuthorities(owncloudUserDetails)); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestAuthenticationProviderImpl.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = authentication.getName(); if (StringUtils.isBlank(username)) { log.warn("Username is null or empty"); throw new BadCredentialsException(messages .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad Credentials")); }//w w w . j a v a 2 s . co m String password = authentication.getCredentials() != null ? authentication.getCredentials().toString() : null; if (StringUtils.isBlank(password)) { log.warn("Password is null or empty"); throw new BadCredentialsException(messages .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad Credentials")); } log.debug("Try to get Information about User {} from Location {}", username, getLocation()); Ocs.User user = exchange("/cloud/users/{user}", HttpMethod.GET, emptyEntity(username, password), Ocs.User.class, username); if (!user.getData().isEnabled()) { log.error("User {} is disabled", username); throw new DisabledException( messages.getMessage("AbstractUserDetailsAuthenticationProvider.disabled", "Disabled")); } log.debug("Set a new UsernamePasswordAuthenticationToken with User {} to the SecurityContextHolder", username); SecurityContextHolder.getContext() .setAuthentication(new UsernamePasswordAuthenticationToken(username, password)); log.info("User {} has been successfully authenticated. Get Information from UserDetailsService", username); OwncloudUserDetails owncloudUserDetails = userDetailsService.loadPreloadedUserByUsername(username, user); log.trace("Set the Password of User {} to the Authentication Object", username); owncloudUserDetails.setPassword(password); return new UsernamePasswordAuthenticationToken(owncloudUserDetails, password, grantedAuthoritiesMappingService.mapGrantedAuthorities(owncloudUserDetails)); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestAuthenticationProviderImpl.java
@Override protected void checkFailure(String username, String uri, Ocs.Meta metaInformation) throws OwncloudStatusException { if ("ok".equals(metaInformation.getStatus())) { return;/*from ww w . j av a 2 s. c o m*/ } log.warn( "Authentication Failure with Authorization User {} and Code {} from Backend. Returned Failure-Message: {}", username, metaInformation.getStatuscode(), metaInformation.getMessage()); throw new BadCredentialsException( messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad Credentials")); }