当前位置: 首页>>代码示例>>Java>>正文


Java BasicCredentials.getUsername方法代码示例

本文整理汇总了Java中io.dropwizard.auth.basic.BasicCredentials.getUsername方法的典型用法代码示例。如果您正苦于以下问题:Java BasicCredentials.getUsername方法的具体用法?Java BasicCredentials.getUsername怎么用?Java BasicCredentials.getUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.dropwizard.auth.basic.BasicCredentials的用法示例。


在下文中一共展示了BasicCredentials.getUsername方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authenticate

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
@Override
public Optional<User> authenticate(final BasicCredentials credentials) throws AuthenticationException {
    String username = credentials.getUsername();
    String password = credentials.getPassword();

    try {
        try (AutoclosableDirContext context = buildContext(username, password)) {

            //Get the user DN
            SearchResult userSearched = searchUser(context, username);

            //Check if user is in the prod group
            final boolean prodUser = checkIfUserBelongsToGroup(context, userSearched.getNameInNamespace(), configuration.getProdGroupName());
            final boolean techUser = checkIfUserBelongsToGroup(context, userSearched.getNameInNamespace(), configuration.getTechGroupName());

            User user = new User(username, prodUser, techUser);
            return Optional.of(user);
        }

    } catch (NamingException e) {
        LOGGER.debug("{} failed to authenticate {}", username);
    }

    return Optional.empty();
}
 
开发者ID:voyages-sncf-technologies,项目名称:hesperides,代码行数:26,代码来源:LDAPAuthenticator.java

示例2: authenticate

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
@Override public Optional<User> authenticate(BasicCredentials credentials)
    throws AuthenticationException {
  User user = null;
  String username = credentials.getUsername();
  if (!User.isSanitizedUsername(username)) {
    logger.info("Username: {} must match pattern: {}", username, User.USERNAME_PATTERN);
    return Optional.empty();
  }

  String password = credentials.getPassword();

  // Get hashed password column from BCrypt table by username
  Optional<String> optionalHashedPwForUser = userDAO.getHashedPassword(username);
  if (!optionalHashedPwForUser.isPresent()) {
    return Optional.empty();
  }

  if (BCrypt.checkpw(password, optionalHashedPwForUser.get())) {
    user = User.named(username);
  }

  return Optional.ofNullable(user);
}
 
开发者ID:square,项目名称:keywhiz,代码行数:24,代码来源:BcryptAuthenticator.java

示例3: authenticate

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
@UnitOfWork
public Optional<User> authenticate(final BasicCredentials basicCredentials) throws AuthenticationException {

    String email = basicCredentials.getUsername();
    String plaintextPassword = basicCredentials.getPassword();

    final Optional<User> user = userDao.findByEmail(email);
    if (user.isPresent()) {
        final User existingUser = user.get();
        checkState(existingUser.getPassword() != null, "Cannot authenticate: user with id: %s (email: %s) without password",
                existingUser.getId(), existingUser.getEmail());

        if (isMatched(plaintextPassword, existingUser.getPassword())) {
            return user;
        }
    }
    return Optional.absent();
}
 
开发者ID:blstream,项目名称:AugumentedSzczecin_java,代码行数:19,代码来源:BasicAuthenticator.java

示例4: authenticate

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
@Override
public Optional<String> authenticate(BasicCredentials credentials)
    throws AuthenticationException {
  checkNotNull(credentials);

  String username = credentials.getUsername();
  String secret = credentials.getPassword();

  ApiKey key = provider.get(username);
  if (key == null) {
    return Optional.absent();
  }

  if (!secret.equals(key.getSecret())) {
    return Optional.absent();
  }

  return Optional.of(key.getUsername());
}
 
开发者ID:dropwizard-bundles,项目名称:dropwizard-api-key-bundle,代码行数:20,代码来源:BasicCredentialsAuthenticator.java

示例5: authenticate

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
@Override
public String authenticate(HttpServletRequest request) throws AuthenticationException {
    BasicCredentials credentials = getCredentials(request);
    if (credentials == null) {
        throw new AuthenticationException("Could not parse Basic Authorization header", "Anonymous", request.getRemoteAddr());
    }
    try {
        Optional<T> user = authenticator.authenticate(credentials);
        if (!user.isPresent()) {
            throw new AuthenticationException("User authention failed", credentials.getUsername(), request.getRemoteAddr());
        }
    } catch (io.dropwizard.auth.AuthenticationException e) {
        throw new AuthenticationException("User authention failed", e, credentials.getUsername(), request.getRemoteAddr());
    }
   
     return credentials.getUsername();
}
 
开发者ID:wigforss,项目名称:Ka-Websocket,代码行数:18,代码来源:BasicAuthenticationProvider.java

示例6: authenticate

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
@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);
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:13,代码来源:BasicAuthenticator.java

示例7: authenticate

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
@Override
public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException {

  final String username = credentials.getUsername();
  LOGGER.debug("Authenticating user {}", username);
  if ("secret".equals(credentials.getPassword())) {
    return Optional.of(new User(username, Optional.empty()));
  }
  return Optional.empty();
}
 
开发者ID:atgse,项目名称:sam,代码行数:11,代码来源:BasicAuthenticator.java

示例8: authenticate

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
@Override
public Optional<EyeballUser> authenticate(BasicCredentials basicCredentials) throws AuthenticationException {
    String password = basicCredentials.getPassword();
    String username = basicCredentials.getUsername();
    if (username.equals(eyeballsConfiguration.getUsername()) && password.equals(eyeballsConfiguration.getPassword())) {
        return Optional.of(new EyeballUser());
    }
    return Optional.absent();
}
 
