Example usage for org.springframework.security.authentication BadCredentialsException BadCredentialsException

List of usage examples for org.springframework.security.authentication BadCredentialsException BadCredentialsException

Introduction

In this page you can find the example usage for org.springframework.security.authentication BadCredentialsException BadCredentialsException.

Prototype

public BadCredentialsException(String msg) 

Source Link

Document

Constructs a BadCredentialsException with the specified message.

Usage

From source file:com.thoughtworks.go.server.newsecurity.utils.BasicAuthHeaderExtractor.java

public static UsernamePassword extractBasicAuthenticationCredentials(String authorizationHeader) {
    if (isBlank(authorizationHeader)) {
        return null;
    }//from w  ww .  j  a  v  a  2 s.  c om

    final Matcher matcher = BASIC_AUTH_EXTRACTOR_PATTERN.matcher(authorizationHeader);
    if (matcher.matches()) {
        final String encodedCredentials = matcher.group(1);
        final byte[] decode = Base64.getDecoder().decode(encodedCredentials);
        String decodedCredentials = new String(decode, StandardCharsets.UTF_8);

        final int indexOfSeparator = decodedCredentials.indexOf(':');
        if (indexOfSeparator == -1) {
            throw new BadCredentialsException("Invalid basic authentication credentials specified in request.");
        }

        final String username = decodedCredentials.substring(0, indexOfSeparator);
        final String password = decodedCredentials.substring(indexOfSeparator + 1);

        return new UsernamePassword(username, password);
    }

    return null;
}

From source file:com.beto.test.securityinterceptor.security.UserNamePasswordAuth.java

@Override
protected String obtainUsername(HttpServletRequest request) {
    logger.debug("ExUsernamePasswordAuthenticationFilter.obtainUsername() method called..."
            + request.getParameter(getUsernameParameter()) + "   "
            + request.getParameter(getPasswordParameter()));
    String username = request.getParameter(getUsernameParameter());
    String password = request.getParameter(getPasswordParameter());

    if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
        throw new BadCredentialsException("");
    }// ww  w  .  j  a  va2s  . c o m

    return username;
}

From source file:com.isalnikov.config.SampleAuthenticationManager.java

@Override
public Authentication authenticate(Authentication auth) throws AuthenticationException {
    if (auth.getName().equals(auth.getCredentials())) {

        UserAuthorizationToken token = (UserAuthorizationToken) auth;

        return new UserAuthorizationToken(token.getName(), token.getPassword(), token.getTerminalId(),
                token.getAuthorities());
    }/*from w ww.j  av a 2  s  .c o m*/
    throw new BadCredentialsException("Bad Credentials");
}

From source file:edu.eci.test.AAAUserAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String user = authentication.getPrincipal().toString();
    String pwd = authentication.getCredentials().toString();

    //PUT Auth Bean here

    boolean result = user.equals("myuser") && pwd.equals("mypassword");
    //= aaaProxy.isValidUser(authentication.getPrincipal()
    //.toString(), authentication.getCredentials().toString());

    if (result) {
        List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
        AAAUserAuthenticationToken auth = new AAAUserAuthenticationToken(authentication.getPrincipal(),
                authentication.getCredentials(), grantedAuthorities);

        return auth;
    } else {/*from w w  w.  j a v  a 2s .  c  o  m*/
        throw new BadCredentialsException("Bad User Credentials.");
    }

}

From source file:com.cosw.productsmaster.authsec.UserAuthenticationProvider.java

public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String user = authentication.getPrincipal().toString();
    String pwd = authentication.getCredentials().toString();

    //PUT Auth Bean here

    boolean result = user.equals("myuser") && pwd.equals("mypassword");
    System.out.println("hola" + result);
    if (result) {
        List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
        UserAuthenticationToken auth = new UserAuthenticationToken(authentication.getPrincipal(),
                authentication.getCredentials(), grantedAuthorities);

        return auth;
    } else {/*from   w  w w .jav  a  2  s.c  o  m*/
        throw new BadCredentialsException("Bad User Credentials.");
    }

}

