Package gwtappcontainer.server.apps.security

Examples of gwtappcontainer.server.apps.security.SecurityAPI


  }
 
  @SuppressWarnings("unchecked")
  @Test
  public void getAllRolesTest() {
    SecurityAPI api = new SecurityAPI();
   
    TreeSet<RoleProp> allRoles = (TreeSet<RoleProp>) api.getAllRoles().object;   
    assertTrue(allRoles.size() == 0);
   
    api.addRole("role3", helper.loginAsSuperUser());
    api.addRole("ROLE2", helper.loginAsSuperUser());
    api.addRole("rolE1", helper.loginAsSuperUser());
   
    api.addPrivilege("privilege1", helper.loginAsSuperUser());
    api.addPrivilege("privilege2", helper.loginAsSuperUser());
    api.addPrivilege("privilege3", helper.loginAsSuperUser());
   
    api.assignPrivilegeToRole("role1", "privilege1", helper.loginAsSuperUser());
    api.assignPrivilegeToRole("role1", "privilege2", helper.loginAsSuperUser());
    api.assignPrivilegeToRole("role1", "privilege3", helper.loginAsSuperUser());
   
    api.assignPrivilegeToRole("role2", "privilege1", helper.loginAsSuperUser());
   
    allRoles = (TreeSet<RoleProp>) api.getAllRoles().object;
    assertTrue(allRoles.size() == 3);
    //should be sorted
    List<RoleProp> list = new ArrayList<RoleProp>();
    list.addAll(allRoles);
    assertTrue(list.get(0).role.equals("ROLE1"));
View Full Code Here


  }
 
  @SuppressWarnings("unchecked")
  @Test
  public void assignPrivilegeToRoleTest() {
    SecurityAPI api = new SecurityAPI();
   
    APIResponse response = api.addPrivilege("testprivilege",
        helper.loginWithPrivilege(Privileges.EDIT_PRIVILEGE));
    assertTrue(response.statusCode == Status.SUCCESS);
   
    response = api.addRole("testrole",
        helper.loginWithPrivilege(Privileges.EDIT_ROLE));
    assertTrue(response.statusCode == Status.SUCCESS);
   
    //should have the right privilege to assign
    response = api.assignPrivilegeToRole("testrole",
        "testprivilege", null);
    assertTrue(response.statusCode == Status.ERROR_LOGIN_REQUIRED);
   
    response = api.assignPrivilegeToRole("testrole",
        "testprivilege", helper.loginAsInvalidUser());
    assertTrue(response.statusCode == Status.ERROR_INVALID_USER);
   
    response = api.assignPrivilegeToRole("testrole",
        "testprivilege", helper.loginAsValidUser());
    assertTrue(response.statusCode == Status.ERROR_INSUFFICIENT_PERMISSION);
   
    response = api.assignPrivilegeToRole("testrole",
        "testprivilege", helper.loginWithPrivilege(Privileges.EDIT_ROLE));   
    assertTrue(response.statusCode == Status.SUCCESS);
   
    response = api.getAllRoles();
    TreeSet<RoleProp> allRoles = (TreeSet<RoleProp>) response.object;
    assertTrue(allRoles.first().privileges.contains("TESTPRIVILEGE"));     
   
    //cannot assign non existant privilege/role
    response = api.assignPrivilegeToRole("testrole",
        "non existant privilege", helper.loginWithPrivilege(Privileges.EDIT_ROLE));
    assertTrue(response.statusCode == Status.ERROR_RESOURCE_DOES_NOT_EXIST);
   
    response = api.assignPrivilegeToRole("non existant role",
        "testprivilege", helper.loginWithPrivilege(Privileges.EDIT_ROLE));
    assertTrue(response.statusCode == Status.ERROR_RESOURCE_DOES_NOT_EXIST);
   
    //admin can assign as well
    api.addPrivilege("testprivilege2", helper.loginAsSuperUser());
    response = api.assignPrivilegeToRole("testrole",
        "testprivilege2", helper.loginAsSuperUser());
    assertTrue(response.statusCode == Status.SUCCESS);
   
    response = api.getAllRoles();
    allRoles = (TreeSet<RoleProp>) response.object;
    assertTrue(allRoles.first().privileges.contains("TESTPRIVILEGE2"));
   
  }
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  @Test
  public void unassignPrivilegeToRoleTest() {
    SecurityAPI api = new SecurityAPI();
   
    APIResponse response = api.addPrivilege("testprivilege",
        helper.loginWithPrivilege(Privileges.EDIT_PRIVILEGE));
    assertTrue(response.statusCode == Status.SUCCESS);
   
    response = api.addRole("testrole",
        helper.loginWithPrivilege(Privileges.EDIT_ROLE));
    assertTrue(response.statusCode == Status.SUCCESS);
   
    //should have the right privilege to assign
    response = api.assignPrivilegeToRole("testrole",
        "testprivilege", helper.loginAsSuperUser());
    assertTrue(response.statusCode == Status.SUCCESS);
   
    response = api.unassignPrivilegeToRole("testrole",
        "testprivilege", helper.loginAsInvalidUser());
    assertTrue(response.statusCode == Status.ERROR_INVALID_USER);
   
    response = api.unassignPrivilegeToRole("testrole",
        "testprivilege", helper.loginAsValidUser());
    assertTrue(response.statusCode == Status.ERROR_INSUFFICIENT_PERMISSION);
   
    response = api.unassignPrivilegeToRole("testrole",
        "testprivilege", helper.loginWithPrivilege(Privileges.EDIT_ROLE));   
    assertTrue(response.statusCode == Status.SUCCESS);
   
    response = api.getAllRoles();
    TreeSet<RoleProp> allRoles = (TreeSet<RoleProp>) response.object;
    assertTrue(! allRoles.first().privileges.contains("TESTPRIVILEGE"))
   
    //admin can unassign as well
    response = api.unassignPrivilegeToRole("testrole",
        "testprivilege", helper.loginAsSuperUser());     
    assertTrue(response.statusCode == Status.SUCCESS);     
  }
