use of org.springframework.security.authentication.BadCredentialsException in project head by mifos.
the class MifosDaoAuthenticationProvider method additionalAuthenticationChecks.
@Override
protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
MifosUser user = (MifosUser) userDetails;
if (authentication.getCredentials() == null) {
throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
}
String presentedPassword = authentication.getCredentials().toString();
boolean isPasswordValid = passwordHashing.verifyPassword(presentedPassword, user.getPasswordAsBytes());
if (!isPasswordValid) {
throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
}
}
use of org.springframework.security.authentication.BadCredentialsException in project opennms by OpenNMS.
the class HybridOpenNMSUserAuthenticationProvider method checkUserPassword.
protected void checkUserPassword(final String authUsername, final String authPassword, final SpringSecurityUser user) throws AuthenticationException {
final String existingPassword = user.getPassword();
boolean hasUser = false;
try {
hasUser = m_userManager.hasUser(user.getUsername());
} catch (final Throwable e) {
throw new AuthenticationServiceException("An error occurred while checking for " + authUsername + " in the UserManager", e);
}
if (hasUser) {
if (!m_userManager.comparePasswords(authUsername, authPassword)) {
LOG.warn("Password auth failed for user: " + authUsername);
throw new BadCredentialsException("Bad credentials");
}
} else {
if (!m_userManager.checkSaltedPassword(authPassword, existingPassword)) {
LOG.warn("Salted password auth failed for user: " + authUsername);
throw new BadCredentialsException("Bad credentials");
}
}
}
use of org.springframework.security.authentication.BadCredentialsException in project Activiti by Activiti.
the class BasicAuthenticationProvider method authenticate.
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String name = authentication.getName();
String password = authentication.getCredentials().toString();
boolean authenticated = identityService.checkPassword(name, password);
if (authenticated) {
List<Group> groups = identityService.createGroupQuery().groupMember(name).list();
Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
for (Group group : groups) {
grantedAuthorities.add(new SimpleGrantedAuthority(group.getId()));
}
identityService.setAuthenticatedUserId(name);
return new UsernamePasswordAuthenticationToken(name, password, grantedAuthorities);
} else {
throw new BadCredentialsException("Authentication failed for this username and password");
}
}
use of org.springframework.security.authentication.BadCredentialsException in project ORCID-Source by ORCID.
the class OrcidMultiSecretAuthenticationProvider method additionalAuthenticationChecks.
@SuppressWarnings("deprecation")
@Override
protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
if (authentication.getCredentials() == null) {
logger.debug("Authentication failed: no credentials provided");
throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
}
String presentedPassword = authentication.getCredentials().toString();
ClientDetailsEntity clientDetailsEntity = clientDetailsManager.findByClientId(userDetails.getUsername());
for (ClientSecretEntity clientSecretEntity : clientDetailsEntity.getClientSecrets()) {
if (getPasswordEncoder().isPasswordValid(encryptionManager.decryptForInternalUse(clientSecretEntity.getClientSecret()), presentedPassword, null)) {
return;
}
}
logger.debug("Authentication failed: password does not match any value");
throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
}
use of org.springframework.security.authentication.BadCredentialsException in project ORCID-Source by ORCID.
the class OrcidOauth2TokenEndPointFilter method attemptAuthentication.
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
if (request.getMethod().equals(RequestMethod.GET.name())) {
InvalidRequestException ire = new InvalidRequestException(localeManager.resolveMessage("apiError.token_request_callmethod.exception"));
throw new MethodNotAllowedException(localeManager.resolveMessage("apiError.token_request_callmethod.exception"), ire);
}
String clientId = request.getParameter("client_id");
String clientSecret = request.getParameter("client_secret");
// If the request is already authenticated we can assume that this
// filter is not needed
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.isAuthenticated()) {
return authentication;
}
if (clientId == null) {
throw new BadCredentialsException(localeManager.resolveMessage("apiError.client_credentials.exception"));
}
if (clientSecret == null) {
clientSecret = "";
}
clientId = clientId.trim();
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(clientId, clientSecret);
authentication = this.getAuthenticationManager().authenticate(authRequest);
if (authentication != null) {
for (GrantedAuthority auth : authentication.getAuthorities()) {
if (PUBLIC_ROLE.equals(auth.getAuthority())) {
InvalidRequestException ire = new InvalidRequestException(localeManager.resolveMessage("apiError.memberapi_access.exception"));
throw new MethodNotAllowedException(localeManager.resolveMessage("apiError.memberapi_access.exception"), ire);
}
}
}
return authentication;
}
Aggregations