use of org.wso2.carbon.user.api.UserRealm in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticator method getUserRealm.
/**
* Get the user realm of the logged in user.
*
* @param username the Username
* @return the userRealm
* @throws AuthenticationFailedException
*/
private UserRealm getUserRealm(String username) throws AuthenticationFailedException {
UserRealm userRealm = null;
try {
if (StringUtils.isNotEmpty(username)) {
String tenantDomain = MultitenantUtils.getTenantDomain(username);
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
RealmService realmService = IdentityTenantUtil.getRealmService();
userRealm = realmService.getTenantUserRealm(tenantId);
}
} catch (UserStoreException e) {
throw new AuthenticationFailedException("Cannot find the user realm. ", e);
}
return userRealm;
}
use of org.wso2.carbon.user.api.UserRealm in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPUtils method getMobileNumberForUsername.
/**
* Get the mobile number for Username.
*
* @param username the username
* @return mobile number
* @throws SMSOTPException
*/
public static String getMobileNumberForUsername(String username) throws SMSOTPException, AuthenticationFailedException {
UserRealm userRealm;
String mobile;
try {
String tenantDomain = MultitenantUtils.getTenantDomain(username);
String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
userRealm = getUserRealm(tenantDomain);
if (userRealm != null) {
mobile = userRealm.getUserStoreManager().getUserClaimValue(tenantAwareUsername, SMSOTPConstants.MOBILE_CLAIM, null);
} else {
throw new SMSOTPException("Cannot find the user realm for the given tenant domain : " + tenantDomain);
}
} catch (UserStoreException e) {
throw new SMSOTPException("Cannot find the user " + username + " to get the mobile number ", e);
}
return mobile;
}
use of org.wso2.carbon.user.api.UserRealm in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPUtils method verifyUserExists.
/**
* Verify whether user Exist in the user store or not.
*
* @param username the Username
* @throws SMSOTPException
*/
public static void verifyUserExists(String username, String tenantDomain) throws SMSOTPException, AuthenticationFailedException {
UserRealm userRealm;
boolean isUserExist = false;
try {
userRealm = SMSOTPUtils.getUserRealm(tenantDomain);
if (userRealm == null) {
throw new SMSOTPException("Super tenant realm not loaded.");
}
UserStoreManager userStoreManager = userRealm.getUserStoreManager();
if (userStoreManager.isExistingUser(username)) {
isUserExist = true;
}
} catch (UserStoreException e) {
throw new SMSOTPException("Error while validating the user.", e);
}
if (!isUserExist) {
if (log.isDebugEnabled()) {
log.debug("User does not exist in the User Store");
}
throw new SMSOTPException("User does not exist in the User Store.");
}
}
use of org.wso2.carbon.user.api.UserRealm in project carbon-business-process by wso2.
the class UserSubstitutionService method isUserAuthorizedForSubstitute.
/**
* Check the logged in user has permission for viewing other substitutions.
* @return true if the permission sufficient
* @throws UserStoreException
*/
private boolean isUserAuthorizedForSubstitute(String username) throws UserStoreException {
UserRealm userRealm = BPMNOSGIService.getUserRealm();
// check with bpmn permission path
String[] permissionArray = userRealm.getAuthorizationManager().getAllowedUIResourcesForUser(username, BPMNConstants.BPMN_PERMISSION_PATH);
if (permissionArray != null && permissionArray.length > 0) {
if (permissionArray[0].equals(BPMNConstants.BPMN_PERMISSION_PATH) || isPermissionExist(permissionArray, BPMNConstants.SUBSTITUTION_PERMISSION_PATH)) {
return true;
}
}
// check for admin permission
String[] adminPermissionArray = userRealm.getAuthorizationManager().getAllowedUIResourcesForUser(username, BPMNConstants.ROOT_PERMISSION_PATH);
if (adminPermissionArray != null && adminPermissionArray.length > 0) {
if (adminPermissionArray[0].equals(BPMNConstants.ROOT_PERMISSION_PATH) || adminPermissionArray[0].equals(BPMNConstants.ADMIN_PERMISSION_PATH)) {
return true;
}
}
return false;
}
use of org.wso2.carbon.user.api.UserRealm in project carbon-business-process by wso2.
the class CommonTaskUtil method getAssignableUserNameList.
/**
* Returns the list of assignable user name list.
*
* @param task : The task object.
* @param excludeActualOwner : Whether to exclude the actual owner from the returned list.
* @return : the list of assignable user name list.
*/
public static List<String> getAssignableUserNameList(TaskDAO task, boolean excludeActualOwner) {
List<String> allPotentialOwners = new ArrayList<String>();
GenericHumanRoleDAO ghr = task.getGenericHumanRole(GenericHumanRole.GenericHumanRoleType.POTENTIAL_OWNERS);
RegistryService registryService = HumanTaskServiceComponent.getRegistryService();
for (OrganizationalEntityDAO orgEntity : ghr.getOrgEntities()) {
if (OrganizationalEntityDAO.OrganizationalEntityType.GROUP.equals(orgEntity.getOrgEntityType())) {
String roleName = orgEntity.getName();
UserRealm userRealm;
try {
userRealm = registryService.getUserRealm(task.getTenantId());
String[] assignableUsersArray = userRealm.getUserStoreManager().getUserListOfRole(roleName);
allPotentialOwners.addAll(Arrays.asList(assignableUsersArray));
} catch (RegistryException e) {
throw new HumanTaskRuntimeException("Cannot locate user realm for tenant id " + task.getTenantId());
} catch (UserStoreException e) {
throw new HumanTaskRuntimeException("Error retrieving the UserStoreManager " + task.getTenantId(), e);
}
} else if (OrganizationalEntityDAO.OrganizationalEntityType.USER.equals(orgEntity.getOrgEntityType())) {
allPotentialOwners.add(orgEntity.getName());
}
}
OrganizationalEntityDAO actualOwner = getActualOwner(task);
if (excludeActualOwner && actualOwner != null) {
allPotentialOwners.remove(actualOwner.getName());
}
return allPotentialOwners;
}
Aggregations