View Full Code Here

    assertTrue(response.statusCode == Status.SUCCESS);     
  }
 
  @Test
  public void addUserTest() {
    SecurityAPI api = new SecurityAPI();
   
    //should have the right privilege
    APIResponse response = api.addUser("test@Test.com", null);
    assertTrue(response.statusCode == Status.ERROR_LOGIN_REQUIRED);
   
    response = api.addUser("test@Test.com", helper.loginAsInvalidUser());
    assertTrue(response.statusCode == Status.ERROR_INVALID_USER);
   
    response = api.addUser("test@Test.com", helper.loginAsValidUser());
    assertTrue(response.statusCode == Status.ERROR_INSUFFICIENT_PERMISSION);
   
    response = api.addUser("test@Test.com",
        helper.loginWithPrivilege(Privileges.EDIT_USER));   
    assertTrue(response.statusCode == Status.SUCCESS);
   
    response = api.getUser("TEST@tESt.com");
    UserProp userProp = (UserProp) response.object;
    assertTrue(userProp.email.equals("test@test.com"));
       
    //adding the same user again should give correct error
    response = api.addUser("test@TEST.COM",
        helper.loginWithPrivilege(Privileges.EDIT_USER));   
    assertTrue(response.statusCode == Status.ERROR_RESOURCE_ALREADY_EXISTS);
       
    //admin can add as well
    response = api.addUser("test2@test.com", helper.loginAsSuperUser());
    assertTrue(response.statusCode == Status.SUCCESS);
    response = api.getAllUsers();

    response = api.getUser("test2@test.com");
    userProp = (UserProp) response.object;
    assertTrue(response.statusCode == Status.SUCCESS);
    assertTrue(userProp.email.equals("test2@test.com"));
  }