From source file:br.com.sicva.seguranca.ProvedorAutenticacao.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String name = authentication.getName();
    String password = authentication.getCredentials().toString();
    UsuariosDao usuariosDao = new UsuariosDao();
    Usuarios usuario = usuariosDao.PesquisarUsuario(name);

    if (usuario == null || !usuario.getUsuariosCpf().equalsIgnoreCase(name)) {
        throw new BadCredentialsException("Username not found.");
    }/*ww w.  j a  v a2s.co m*/

    if (!GenerateMD5.generate(password).equals(usuario.getUsuarioSenha())) {
        throw new LockedException("Wrong password.");
    }
    if (!usuario.getUsuarioAtivo()) {
        throw new DisabledException("User is disable");
    }
    List<GrantedAuthority> funcoes = new ArrayList<>();
    funcoes.add(new SimpleGrantedAuthority("ROLE_" + usuario.getFuncao().getFuncaoDescricao()));
    Collection<? extends GrantedAuthority> authorities = funcoes;
    return new UsernamePasswordAuthenticationToken(name, password, authorities);

}

From source file:hr.foi.sis.conf.PBKDF2AuthProvider.java

@Override
public Authentication authenticate(Authentication a) throws AuthenticationException {

    String username = a.getName();

    Logger.getLogger("Auth").log(Level.INFO, "POST on login username -- " + username);

    if (username == null)
        throw new BadCredentialsException("Username not found.");

    String password = (String) a.getCredentials();

    Logger.getLogger("Auth").log(Level.INFO, "POST on password -- " + password);

    if (password == null)
        throw new BadCredentialsException("Password not found.");

    Logger.getLogger("Auth").log(Level.INFO, "Getting user from database");

    UserSaltDetails user = userService.loadUserByUsername(username);

    Logger.getLogger("Auth").log(Level.INFO, "User get with username: " + user.getUsername());

    Logger.getLogger("Auth").log(Level.INFO, "User get with password: " + user.getPassword());
    String pw = user.getPassword();

    Logger.getLogger("Auth").log(Level.INFO, "User get with salt : " + user.getUserSalt());

    Logger.getLogger("Auth").log(Level.INFO, "User get with authorities : " + user.getAuthorities().toString());

    boolean isAuthenticated = false;

    try {/*from w  w w .j a v a2s. c o  m*/

        isAuthenticated = PBKDF2.authenticate(password, user.getPassword(), user.getUserSalt());
        Logger.getLogger("Auth").log(Level.INFO, "Is true : " + isAuthenticated);

    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(PBKDF2AuthProvider.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvalidKeySpecException ex) {
        Logger.getLogger(PBKDF2AuthProvider.class.getName()).log(Level.SEVERE, null, ex);
    }

    if (!isAuthenticated)
        throw new BadCredentialsException("Wrong password.");
    else
        Logger.getLogger("Auth").log(Level.INFO, "Authenticated");

    return new UsernamePasswordAuthenticationToken(user, user.getPassword(), user.getAuthorities());

}

From source file:org.xaloon.wicket.security.spring.XaloonDaoAuthenticationProvider.java

@Override
protected void additionalAuthenticationChecks(UserDetails userDetails,
        UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
    if (authentication.getCredentials() == null) {
        throw new BadCredentialsException(messages
                .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
    }/*  w w  w  .j  av a2 s. co  m*/
    if (authentication.getCredentials() instanceof String) {
        String encoded = PasswordEncoder.get().encode(authentication.getName(),
                authentication.getCredentials().toString());

        if (!userDetails.getPassword().equals(encoded)) {
            throw new BadCredentialsException(messages
                    .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
        }
    }
}

From source file:eu.freme.broker.security.TokenService.java

public Token retrieve(String tokenStr) {
    Token token = tokenRepository.findOneByToken(tokenStr);
    if (token == null) {
        throw new BadCredentialsException("invalid token");
    }// w ww . j  av  a 2s .  c o  m
    return token;
}

From source file:com.isalnikov.config.auth.UserAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {

    UserAuthorizationToken auth = (UserAuthorizationToken) authentication;

    String login = auth.getLogin();
    String password = auth.getPassword();
    String terminalId = auth.getTerminalId();

    if (loginService.login(login, password, terminalId) == 0) {

        Object principal = auth.getPrincipal();
        UserAuthorizationToken authorizationToken = new UserAuthorizationToken(login, password, terminalId,
                Arrays.asList(UserAuthority.ROLE_USER));

        return authorizationToken;
    }/*from w w  w  . j  a  va 2s . c o  m*/

    throw new BadCredentialsException("Invalid username or password");

}