Package org.openmhealth.reference.domain

Examples of org.openmhealth.reference.domain.User


            "', pair is unknown.");
    }
    Schema schema = schemas.iterator().next();
   
    // Get the user that owns this token.
    User requestingUser = authToken.getUser();
   
    // Parse the data.
    JsonNode dataNode;
    try {
      dataNode =
        JSON_FACTORY
          .createJsonParser(data).readValueAs(JsonNode.class);
    }
    catch(JsonParseException e) {
      throw new OmhException("The data was not well-formed JSON.", e);
    }
    catch(JsonProcessingException e) {
      throw new OmhException("The data was not well-formed JSON.", e);
    }
    catch(IOException e) {
      throw new OmhException("The data could not be read.", e);
    }
   
    // Make sure it is a JSON array.
    if(! (dataNode instanceof ArrayNode)) {
      throw new OmhException("The data was not a JSON array.");
    }
    ArrayNode dataArray = (ArrayNode) dataNode;
   
    // Get the number of data points.
    int numDataPoints = dataArray.size();
   
    // Create the result list of data points.
    List<Data> dataPoints = new ArrayList<Data>(numDataPoints);
   
    // Create a new ObjectMapper that will be used to convert the meta-data
    // node into a MetaData object.
    ObjectMapper mapper = new ObjectMapper();
   
    // For each element in the array, be sure it is a JSON object that
    // represents a valid data point for this schema.
    for(int i = 0; i < numDataPoints; i++) {
      // Get the current data point.
      JsonNode dataPoint = dataArray.get(i);
     
      // Validate that it is a JSON object.
      if(! (dataPoint instanceof ObjectNode)) {
        throw
          new OmhException(
            "A data point was not a JSON object: " + i);
      }
      ObjectNode dataObject = (ObjectNode) dataPoint;
     
      // Attempt to get the meta-data;
      MetaData metaData = null;
      JsonNode metaDataNode = dataObject.get(Data.JSON_KEY_METADATA);
      if(metaDataNode != null) {
        metaData = mapper.convertValue(metaDataNode, MetaData.class);
      }
     
      // Attempt to get the schema data.
      JsonNode schemaData = dataObject.get(Data.JSON_KEY_DATA);
     
      // If the data is missing, fail the request.
      if(schemaData == null) {
        throw
          new OmhException(
            "A data point's '" +
              Data.JSON_KEY_DATA +
              "' field is missing.");
      }
     
      // Create and add the point to the set of data.
      dataPoints
        .add(
          schema
            .validateData(
              requestingUser.getUsername(),
              metaData,
              schemaData));
    }
   
    // Store the data.
View Full Code Here


    throws IOException, OAuthSystemException {
   
    // Get the user. If the user's credentials are invalid for whatever
    // reason, an exception will be thrown and the page will echo back the
    // reason.
    User user = AuthenticationRequest.getUser(username, password);
   
    // Get the authorization code.
    AuthorizationCode authCode =
      AuthorizationCodeBin.getInstance().getCode(code);
    // If the code is unknown, we cannot redirect back to the third-party
    // because we don't know who they are.
    if(authCode == null) {
      throw new OmhException("The authorization code is unknown.");
    }
   
    // Verify that the code has not yet expired.
    if(System.currentTimeMillis() > authCode.getExpirationTime()) {
      response
        .sendRedirect(
          OAuthASResponse
            .errorResponse(HttpServletResponse.SC_BAD_REQUEST)
            .setError(CodeResponse.ACCESS_DENIED)
            .setErrorDescription("The code has expired.")
            .location(
              authCode
                .getThirdParty().getRedirectUri().toString())
            .setState(authCode.getState())
            .buildQueryMessage()
            .getLocationUri());
      return;
    }
   
    // Get the response if it already exists.
    AuthorizationCodeResponse codeResponse =
      AuthorizationCodeResponseBin.getInstance().getResponse(code);
   
    // If the response does not exist, attempt to create a new one and
    // save it.
    if(codeResponse == null) {
      // Create the new code.
      codeResponse =
        new AuthorizationCodeResponse(authCode, user, granted);
     
      // Store it.
      AuthorizationCodeResponseBin
        .getInstance().storeVerification(codeResponse);
    }
    // Make sure it is being verified by the same user.
    else if(
      ! user
        .getUsername().equals(codeResponse.getOwner().getUsername())) {
     
      response
        .sendRedirect(
          OAuthASResponse
View Full Code Here

   * @see org.openmhealth.reference.request.Request#service()
   */
  @Override
  public void service() throws OmhException {
    // Get the user.
    User user =
      UserBin.getInstance().getUserFromRegistrationId(registrationId);
   
    // Verify that the registration ID returned an actual user.
    if(user == null) {
      throw new OmhException("The registration ID is unknown.");
    }
   
    // Activate the account.
    user.activate();
   
    // Save the account.
    UserBin.getInstance().updateUser(user);
  }
View Full Code Here

    else {
      setServiced();
    }

    // Get the user.
    User user = getUser(username, password);
   
    // Verify that the account is active.
    if(! user.isActivated()) {
      throw new OmhException("The account has not been activated.");
    }
   
    // Create the user's authentication token.
    AuthenticationToken token = new AuthenticationToken(user);
View Full Code Here

    final String username,
    final String password)
    throws OmhException {
   
    // Get the user.
    User user = UserBin.getInstance().getUser(username);
   
    // Make sure the user exists.
    if(user == null) {
      throw
        new InvalidAuthenticationException(
          MESSAGE_AUTHENTICATION_FAILURE);
    }
   
    // Check the password.
    if(! user.checkPassword(password)) {
      throw
        new InvalidAuthenticationException(
          MESSAGE_AUTHENTICATION_FAILURE);
    }
   
View Full Code Here

    }
   
    // Create the new user from the parameters and a random registration
    // ID.
    this.user =
      new User(
        username,
        User.hashPassword(password),
        email,
        createRegistrationId(username, email),
        System.currentTimeMillis(),
View Full Code Here

                final ResultSet resultSet,
                final int rowNum)
                throws SQLException {
               
                return
                  new User(
                    resultSet
                      .getString(User.JSON_KEY_USERNAME),
                    resultSet
                      .getString(User.JSON_KEY_PASSWORD),
                    resultSet
View Full Code Here

                if(resultSet.wasNull()) {
                  dateActivated = null;
                }
               
                return
                  new User(
                    resultSet
                      .getString(User.JSON_KEY_USERNAME),
                    resultSet
                      .getString(User.JSON_KEY_PASSWORD),
                    resultSet
View Full Code Here

TOP

Related Classes of org.openmhealth.reference.domain.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.