View Full Code Here

    assertTrue(userProp.email.equals("test2@test.com"));
  }
 
  @Test
  public void deleteUserTest() {
    SecurityAPI api = new SecurityAPI();
   
    //should have the right privilege
    APIResponse response = api.addUser("test@Test.com",
        helper.loginAsSuperUser());
    assertTrue(response.statusCode == Status.SUCCESS);   
   
    assertTrue(api.getUser("test@test.com").object != null);   
   
    response = api.deleteUser("test@Test.com", helper.loginAsInvalidUser());
    assertTrue(response.statusCode == Status.ERROR_INVALID_USER);
   
    response = api.deleteUser("test@Test.com", helper.loginAsValidUser());
    assertTrue(response.statusCode == Status.ERROR_INSUFFICIENT_PERMISSION);
   
    response = api.deleteUser("test@Test.com",
        helper.loginWithPrivilege(Privileges.EDIT_USER));   
    assertTrue(response.statusCode == Status.SUCCESS);
   
    assertTrue(api.getUser("test@test.com").object == null);
       
    //admin can delete as well
    //first add and then delete
    response = api.addUser("test2@Test.com", helper.loginAsSuperUser());

    response = api.deleteUser("test2@test.com", helper.loginAsSuperUser());
    assertTrue(api.getUser("test@test.com").object == null)
  }
View Full Code Here

    assertTrue(api.getUser("test@test.com").object == null)
  }
 
  @Test
  public void getUserTest() {
    SecurityAPI api = new SecurityAPI();
   
    assertTrue(api.getUser("test@test.com").object == null);
   
    api.addUser("test@test.com", helper.loginAsSuperUser());
    api.addPrivilege("privilege1", helper.loginAsSuperUser());
    api.addPrivilege("privilege2", helper.loginAsSuperUser());
   
    api.addRole("role1", helper.loginAsSuperUser());
    api.assignPrivilegeToRole("role1", "privilege1", helper.loginAsSuperUser());
   
    api.assignPrivilegeToUser("test@test.com", "privilege2", helper.loginAsSuperUser());
    api.assignRoleToUser("test@test.com", "role1", helper.loginAsSuperUser());
       
    UserProp userProp = (UserProp) api.getUser("test@test.com").object;
    assertTrue(userProp.email.equals("test@test.com"));   
    assertTrue(userProp.privileges.contains("PRIVILEGE2"));
    assertTrue(userProp.roles.first().role.equals("ROLE1"));
    assertTrue(userProp.roles.first().privileges.contains("PRIVILEGE1"));       
  }
View Full Code Here

    assertTrue(userProp.roles.first().privileges.contains("PRIVILEGE1"));       
  }
 
  @Test
  public void getAllUsersTest() {
    SecurityAPI api = new SecurityAPI();
   
    api.addUser("sathya@test.com", helper.loginAsSuperUser());
    api.addUser("SOWMYA@test.com", helper.loginAsSuperUser());
    api.addUser("thilaKan@test.com", helper.loginAsSuperUser());
    api.addUser("Hema@test.com", helper.loginAsSuperUser());
       
    APIResponse response = api.getAllUsers();
    assertTrue(response.statusCode == Status.SUCCESS);
    @SuppressWarnings("unchecked")
    TreeSet<UserProp> all = (TreeSet<UserProp>) response.object;
   
    assertTrue(all.size() == 4);   
View Full Code Here

    assertTrue(list.get(3).email.equals("thilakan@test.com"));
  }
 
  @Test
  public void assignRoleToUserTest() {
    SecurityAPI api = new SecurityAPI();
    api.addUser("test@test.com", helper.loginAsSuperUser());
   
    api.addRole("role1", helper.loginAsSuperUser());
    api.addPrivilege("privilege1", helper.loginAsSuperUser());
   
    api.assignPrivilegeToRole("role1", "privilege1", helper.loginAsSuperUser());
   
    APIResponse response = api.assignRoleToUser("test@test.com", "role1", null);
    assertTrue(response.statusCode == Status.ERROR_LOGIN_REQUIRED);
   
    response = api.assignRoleToUser("test@test.com", "role1",
        helper.loginAsInvalidUser());
    assertTrue(response.statusCode == Status.ERROR_INVALID_USER);
   
    response = api.assignRoleToUser("test@test.com", "role1",
        helper.loginAsValidUser());
    assertTrue(response.statusCode == Status.ERROR_INSUFFICIENT_PERMISSION);
   
    response = api.assignRoleToUser("test@test.com", "role1",
        helper.loginWithPrivilege(Privileges.EDIT_USER));
    assertTrue(response.statusCode == Status.SUCCESS);
   
    UserProp userProp = (UserProp) api.getUser("test@test.com").object;
    assertTrue(userProp.email.equals("test@test.com"));
    assertTrue(userProp.roles.first().role.equals("ROLE1"));
    assertTrue(userProp.roles.first().privileges.contains("PRIVILEGE1"));
  }
