if (StringUtils.isEmpty(username)) throw new IllegalArgumentException("username cannot be null or empty");
if (StringUtils.isEmpty(password)) throw new IllegalArgumentException("password cannot be null or empty");
ODatabaseRecordTx db = DbHelper.getConnection();
ODocument profile=null;
UserDao dao = UserDao.getInstance();
try{
//because we have to create an OUser record and a User Object, we need a transaction
DbHelper.requestTransaction();
if (role==null) profile=dao.create(username, password);
else profile=dao.create(username, password,role);
ORID userRid = ((ORID)profile.field("user")).getIdentity();
ORole friendRole=RoleDao.createFriendRole(username);
friendRole.getDocument().field(RoleService.FIELD_ASSIGNABLE,true);
friendRole.getDocument().field(RoleService.FIELD_MODIFIABLE,false);