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

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


  }

  @Override
  public User[] getAll(Session s) {
    User[] ret = new User[1];
    ret = data.retrieveAll(new User("","","",0)).toArray(ret);
    return ret;
  }
View Full Code Here


  }

  @Override
  public void deleteAll(Session s) {
    logger.log(Level.INFO, "UserManager invoking DeleteAll...");
    data.deleteAll(new User("","","",0));
  }
View Full Code Here

   */
  public User update(Session s, User toUpdate, String changeSet) throws WPISuiteException
  {
    // TODO: permissions checking here

    User changes;

    // Inflate the changeSet into a User object.
    try
    {
      logger.log(Level.FINE, "User update being attempted...");
      changes = User.fromJSON(changeSet);
    }
    catch(JsonParseException e)
    {
      logger.log(Level.WARNING, "UserManager.update() had a failure in the changeset mapper.");

      throw new SerializationException("Error inflating the changeset: " + e.getMessage());
    }

   
    if(s.getUser().getUsername().equals(toUpdate.getUsername()) || s.getUser().getRole().equals(Role.ADMIN))
    {
      // Resolve differences toUpdate using changes, field-by-field.
      toUpdate.setIdNum(changes.getIdNum());
 
      if(changes.getName() != null)
      {
        toUpdate.setName(changes.getName());
      }
 
      //shouldn't be able to change unique identifier
      /*if(changes.getUsername() != null)
      {
        toUpdate.setUserName(changes.getUsername());
      }*/
     
      if(changes.getPassword() != null)
      {
        String encryptedPass = this.passwordHash.generateHash(changes.getPassword());
        toUpdate.setPassword(encryptedPass);
      }
 
      if((changes.getRole() != null))
      {
        if(s.getUser().getRole().equals(Role.ADMIN))
        {
          toUpdate.setRole(changes.getRole());
        }
        else
        {
          logger.log(Level.WARNING,"User: "+s.getUser().getUsername()+" attempted unauthorized priveledge elevation");
        }
View Full Code Here

   */
  public User createAdmin()
  {
    logger.log(Level.INFO, "Adding an admin");

    User p = new User("Admin", "admin", "password", 0);

    try {
      if(getEntity(null,p.getUsername())[0] == null)
      {
        String newPassword = "password";
        String hashedPassword = this.passwordHash.generateHash(newPassword);

        p.setPassword(hashedPassword);
       
        p.setRole(Role.ADMIN);
       
        save(null,p);
      }
      else
      {
        p = getEntity(null,p.getUsername())[0];
      }
    } catch (WPISuiteException e) {
    }

    logger.log(Level.INFO, "Admin creation success!");
View Full Code Here

  String mockSsid;
 
  @Before
  public void setUp() throws Exception {
    mockSsid = "abc123";
    bob = new User("bob", "bob", "1234", 1);
    testProject = new Project("test", "1");
    defaultSession = new Session(bob, testProject, mockSsid);
    defect = new Defect(1, "title", "description", bob);
    goodComment = new Comment(1, bob, "this defect is stupid, and so are you");
   
View Full Code Here

    {
      logger.log(Level.WARNING, "Project Session switch attempted with invalid SSID");
      throw new SessionException("Session matching the givenId does not exist");
    }
   
    User u = current.getUser();
   
    // find the project
    ManagerLayer manager = ManagerLayer.getInstance();
    ProjectManager projects = manager.getProjects();
    Project p = null;
View Full Code Here

  @Test
  public void testSaveandRetrieve() throws WPISuiteException {
    Data db = DataStore.getDataStore();
    User[] arr = new User[1];
    User firstUser = new User("Ryan", "rchamer", "password", 0);
    db.save(firstUser);
    User me = db.retrieve(User.class, "username", "rchamer").toArray(arr)[0];
    assertEquals(me, firstUser);
    db.delete(me);
  }
View Full Code Here

 
  @Test
  public void testDelete() throws WPISuiteException{
    Data db = DataStore.getDataStore();
    User[] arr = new User[1];
    User firstUser = new User("Ryan", "rchamer", "password", 0);
    db.save(firstUser);
    db.delete(firstUser);
    User me = db.retrieve(User.class, "username", "rchamer").toArray(arr)[0];
    assertEquals(me, null);
  }
View Full Code Here

 
  @Test
  public void testUpdate() throws WPISuiteException{
    Data db = DataStore.getDataStore();
    User[] arr = new User[2];
    User firstUser = new User("Ryan", "rchamer", "password", 0);
    db.save(firstUser);
    db.update(User.class, "username", "rchamer", "name", "Mjolnir");
    User Mjolnir = db.retrieve(User.class, "username", "rchamer").toArray(arr)[0];
    assertEquals(firstUser, Mjolnir);
    db.delete(Mjolnir);
   
   
  }
View Full Code Here

  }
 
  @Test
  public void testRetrieveAll(){
    Data db = DataStore.getDataStore();
    User firstUser = new User("Brian", "bgaffey", "password", 0);
    db.save(firstUser);
    User secondUser = new User("Gaffey", "gafftron", "password", 0);
    db.save(secondUser);
    List<User> retrievedList = db.retrieveAll(firstUser);
   
    int initCount = retrievedList.size();
    assertTrue(retrievedList.contains(firstUser));
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.