Package edu.wpi.cs.wpisuitetng.modules.core.models

Examples of edu.wpi.cs.wpisuitetng.modules.core.models.User


  public void deserializeUserMissingFields()
  {
    String jsonUser ="{\"username\":\"Tyler\", \"idNum\":2}";
    Gson deserializer = this.gson.create();
   
    User inflated = deserializer.fromJson(jsonUser, User.class);
   
    assertEquals(2, inflated.getIdNum());
    assertTrue(inflated.getUsername().equals("Tyler"));
   
    assertFalse(inflated.matchPassword(null));
  }
View Full Code Here


  public void deserializeUserMissingId()
  {
    String jsonUser ="{\"name\":\"Tyler\", \"idNum\":2, \"password\":\"abcde\"}";
    Gson deserializer = this.gson.create();
   
    User inflated = deserializer.fromJson(jsonUser, User.class); // exception expected.
   
    fail("exception not thrown");
  }
View Full Code Here

    this.sessions = man.getSessions();
   
    // add the test user to the database
    DataStore db = DataStore.getDataStore();
    String hashedPassword = new Sha256Password().generateHash("jayms");
    this.u = new User("Tyler", "twack", hashedPassword, 5);
    db.save(this.u);
  }
View Full Code Here

    } catch (NotFoundException e) {
      logger.log(Level.WARNING, "Login attempted with non-existant user <" + credentials[0] + ">");
      throw new AuthenticationException("The user \"" + credentials[0] + "\" could not be found. Please check if the username was spelled correctly.");
    }

    User user = u[0];
   
    // check password
    System.out.println("DEBUG: Authenticate Password");
    // password security
    logger.log(Level.INFO, "Authenticating password for User <" + credentials[0] + ">...");
    String hashedPassword = this.passwordHash.generateHash(credentials[1]);
    if(!user.matchPassword(hashedPassword))
    {
      logger.log(Level.WARNING, "Login attempted with bad password for User <" + credentials[0] + ">");
      throw new AuthenticationException("An invalid password was given. Please check the password and try again.");
    }
    logger.log(Level.INFO, "Password authentication Success! <" + credentials[0] + ">");
View Full Code Here

    return this.getEntity(s, s.getProject().getIdNum())[0].toJSON();
  }

  @Override
  public Project makeEntity(Session s, String content) throws WPISuiteException
    User theUser = s.getUser();
   
    logger.log(Level.FINER, "Attempting new Project creation...");
   
    Project p;
    try{
      p = Project.fromJSON(content);
    } catch(JsonSyntaxException e){
      logger.log(Level.WARNING, "Invalid Project entity creation string.");
      throw new BadRequestException("The entity creation string had invalid format. Entity String: " + content);
    }
   
    
    logger.log(Level.FINE, "New project: "+ p.getName() +" submitted by: "+ theUser.getName() );
    p.setOwner(theUser);
   
    if(getEntity(s,p.getIdNum())[0] == null)
    {
      if(getEntityByName(s, p.getName())[0] == null)
View Full Code Here

  public boolean deleteEntity(Session s1, String id) throws WPISuiteException
  {
    if(s1==null){
      throw new WPISuiteException("Null Session.");
    }
    User theUser = s1.getUser();
    Project[] model = this.getEntity(id);
    if(model[0].getPermission(theUser).equals(Permission.WRITE) ||
       theUser.getRole().equals(Role.ADMIN)){
      Model m = data.delete(data.retrieve(project, "idNum", id).get(0));
      logger.log(Level.INFO, "ProjectManager deleting project <" + id + ">");
     
      return (m != null) ? true : false;
    }
View Full Code Here

    }
  }
 
  @Override
  public void deleteAll(Session s) throws WPISuiteException {
    User theUser = s.getUser();
    logger.log(Level.INFO, "ProjectManager invoking DeleteAll...");
    if(theUser.getRole().equals(Role.ADMIN)){
    data.deleteAll(new Project("",""));
    }
    else
    {
      logger.log(Level.WARNING, "ProjectManager DeleteAll attempted by user with insufficient permission");
View Full Code Here

  {
    if(s == null){
      throw new WPISuiteException("Null session.");
    }
   
    User theUser = s.getUser();
    if(theUser.equals(toUpdate.getOwner()) ||
       theUser.getRole().equals(Role.ADMIN)){
   
      // convert updateString into a Map, then load into the User
      try
      {
        logger.log(Level.FINE, "Project update being attempted...");
View Full Code Here

        String newDesc = context.deserialize(descriptionObj.get("newValue"), String.class);
        changesMap.put("description", new FieldChange<String>(oldDesc, newDesc));
      }
      if (changes.has("assignee")) {
        JsonObject assigneeObj = changes.get("assignee").getAsJsonObject();
        User oldUser = context.deserialize(assigneeObj.get("oldValue"), User.class);
        User newUser = context.deserialize(assigneeObj.get("newValue"), User.class);
        changesMap.put("assignee", new FieldChange<User>(oldUser, newUser));
      }
      if (changes.has("tags")) {
        JsonObject tagsObj = changes.get("tags").getAsJsonObject();
        Tag[] oldTags = context.deserialize(tagsObj.get("oldValue"), Tag[].class);
View Full Code Here

    //TODO: create a custom de-serializer & serializer so we can hash the desired password & remove it from others.
   
    logger.log(Level.FINE, "Attempting new User creation...");

    User p;
    try{
      p = User.fromJSON(content);
    } catch(JsonSyntaxException e){
      logger.log(Level.WARNING, "Invalid User entity creation string.");
      throw new BadRequestException("The entity creation string had invalid format. Entity String: " + content);
    }

    if(getEntity(s,p.getUsername())[0] == null)
    {
      String newPassword = UserDeserializer.parsePassword(content);
      String hashedPassword = this.passwordHash.generateHash(newPassword);

      p.setPassword(hashedPassword);
     
      p.setRole(Role.USER);
     
      save(s,p);
    }
    else
    {
View Full Code Here

TOP

Related Classes of edu.wpi.cs.wpisuitetng.modules.core.models.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.