开发者ID:chriskearney,项目名称:eyeballs,代码行数:10,代码来源:BasicAuthenticator.java

示例9: authenticate

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
@Override
public Optional<SimplePrincipal> authenticate(BasicCredentials credentials) {
    User user = userDAO.findByUsername(credentials.getUsername());
    if (user != null && user.getPassword().equals(
            PasswordUtils.hashPassword(credentials.getPassword(), user.getSalt()))) {
        SimplePrincipal principal = new SimplePrincipal(credentials.getUsername());
        principal.getRoles().addAll(user.getRoles());
        return Optional.of(principal);
    }
    return Optional.absent();
}
 
开发者ID:zheng-wang,项目名称:irontest,代码行数:12,代码来源:ResourceAuthenticator.java

示例10: authenticateUnencrypted

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
private Optional<Peer> authenticateUnencrypted(BasicCredentials credentials) throws AuthenticationException {
    Peer peer = new Peer(credentials.getUsername(), credentials.getPassword());

    if (this.allPeers.contains(peer)) {
        LOGGER.debug("{} authenticated and allowed to request service", credentials.getUsername());
        return Optional.of(peer);
    }
    else {
        LOGGER.debug("{} is not known in our list of allowed peers", credentials.getUsername());
    }
    return Optional.empty();
}
 
开发者ID:washingtonpost,项目名称:dropwizard-peer-authenticator,代码行数:13,代码来源:AllowedPeerAuthenticator.java

示例11: authenticate

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
@Override
public Optional<BasicUserPrincipal> authenticate(BasicCredentials credentials) throws AuthenticationException {
	String loginUserName = credentials.getUsername();
	String loginPassword = credentials.getPassword();
	String htUsersPass = readHtUsers().getPassword(loginUserName);
	if(negate(comparePasswords(loginPassword, htUsersPass))) {
		logger.info("Failed to login " + loginUserName);
		return Optional.empty();
	}
	return Optional.of(new BasicUserPrincipal(loginUserName));
}
 
开发者ID:rrauschenbach,项目名称:FeedExpander,代码行数:12,代码来源:HtUserAuthenticator.java

示例12: authenticate

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
private Optional<AuthorizedPrincipal> authenticate(BasicCredentials credentials,
                                                   Model model) {
    String username = credentials.getUsername();
    List<? extends ExistentialRuleform> agencies = model.getPhantasmModel()
                                                        .findByAttributeValue(model.getKernel()
                                                                                   .getLogin(),
                                                                              username);
    if (agencies.size() > 1) {
        log.error(String.format("Multiple agencies with username %s",
                                username));
        return absent();
    }
    if (agencies.size() == 0) {
        log.warn(String.format("Attempt to login from non existent username %s",
                               username));
        return absent();
    }
    ExistentialRuleform agency = agencies.get(0);
    if (agency.getDomain() != ExistentialDomain.Agency) {
        log.warn(String.format("Attempt to login from non existent agency %s",
                               username));
        return absent();
    }
    CoreUser user = model.wrap(CoreUser.class, agency);

    if (!canLoginToInstance(user, model)) {
        return noCapability(username, user);
    }

    boolean authenticated = authenticate(user, credentials.getPassword());
    if (authenticated) {
        return authenticatedPrincipal(user, username);
    } else {
        return authenticationFailure(username, user);
    }
}
 
开发者ID:ChiralBehaviors,项目名称:Ultrastructure,代码行数:37,代码来源:AgencyBasicAuthenticator.java

示例13: authenticate

import io.dropwizard.auth.basic.BasicCredentials; //导入方法依赖的package包/类
@Override
public Optional<User> authenticate(BasicCredentials credentials) {
  User user = null;

  try {
    String username = credentials.getUsername();
    if (!User.isSanitizedUsername(username)) {
      logger.info("Username: {} must match pattern: {}", username, User.USERNAME_PATTERN);
      return Optional.empty();
    }

    String userDN = dnFromUsername(username);
    String password = credentials.getPassword();

    // Must have password for current config
    if (Strings.isNullOrEmpty(password)) {
      logger.info("No password for user provided");
      return Optional.empty();
    }

    LDAPConnection authenticatedConnection = connectionFactory.getLDAPConnection(userDN, password);
    authenticatedConnection.close();

    Set<String> requiredRoles = config.getRequiredRoles();
    if (!requiredRoles.isEmpty()) {
      Set<String> roles = rolesFromDN(userDN);

      boolean accessAllowed = false;
      for (String requiredRole : requiredRoles) {
        if (roles.contains(requiredRole)) {
          accessAllowed = true;
        }
      }

      if (!accessAllowed) {
        logger.warn("User {} not in one of required LDAP roles: [{}].", username, requiredRoles);
        throw new ForbiddenException();
      }
    }

    user = User.named(username);
  } catch (LDAPException le) {
    // The INVALID_CREDENTIALS case is handled by returning an absent optional from this function
    if (le.getResultCode() != ResultCode.INVALID_CREDENTIALS) {
      logger.error("Error connecting to LDAP", le);
      throw Throwables.propagate(le);
    }
  } catch (GeneralSecurityException gse) {
      logger.error("TLS error connecting to LDAP", gse);
      throw Throwables.propagate(gse);
  }

  return Optional.ofNullable(user);
}
 
开发者ID:square,项目名称:keywhiz,代码行数:55,代码来源:LdapAuthenticator.java


注:本文中的io.dropwizard.auth.basic.BasicCredentials.getUsername方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。