View Full Code Here

    assertTrue(userProp.roles.first().privileges.contains("PRIVILEGE1"));
  }
 
  @Test
  public void unassignRoleToUserTest() {
    SecurityAPI api = new SecurityAPI();
    api.addUser("test@test.com", helper.loginAsSuperUser());
   
    api.addRole("role1", helper.loginAsSuperUser());
    api.addRole("role2", helper.loginAsSuperUser());
    api.addPrivilege("privilege1", helper.loginAsSuperUser());
   
    api.assignPrivilegeToRole("role1", "privilege1", helper.loginAsSuperUser());
   
    api.assignRoleToUser("test@test.com", "role1", helper.loginAsSuperUser());
    api.assignRoleToUser("test@test.com", "role2", helper.loginAsSuperUser());
   
    APIResponse response = api.unassignRoleToUser("test@test.com", "role2", null);   
    assertTrue(response.statusCode == Status.ERROR_LOGIN_REQUIRED);
   
    response = api.unassignRoleToUser("test@test.com", "role2",
        helper.loginAsInvalidUser());   
    assertTrue(response.statusCode == Status.ERROR_INVALID_USER);
   
    response = api.unassignRoleToUser("test@test.com", "role2",
        helper.loginWithPrivilege(Privileges.EDIT_USER));   
    assertTrue(response.statusCode == Status.SUCCESS);
   
    UserProp userProp = (UserProp) api.getUser("test@test.com").object;
    assertTrue(userProp.roles.size() == 1);
    assertTrue(userProp.roles.first().role.equals("ROLE1"));
           
    //admin can also unassign
    response = api.unassignRoleToUser("test@test.com", "role1",
        helper.loginAsSuperUser());   
    assertTrue(response.statusCode == Status.SUCCESS);
   
    userProp = (UserProp) api.getUser("test@test.com").object;
    assertTrue(userProp.roles.size() == 0);       
  }
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  @Test
  public void addPrivilegeTest() {
    SecurityAPI api = new SecurityAPI();
   
    //should have the right privilege
    APIResponse response = api.addPrivilege("test", null);
    assertTrue(response.statusCode == Status.ERROR_LOGIN_REQUIRED);
   
    response = api.addPrivilege("test", helper.loginAsInvalidUser());
    assertTrue(response.statusCode == Status.ERROR_INVALID_USER);
   
    response = api.addPrivilege("test", helper.loginAsValidUser());
    assertTrue(response.statusCode == Status.ERROR_INSUFFICIENT_PERMISSION);
   
    response = api.addPrivilege("test",
        helper.loginWithPrivilege(Privileges.EDIT_PRIVILEGE));
    assertTrue(response.statusCode == Status.SUCCESS);
    response = api.getAllPrivileges();
    TreeSet<String> all = (TreeSet<String>) response.object;
    assertTrue(all.contains("TEST"));
   
    //adding the same privilege again should give correct error
    response = api.addPrivilege("test",
        helper.loginWithPrivilege(Privileges.EDIT_PRIVILEGE));   
    assertTrue(response.statusCode == Status.ERROR_RESOURCE_ALREADY_EXISTS);
       
    //admin can add as well
    response = api.addPrivilege("test2", helper.loginAsSuperUser());
    assertTrue(response.statusCode == Status.SUCCESS);
    response = api.getAllPrivileges();

    all = (TreeSet<String>) response.object;
    assertTrue(all.contains("TEST2"))
  }
View Full Code Here

TOP

Related Classes of gwtappcontainer.server.apps.security.SecurityAPI

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.