Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2014-2015 Hewlett-Packard Development Company, L.P.
  * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
  */
 package com.hp.autonomy.frontend.configuration.authentication;
 
    private final String roleAdmin;
    private final ConfigService<? extends AuthenticationConfig<?>> configService;
    public SingleUserAuthenticationProvider(final ConfigService<? extends AuthenticationConfig<?>> configServicefinal String roleAdmin) {
        this. = configService;
        this. = roleAdmin;
    }
    @Override
    public Authentication authenticate(final Authentication authenticationthrows AuthenticationException {
        final com.hp.autonomy.frontend.configuration.Authentication<?> configAuthentication = .getConfig().getAuthentication();
        if(!(configAuthentication instanceof SingleUserAuthentication) || ..equalsIgnoreCase(configAuthentication.getMethod())) {
            return null;
        }
        final SingleUserAuthentication singleUserAuthentication = (SingleUserAuthenticationconfigAuthentication;
        final BCryptUsernameAndPassword singleUser = singleUserAuthentication.getSingleUser();
        final String username = singleUser.getUsername();
        final String hashedPassword = singleUser.getHashedPassword();
        final String providedPassword = authentication.getCredentials().toString();
        if(authentication.getName().equals(username) && BCrypt.checkpw(providedPasswordhashedPassword)) {
            return new UsernamePasswordAuthenticationToken(usernameprovidedPassword, Arrays.asList(new SimpleGrantedAuthority()));
        }
        else {
            throw new BadCredentialsException("Bad credentials");
        }
    }
    @Override
    public boolean supports(final Class<?> authentication) {
        return authentication == UsernamePasswordAuthenticationToken.class;
    }
New to GrepCode? Check out our FAQ X