use of org.wso2.carbon.user.core.UserStoreManager 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.core.UserStoreManager in project carbon-business-process by wso2.
the class BPSGroupManagerFactory method openSession.
@Override
public Session openSession() {
try {
RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
UserStoreManager userStoreManager = registryService.getUserRealm(tenantId).getUserStoreManager();
BPSGroupIdentityManager bpsGroupIdentityManager = new BPSGroupIdentityManager(userStoreManager);
return bpsGroupIdentityManager;
} catch (Exception e) {
String msg = "Failed to obtain a group identity manager.";
log.error(msg, e);
return null;
}
}
use of org.wso2.carbon.user.core.UserStoreManager 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;
}
use of org.wso2.carbon.user.core.UserStoreManager in project carbon-apimgt by wso2.
the class DefaultGroupIDExtractorImpl method getGroupingIdentifierList.
@Override
public String[] getGroupingIdentifierList(String loginResponse) {
JSONObject obj;
String username = null;
Boolean isSuperTenant;
int tenantId = MultitenantConstants.SUPER_TENANT_ID;
String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
String claim = config.getFirstProperty(APIConstants.API_STORE_GROUP_EXTRACTOR_CLAIM_URI);
if (StringUtils.isBlank(claim)) {
claim = "http://wso2.org/claims/organization";
}
String organization = null;
String[] groupIdArray = null;
try {
obj = new JSONObject(loginResponse);
username = (String) obj.get("user");
isSuperTenant = (Boolean) obj.get("isSuperTenant");
RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
// if the user is not in the super tenant domain then find the domain name and tenant id.
if (!isSuperTenant) {
tenantDomain = MultitenantUtils.getTenantDomain(username);
tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
}
UserRealm realm = (UserRealm) realmService.getTenantUserRealm(tenantId);
UserStoreManager manager = realm.getUserStoreManager();
organization = manager.getUserClaimValue(MultitenantUtils.getTenantAwareUsername(username), claim, null);
if (organization != null) {
if (organization.contains(",")) {
groupIdArray = organization.split(",");
for (int i = 0; i < groupIdArray.length; i++) {
groupIdArray[i] = groupIdArray[i].toString().trim();
}
} else {
organization = organization.trim();
groupIdArray = new String[] { organization };
}
} else {
// If claim is null then returning a empty string
groupIdArray = new String[] {};
}
} catch (JSONException e) {
log.error("Exception occured while trying to get group Identifier from login response", e);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
log.error("Error while checking user existence for " + username, e);
}
return groupIdArray;
}
use of org.wso2.carbon.user.core.UserStoreManager in project carbon-apimgt by wso2.
the class APIKeyMgtRemoteUserStoreMgtService method authenticate.
/**
* validates a username,password combination. Works for any tenant domain.
* @param username username of the user(including tenant domain)
* @param password password of the user
* @return true if username,password is correct
* @throws APIManagementException
*/
public boolean authenticate(String username, String password) throws APIManagementException {
String tenantDomain = MultitenantUtils.getTenantDomain(username);
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
UserStoreManager userStoreManager;
boolean isAuthenticated = false;
try {
userStoreManager = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager();
String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(username);
isAuthenticated = userStoreManager.authenticate(tenantAwareUserName, password);
} catch (UserStoreException e) {
APIUtil.handleException("Error occurred while validating credentials of user " + username, e);
} finally {
PrivilegedCarbonContext.getThreadLocalCarbonContext().endTenantFlow();
}
return isAuthenticated;
}
Aggregations