use of org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testRemoveRolesFromUserUncategorizedUserRoleDaoException.
@Test(expected = UncategorizedUserRoleDaoException.class)
public void testRemoveRolesFromUserUncategorizedUserRoleDaoException() throws UserRoleListService.UnauthorizedException {
String userName = "testUser";
String roleNames = "Power User\tBusiness User\t";
setupMockSessionUser(SESSION_USER_NAME, true);
// Create session that will generate tenant
IPentahoSession session = mock(IPentahoSession.class);
when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn("testTenantPath");
PentahoSessionHolder.setSession(session);
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getUserRoles(any(ITenant.class), anyString())).thenThrow(new UncategorizedUserRoleDaoException("expectedTestException"));
PentahoSystem.registerObject(roleDao);
userRoleService.removeRolesFromUser(userName, roleNames);
}
use of org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testDeleteRoleUncategorizedUserRoleDaoException.
@Test(expected = UncategorizedUserRoleDaoException.class)
public void testDeleteRoleUncategorizedUserRoleDaoException() {
String roles = "role1\trole2\t";
setupMockSessionUser(SESSION_USER_NAME, true);
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getRole(any(ITenant.class), anyString())).thenThrow(new UncategorizedUserRoleDaoException("expectedTestException"));
PentahoSystem.registerObject(roleDao);
userRoleService.deleteRoles(roles);
}
use of org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException in project pentaho-platform by pentaho.
the class UserRoleDaoUserDetailsService method loadUserByUsername.
// ~ Constructors
// ====================================================================================================
// ~ Methods
// =========================================================================================================
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
final boolean ACCOUNT_NON_EXPIRED = true;
final boolean CREDS_NON_EXPIRED = true;
final boolean ACCOUNT_NON_LOCKED = true;
IPentahoUser user;
try {
if (userRoleDao == null) {
userRoleDao = PentahoSystem.get(IUserRoleDao.class, "userRoleDaoProxy", PentahoSessionHolder.getSession());
}
user = userRoleDao.getUser(null, username);
} catch (UncategorizedUserRoleDaoException e) {
throw new UserRoleDaoUserDetailsServiceException(Messages.getInstance().getString("UserRoleDaoUserDetailsService.ERROR_0003_DATA_ACCESS_EXCEPTION"), // $NON-NLS-1$
e);
}
if (user == null) {
throw new UsernameNotFoundException(Messages.getInstance().getString(// $NON-NLS-1$
"UserRoleDaoUserDetailsService.ERROR_0001_USER_NOT_FOUND"));
}
// convert IPentahoUser to a UserDetails instance
List<IPentahoRole> userRoles = userRoleDao.getUserRoles(null, username);
int authsSize = userRoles != null ? userRoles.size() : 0;
GrantedAuthority[] auths = new GrantedAuthority[authsSize];
int i = 0;
for (IPentahoRole role : userRoles) {
auths[i++] = new SimpleGrantedAuthority(role.getName());
}
List<GrantedAuthority> dbAuths = new ArrayList<GrantedAuthority>(Arrays.asList(auths));
addCustomAuthorities(user.getUsername(), dbAuths);
// Store the Tenant ID in the session
IPentahoSession session = PentahoSessionHolder.getSession();
String tenantId = (String) session.getAttribute(IPentahoSession.TENANT_ID_KEY);
if (tenantId == null) {
ITenant tenant = JcrTenantUtils.getTenant(username, true);
session.setAttribute(IPentahoSession.TENANT_ID_KEY, tenant.getId());
}
if (!StringUtils.isEmpty(defaultRoleString)) {
defaultRole = new SimpleGrantedAuthority(defaultRoleString);
}
if (defaultRole != null && !dbAuths.contains(defaultRole)) {
dbAuths.add(defaultRole);
}
if (dbAuths.size() == 0) {
throw new UsernameNotFoundException(Messages.getInstance().getString(// $NON-NLS-1$
"UserRoleDaoUserDetailsService.ERROR_0002_NO_AUTHORITIES"));
}
return new User(user.getUsername(), user.getPassword(), user.isEnabled(), ACCOUNT_NON_EXPIRED, CREDS_NON_EXPIRED, ACCOUNT_NON_LOCKED, dbAuths);
}
Aggregations