.getProfileTestData(),0);
}
public void doUserStuff() throws Exception {
UserStoreManager admin = realm.getUserStoreManager();
Map<String, String> userProps = new HashMap<String, String>();
userProps.put(ClaimTestUtil.CLAIM_URI1, "1claim1Value");
userProps.put(ClaimTestUtil.CLAIM_URI2, "2claim2Value");
Permission[] permisions = new Permission[2];
permisions[0] = new Permission("high security", "read");
permisions[1] = new Permission("low security", "write");
//add USER
admin.addUser("dimuthu", "credential", null, null, null, false);
try{
admin.addUser(null, null, null, null, null, false);
TestCase.assertTrue(false);
}catch(Exception ex){
//expected error
}
try{
admin.addUser("dimuthu", null, null, null, null, false);
TestCase.assertTrue(false);
}catch(Exception ex){
//expected error
}
try{
admin.addUser(null, "credential", null, null, null, false);
TestCase.assertTrue(false);
}catch(Exception ex){
//expected error
}
try{
admin.addUser(" ", "credential", null, null, null, false);
TestCase.assertTrue(false);
}catch(Exception ex){
//expected error
}
try{
admin.addUser("dimuthu", "credential", null, null, null, false);
fail("Exception at adding the same user again");
}catch(Exception ex){
//expected error
}
// add ROLE
admin.addRole("role1", new String[] { "dimuthu" }, permisions);//dimuthu added to the role
try{
admin.addRole(null, null, null);
fail("Exception at defining a roll with No information");
}catch(Exception ex){
//expected error
}
try{
admin.addRole(null, new String[] { "dimuthu" }, permisions);
fail("Exception at adding user to a non specified role");
}catch(Exception ex){
//expected error
}
try{
admin.addRole("role1", new String[] { "isuru" }, permisions);
fail("Exception at adding a non existing user to the role");
}catch(Exception ex){
//expected error
}
//add USER to a ROLE
admin.addUser("vajira", "credential", new String[] { "role1" }, userProps, null, false);
try{
admin.addUser("Bence", "credential", new String[] { "rolexxx" }, userProps, null, false);
fail("Exception at adding user to a Non-existing role");
}catch(Exception ex){
//expected user
}
try{
admin.addUser(null, "credential", new String[] { "role1" }, userProps, null, false);
fail("Exception at adding user to a role with no user name");
}catch(Exception ex){
//expected user
}
try{
admin.addUser("vajira", "credential", new String[] { "role1" }, userProps, null, false);
fail("Exception at adding same user to the same roll");
}catch(Exception ex){
//expected user
}
//Authenticate USER
assertTrue(admin.authenticate("dimuthu", "credential"));
assertFalse(admin.authenticate(null, "credential"));
assertFalse(admin.authenticate("dimuthu",null));
try{
admin.authenticate("dimuthu", 123);
fail("Exception at when Object credential is not an instance of String");
}catch(Exception ex){
//expected user
}
//update by ADMIN
admin.updateCredentialByAdmin("dimuthu", "topsecret");
assertTrue(admin.authenticate("dimuthu", "topsecret"));
//isExistingUser
assertTrue(admin.isExistingUser("dimuthu"));
assertFalse(admin.isExistingUser("muhaha"));
// update by USER
admin.updateCredential("dimuthu", "password", "topsecret");
//assertTrue(admin.authenticate("dimuthu", "password")); //TO DO
assertFalse(admin.authenticate("dimuthu", "credential"));
try{
admin.updateCredential("dimuthu", "password", "xxx");
TestCase.assertTrue(false);
}catch(Exception ex){
//expected exception
}
String[] names = admin.listUsers("*", 100);
assertEquals(3, names.length);
String[] names1 = admin.listUsers("*", 0);
assertEquals(0, names1.length);
String[] names2 = admin.listUsers("*", 2);
assertEquals(2, names2.length);
String[] names3 = admin.listUsers("di?uthu", 100);
assertEquals(1, names3.length);
String[] names4 = admin.listUsers("is?ru", 100);
assertEquals(0, names4.length);
String[] roleNames = admin.getRoleNames();
assertEquals(4, roleNames.length);
// delete
admin.deleteUser("vajira");
assertFalse(admin.isExistingUser("vajira"));
assertFalse(admin.authenticate("vajira", "credential"));
//delete ROLE
admin.addUser("vajira", "credential", new String[] { "role1" }, userProps, null, false);
assertTrue(admin.isExistingUser("vajira"));
admin.deleteRole("role1");
//add role
admin.addRole("role1", new String[] { "dimuthu" }, permisions);
}