@Override public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException { if (VALID_USERS.containsKey(credentials.getUsername()) && "secret".equals(credentials.getPassword())) { return Optional.of(new User(credentials.getUsername(), VALID_USERS.get(credentials.getUsername()))); } return Optional.empty(); } }
public GithubWebhookAuthenticator(String username, String password) { this.correctCredentials = new BasicCredentials(username, password); }
@Override public Optional<Authentication> authenticate(BasicCredentials clientCredentials) { if (correctCredentials.equals(clientCredentials)) { return Optional.of(new Authentication()); } else { return Optional.absent(); } } }
AuthorizationPolicy policy = message.get(AuthorizationPolicy.class); if (policy != null) { credentials = new BasicCredentials(policy.getUserName(), policy.getPassword()); } else { if (token != null && token.getTokenType() == TokenType.UsernameToken) { UsernameToken ut = (UsernameToken)token; credentials = new BasicCredentials(ut.getName(), ut.getPassword()); new BasicCredentials(credentials.getUsername(), credentials.getPassword()));
@Override public java.util.Optional<UserConfiguration> authenticate(BasicCredentials credentials) throws AuthenticationException { if (userConfiguration != null && userConfiguration.getUsername().equals(credentials.getUsername()) && userConfiguration.getPassword().equals(credentials.getPassword())) { return Optional.of(userConfiguration); } LOGGER.warn("Unauthorized access attempt: " + credentials.toString()); return Optional.empty(); } }
@Override public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException { if (ldapAuthenticator.authenticate(credentials)) { return Optional.of(new User(credentials.getUsername(), Collections.emptySet())); } else { return Optional.empty(); } } }
private static boolean matchesTheCredentialsSuppliedByTheClient(UserCredentials userCredentials, BasicCredentials basicCredentials) { return userCredentials.getAuthField().equals( crypt(basicCredentials.getPassword(), userCredentials.getAuthField())); }
@Override public Optional<Principal> authenticate(BasicCredentials basicCredentials) throws AuthenticationException { final UserId id = new UserId(basicCredentials.getUsername()); return readonlyUserDAO .getUserCredentialsById(id) .filter(BasicAuthenticator::hasCorrectAuthType) .filter(credentials -> matchesTheCredentialsSuppliedByTheClient(credentials, basicCredentials)) .map(UserCredentials::getId) .map(UserId::toString) .map(PrincipalImpl::new); } }
import com.google.common.base.Optional; import io.dropwizard.auth.AuthenticationException; import io.dropwizard.auth.Authenticator; import io.dropwizard.auth.basic.BasicCredentials; public class SimpleAuthenticator implements Authenticator<BasicCredentials, SimplePrincipal> { @Override public Optional<SimplePrincipal> authenticate(BasicCredentials credentials) throws AuthenticationException { // Note: this is horrible authentication. Normally we'd use some // service to identify the password from the user name. if (!"pass".equals(credentials.getPassword())) { throw new AuthenticationException("Boo Hooo!"); } // from some user service get the roles for this user // I am explicitly setting it just for simplicity SimplePrincipal prince = new SimplePrincipal(credentials.getUsername()); prince.getRoles().add(Roles.ADMIN); return Optional.fromNullable(prince); } }
public Optional<IAuthenticatedUser> authenticate(BasicCredentials credentials) throws AuthenticationException LOG.trace("Attempting to HTTP BASIC authenticate username {}", credentials.getUsername()); IUser knownUser = userDAO.lookupEmailAddress(credentials.getUsername()); LOG.debug("User with username {} is recognized", credentials.getUsername()); } catch (Exception e) LOG.warn("User with username {} is not recognized", credentials.getUsername()); failedUser.setEmailAddress(credentials.getUsername());
return new BasicCredentials(username, password);
@Override public Optional<Account> authenticate(BasicCredentials basicCredentials) throws AuthenticationException { try { AuthorizationHeader authorizationHeader = AuthorizationHeader.fromUserAndPassword(basicCredentials.getUsername(), basicCredentials.getPassword()); Optional<Account> account = accountsManager.get(authorizationHeader.getNumber()); if (!account.isPresent()) { return Optional.empty(); } Optional<Device> device = account.get().getDevice(authorizationHeader.getDeviceId()); if (!device.isPresent()) { return Optional.empty(); } if (!device.get().isMaster() && device.get().isIdleInactive()) { return Optional.empty(); } if (device.get().getAuthenticationCredentials().verify(basicCredentials.getPassword())) { authenticationSucceededMeter.mark(); account.get().setAuthenticatedDevice(device.get()); updateLastSeen(account.get(), device.get()); return account; } authenticationFailedMeter.mark(); return Optional.empty(); } catch (InvalidAuthorizationHeaderException iahe) { return Optional.empty(); } }
@Override public AuthenticationResult<Account> authenticate(UpgradeRequest request) throws AuthenticationException { try { Map<String, List<String>> parameters = request.getParameterMap(); List<String> usernames = parameters.get("login"); List<String> passwords = parameters.get("password"); if (usernames == null || usernames.size() == 0 || passwords == null || passwords.size() == 0) { return new AuthenticationResult<>(Optional.empty(), false); } BasicCredentials credentials = new BasicCredentials(usernames.get(0).replace(" ", "+"), passwords.get(0).replace(" ", "+")); return new AuthenticationResult<>(accountAuthenticator.authenticate(credentials), true); } catch (io.dropwizard.auth.AuthenticationException e) { throw new AuthenticationException(e); } }
/** * Creates a new BasicCredentials with the given username and password. * * @param credentials instance of BasicCredentials to wrap */ public SmartCosmosCredentials(BasicCredentials credentials) { super(credentials.getUsername(), credentials.getPassword()); }
BasicCredentials creds = new BasicCredentials("username", "password"); JiraClient jira = new JiraClient("https://url", creds); try { File file1 = new File("D:\\image1.jpg"); File file2 = new File("D:\\description.pdf"); List<File> fileList = new ArrayList<File>(); fileList.add(file1); fileList.add(file2); Issue newIssue = jira.createIssue("ProjectName", "Task") .field(Field.SUMMARY, "Task with attachments") .field(Field.DESCRIPTION, "Description for task with attachments.") .field(Field.PRIORITY, Field.valueById("2")) .execute(); newIssue.addAttachment(file1); newIssue.addAttachment(file2); } catch (JiraException e) { e.printStackTrace(); }
public class BasicAuthenticator implements Authenticator<BasicCredentials, Subject> { @Override public Optional<Subject> authenticate(BasicCredentials credentials) throws AuthenticationException { Subject subject = SecurityUtils.getSubject(); try { subject.login(new UsernamePasswordToken(credentials.getUsername(), credentials.getPassword(), false)); return Optional.of(subject); } catch (UnknownAccountException | IncorrectCredentialsException | LockedAccountException e) { } catch (AuthenticationException ae) { } return Optional.absent(); } }
return new BasicCredentials(username, password);
public class AuthenticationService implements Authenticator<BasicCredentials, User>, Authorizer<User> { private final UserDAO userDAO; public AuthenticationService(UserDAO userDAO) { this.userDAO = userDAO; } public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException { User user = userDAO.getByEmail(credentials.getUsername()); if (user != null && user.getPassword().equals(credentials.getPassword())) { return Optional.of(user); } return Optional.absent(); } public boolean authorize(User user, String role) { return user.hasRole(role); } }
@PropertySource("classpath:AwsCredentials.properties") public class AWSConfiguration { @Autowired private Environment env; @Bean public AwsCredentials credentials() { String secretKey = env.getRequiredProperty("name of property"); String accessKey = env.getRequiredProperty("name of property"); return new BasicCredentials(accessKey, secretKey); } }
@Override public Optional<HelloAccount> authenticate(BasicCredentials credentials) throws AuthenticationException { if (credentials.getUsername().equals("moxie") && credentials.getPassword().equals("insecure")) { return Optional.of(new HelloAccount("moxie")); } return Optional.empty(); } }