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


Java BasicDBObject.getString方法代码示例

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


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

示例1: isEqual

import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
public boolean isEqual(BasicDBObject other) {
  // Need to get the salt out of the database so we can encode the password.
  String saltString = other.getString("salt");
  if ((saltString == null) || (saltString.length() == 0)) {
    throw new IllegalArgumentException("DB user does not contain a password salt");
  }

  // Now encode the password so we can compare it to what is in the database.
  byte[] salt = Base64.getDecoder().decode(saltString);
  String hashedPassword = null;

  try {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    md.update(salt);
    hashedPassword = Base64.getEncoder().encodeToString(md.digest(this.password.getBytes()));
  } catch (NoSuchAlgorithmException nsae) {
    throw new IllegalStateException();
  }

  return (id.equals(other.getString(DB_ID))
          && firstName.equals(other.get(JSON_KEY_USER_FIRST_NAME))
          && lastName.equals(other.get(JSON_KEY_USER_LAST_NAME))
          && userName.equals(other.get(JSON_KEY_USER_NAME))
          && twitterHandle.equals(other.get(JSON_KEY_USER_TWITTER_HANDLE))
          && wishListLink.equals(other.get(JSON_KEY_USER_WISH_LIST_LINK))
          && hashedPassword.equals(other.get(JSON_KEY_USER_PASSWORD)))
      ? true
      : false;
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:30,代码来源:User.java

示例2: createGroup

import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response createGroup(JsonObject payload) {

  // Validate the JWT. At this point, anyone can create a group if they
  // have a valid JWT.
  try {
    validateJWT();
  } catch (JWTException jwte) {
    return Response.status(Status.UNAUTHORIZED)
        .type(MediaType.TEXT_PLAIN)
        .entity(jwte.getMessage())
        .build();
  }

  // Create a new group based on the payload information
  Group newGroup = new Group(payload);

  // Create a db object from the group content and insert it into the
  // collection
  BasicDBObject dbGroup = newGroup.getDBObject(false);
  getGroupCollection().insert(dbGroup);

  // Return the new group id
  JsonObjectBuilder responseBuilder = Json.createObjectBuilder();
  String groupId = dbGroup.getString(Group.DB_ID);
  responseBuilder.add(Group.JSON_KEY_GROUP_ID, groupId);

  JsonObject response = responseBuilder.build();
  return Response.ok(response, MediaType.APPLICATION_JSON).build();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:33,代码来源:GroupResource.java


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