本文整理汇总了Java中org.wso2.carbon.user.api.UserStoreManager.isExistingUser方法的典型用法代码示例。如果您正苦于以下问题:Java UserStoreManager.isExistingUser方法的具体用法?Java UserStoreManager.isExistingUser怎么用?Java UserStoreManager.isExistingUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wso2.carbon.user.api.UserStoreManager
的用法示例。
在下文中一共展示了UserStoreManager.isExistingUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyUserExists
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
/**
* 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.");
}
}
示例2: isUserExists
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
@GET
@Path("/checkUser")
@Override
public Response isUserExists(@QueryParam("username") String userName) {
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (userStoreManager.isExistingUser(userName)) {
return Response.status(Response.Status.OK).entity(true).build();
} else {
return Response.status(Response.Status.OK).entity(false).build();
}
} catch (UserStoreException e) {
String msg = "Error while retrieving the user.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
示例3: lockUserAccount
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
/**
* Locks the user account.
*
* @param userName
* @param userStoreManager
* @throws IdentityException
*/
public static void lockUserAccount(String userName, UserStoreManager userStoreManager)
throws IdentityException {
if (!isIdentityMgtListenerEnable()) {
throw IdentityException.error("Cannot lock account, IdentityMgtEventListener is not enabled.");
}
String domainName = ((org.wso2.carbon.user.core.UserStoreManager) userStoreManager).getRealmConfiguration().
getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
userName = UserCoreUtil.addDomainToName(userName, domainName);
try {
if (!userStoreManager.isExistingUser(userName)) {
log.error("User " + userName + " does not exist in tenant " + userStoreManager.getTenantId());
throw IdentityException.error("No user account found for user " + userName);
}
} catch (UserStoreException e) {
log.error("Error while reading user identity data", e);
throw IdentityException.error("Error while lock user account : " + userName);
}
UserIdentityDataStore store = IdentityMgtConfig.getInstance().getIdentityDataStore();
UserIdentityClaimsDO userIdentityDO = store.load(UserCoreUtil.removeDomainFromName(userName), userStoreManager);
if (userIdentityDO != null) {
userIdentityDO.getUserDataMap().put(UserIdentityDataStore.ACCOUNT_LOCKED_REASON,
IdentityMgtConstants.LockedReason.ADMIN_INITIATED.toString());
userIdentityDO.setAccountLock(true);
userIdentityDO.setUnlockTime(0);
store.store(userIdentityDO, userStoreManager);
} else {
throw IdentityException.error("No user account found for user " + userName);
}
}
示例4: disableUserAccount
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
/**
* Disable the user account.
*
* @param userName
* @param userStoreManager
* @throws IdentityException
*/
public static void disableUserAccount(String userName, UserStoreManager userStoreManager)
throws IdentityException {
if (!isIdentityMgtListenerEnable()) {
throw IdentityException.error("Cannot lock account, IdentityMgtEventListener is not enabled.");
}
String domainName = ((org.wso2.carbon.user.core.UserStoreManager) userStoreManager).getRealmConfiguration().
getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
userName = UserCoreUtil.addDomainToName(userName, domainName);
try {
if (!userStoreManager.isExistingUser(userName)) {
log.error("User " + userName + " does not exist in tenant " + userStoreManager.getTenantId());
throw IdentityException.error("No user account found for user " + userName + "to disable");
}
} catch (UserStoreException e) {
log.error("Error while reading user identity data", e);
throw IdentityException.error("Error while disabling user account : " + userName);
}
UserIdentityDataStore store = IdentityMgtConfig.getInstance().getIdentityDataStore();
UserIdentityClaimsDO userIdentityDO = store.load(UserCoreUtil.removeDomainFromName(userName), userStoreManager);
if (userIdentityDO != null) {
userIdentityDO.setAccountDisabled(true);
store.store(userIdentityDO, userStoreManager);
} else {
throw IdentityException.error("No user account found for user " + userName);
}
}
示例5: enableUserAccount
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
/**
* Enable the user account
*
* @param userName
* @param userStoreManager
* @throws IdentityException
*/
public static void enableUserAccount(String userName, UserStoreManager userStoreManager)
throws IdentityException {
if (!isIdentityMgtListenerEnable()) {
throw IdentityException.error("Cannot enable account, IdentityMgtEventListener is not enabled.");
}
String domainName = ((org.wso2.carbon.user.core.UserStoreManager) userStoreManager).getRealmConfiguration().
getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
userName = UserCoreUtil.addDomainToName(userName, domainName);
try {
if (!userStoreManager.isExistingUser(userName)) {
log.error("User " + userName + " does not exist in tenant " + userStoreManager.getTenantId());
throw IdentityException.error("No user account found for user " + userName + "to enable");
}
} catch (UserStoreException e) {
log.error("Error while reading user identity data", e);
throw IdentityException.error("Error while enabling user account " + userName);
}
UserIdentityDataStore store = IdentityMgtConfig.getInstance().getIdentityDataStore();
UserIdentityClaimsDO userIdentityDO = store.load(UserCoreUtil.removeDomainFromName(userName), userStoreManager);
if (userIdentityDO != null) {
userIdentityDO.setAccountDisabled(false);
store.store(userIdentityDO, userStoreManager);
} else {
throw IdentityException.error("No user account found for user " + userName);
}
}
示例6: unlockUserAccount
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
/**
* Unlocks the user account
*
* @param userName
* @param userStoreManager
* @throws IdentityException
*/
public static void unlockUserAccount(String userName, UserStoreManager userStoreManager)
throws IdentityException {
if (!isIdentityMgtListenerEnable()) {
throw IdentityException.error("Cannot unlock account, IdentityMgtEventListener is not enabled.");
}
String domainName = ((org.wso2.carbon.user.core.UserStoreManager) userStoreManager).getRealmConfiguration().
getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
userName = UserCoreUtil.addDomainToName(userName, domainName);
try {
if (!userStoreManager.isExistingUser(userName)) {
log.error("User " + userName + " does not exist in tenant " + userStoreManager.getTenantId());
throw IdentityException.error("No user account found for user " + userName);
}
} catch (UserStoreException e) {
log.error("Error while reading user identity data", e);
throw IdentityException.error("Error while unlock user account " + userName);
}
UserIdentityDataStore store = IdentityMgtConfig.getInstance().getIdentityDataStore();
UserIdentityClaimsDO userIdentityDO = store.load(UserCoreUtil.removeDomainFromName(userName), userStoreManager);
if (userIdentityDO != null) {
userIdentityDO.getUserDataMap().put(UserIdentityDataStore.ACCOUNT_LOCKED_REASON, null);
userIdentityDO.setAccountLock(false);
userIdentityDO.setUnlockTime(0);
store.store(userIdentityDO, userStoreManager);
} else {
throw IdentityException.error("No user account found for user " + userName);
}
}
示例7: getUser
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
@GET
@Path("/{username}")
@Override
public Response getUser(@PathParam("username") String username, @QueryParam("domain") String domain,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
if (domain != null && !domain.isEmpty()) {
username = domain + '/' + username;
}
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (!userStoreManager.isExistingUser(username)) {
if (log.isDebugEnabled()) {
log.debug("User by username: " + username + " does not exist.");
}
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(
"User doesn't exist.").build()).build();
}
BasicUserInfo user = this.getBasicUserInfo(username);
return Response.status(Response.Status.OK).entity(user).build();
} catch (UserStoreException e) {
String msg = "Error occurred while retrieving information of the user '" + username + "'";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}
示例8: removeUser
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
@DELETE
@Path("/{username}")
@Override
public Response removeUser(@PathParam("username") String username, @QueryParam("domain") String domain) {
if (domain != null && !domain.isEmpty()) {
username = domain + '/' + username;
}
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (!userStoreManager.isExistingUser(username)) {
if (log.isDebugEnabled()) {
log.debug("User by username: " + username + " does not exist for removal.");
}
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("User '" +
username + "' does not exist for removal.").build()).build();
}
// Un-enroll all devices for the user
DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService();
deviceManagementService.setStatus(username, EnrolmentInfo.Status.REMOVED);
userStoreManager.deleteUser(username);
if (log.isDebugEnabled()) {
log.debug("User '" + username + "' was successfully removed.");
}
return Response.status(Response.Status.OK).build();
} catch (DeviceManagementException | UserStoreException e) {
String msg = "Exception in trying to remove user by username: " + username;
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}
示例9: getRolesOfUser
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
@GET
@Path("/{username}/roles")
@Override
public Response getRolesOfUser(@PathParam("username") String username, @QueryParam("domain") String domain) {
if (domain != null && !domain.isEmpty()) {
username = domain + '/' + username;
}
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (!userStoreManager.isExistingUser(username)) {
if (log.isDebugEnabled()) {
log.debug("User by username: " + username + " does not exist for role retrieval.");
}
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " + username +
" does not exist for role retrieval.").build()).build();
}
RoleList result = new RoleList();
result.setList(getFilteredRoles(userStoreManager, username));
return Response.status(Response.Status.OK).entity(result).build();
} catch (UserStoreException e) {
String msg = "Error occurred while trying to retrieve roles of the user '" + username + "'";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}
示例10: lockUserAccount
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
/**
* Locks the user account.
*
* @param userName
* @param userStoreManager
* @throws IdentityException
*/
public static void lockUserAccount(String userName, UserStoreManager userStoreManager)
throws IdentityException {
if (!isIdentityMgtListenerEnable()) {
throw IdentityException.error("Cannot lock account, IdentityMgtEventListener is not enabled.");
}
String domainName = ((org.wso2.carbon.user.core.UserStoreManager) userStoreManager).getRealmConfiguration().
getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
userName = UserCoreUtil.addDomainToName(userName, domainName);
try {
if (!userStoreManager.isExistingUser(userName)) {
log.error("User " + userName + " does not exist in tenant "+userStoreManager.getTenantId());
throw IdentityException.error("No user account found for user " + userName);
}
} catch (UserStoreException e) {
log.error("Error while reading user identity data", e);
throw IdentityException.error("Error while lock user account : " + userName);
}
UserIdentityDataStore store = IdentityMgtConfig.getInstance().getIdentityDataStore();
UserIdentityClaimsDO userIdentityDO = store.load(UserCoreUtil.removeDomainFromName(userName), userStoreManager);
if (userIdentityDO != null) {
userIdentityDO.setAccountLock(true);
userIdentityDO.setUnlockTime(0);
store.store(userIdentityDO, userStoreManager);
} else {
throw IdentityException.error("No user account found for user " + userName);
}
}
示例11: unlockUserAccount
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
/**
* Unlocks the user account
*
* @param userName
* @param userStoreManager
* @throws IdentityException
*/
public static void unlockUserAccount(String userName, UserStoreManager userStoreManager)
throws IdentityException {
if (!isIdentityMgtListenerEnable()) {
throw IdentityException.error("Cannot unlock account, IdentityMgtEventListener is not enabled.");
}
String domainName = ((org.wso2.carbon.user.core.UserStoreManager) userStoreManager).getRealmConfiguration().
getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
userName = UserCoreUtil.addDomainToName(userName, domainName);
try {
if (!userStoreManager.isExistingUser(userName)) {
log.error("User " + userName + " does not exist in tenant "+userStoreManager.getTenantId());
throw IdentityException.error("No user account found for user " + userName);
}
} catch (UserStoreException e) {
log.error("Error while reading user identity data", e);
throw IdentityException.error("Error while unlock user account " + userName);
}
UserIdentityDataStore store = IdentityMgtConfig.getInstance().getIdentityDataStore();
UserIdentityClaimsDO userIdentityDO = store.load(UserCoreUtil.removeDomainFromName(userName), userStoreManager);
if (userIdentityDO != null) {
userIdentityDO.setAccountLock(false);
userIdentityDO.setUnlockTime(0);
store.store(userIdentityDO, userStoreManager);
} else {
throw IdentityException.error("No user account found for user " + userName);
}
}
示例12: verifyUserForRecovery
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
/**
* Verifies user id with underline user store
*
* @param sequence TODO
* @param userDTO bean class that contains user and tenant Information
* @return true/false whether user is verified or not. If user is a tenant
* user then always return false
*/
public VerificationBean verifyUserForRecovery(int sequence, UserDTO userDTO) {
String userId = userDTO.getUserId();
int tenantId = userDTO.getTenantId();
boolean success = false;
VerificationBean bean = null;
try {
UserStoreManager userStoreManager = IdentityMgtServiceComponent.getRealmService().
getTenantUserRealm(tenantId).getUserStoreManager();
if (userStoreManager.isExistingUser(userId)) {
if (IdentityMgtConfig.getInstance().isAuthPolicyAccountLockCheck()) {
String accountLock = Utils.getClaimFromUserStoreManager(
userId, tenantId, UserIdentityDataStore.ACCOUNT_LOCK);
if (!Boolean.parseBoolean(accountLock)) {
success = true;
} else {
//account is Locked. Not allowing to recover.
}
} else if (IdentityMgtConfig.getInstance().isAuthPolicyAccountDisableCheck()) {
String accountDisable = Utils.getClaimFromUserStoreManager(
userId, tenantId, UserIdentityDataStore.ACCOUNT_DISABLED);
if (!Boolean.parseBoolean(accountDisable)) {
success = true;
} else {
//account is Disabled. Not allowing to recover.
if (log.isDebugEnabled()) {
log.debug("Account is disabled. Can not allow to recover.");
}
bean = new VerificationBean(VerificationBean.ERROR_CODE_DISABLED_ACCOUNT);
}
} else {
success = true;
}
} else {
log.error("User with user name : " + userId
+ " does not exists in tenant domain : " + userDTO.getTenantDomain());
bean = new VerificationBean(VerificationBean.ERROR_CODE_INVALID_USER + " "
+ "User does not exists");
}
if (success) {
String internalCode = generateUserCode(sequence, userId);
String key = UUID.randomUUID().toString();
UserRecoveryDataDO dataDO =
new UserRecoveryDataDO(userId, tenantId, internalCode, key);
if (sequence != 3) {
dataStore.invalidate(userId, tenantId);
}
dataStore.store(dataDO);
log.info("User verification successful for user : " + userId +
" from tenant domain :" + userDTO.getTenantDomain());
bean = new VerificationBean(userId, getUserExternalCodeStr(internalCode));
}
} catch (Exception e) {
String errorMessage = "Error verifying user : " + userId;
log.error(errorMessage, e);
bean = new VerificationBean(VerificationBean.ERROR_CODE_UNEXPECTED + " "
+ errorMessage);
}
if (bean == null) {
bean = new VerificationBean(VerificationBean.ERROR_CODE_UNEXPECTED);
}
return bean;
}
示例13: updateUser
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
@PUT
@Path("/{username}")
@Override
public Response updateUser(@PathParam("username") String username, @QueryParam("domain") String domain, UserInfo userInfo) {
if (domain != null && !domain.isEmpty()) {
username = domain + '/' + username;
}
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (!userStoreManager.isExistingUser(username)) {
if (log.isDebugEnabled()) {
log.debug("User by username: " + username +
" doesn't exists. Therefore, request made to update user was refused.");
}
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " +
username + " doesn't exist.").build()).build();
}
Map<String, String> defaultUserClaims =
this.buildDefaultUserClaims(userInfo.getFirstname(), userInfo.getLastname(),
userInfo.getEmailAddress());
if (StringUtils.isNotEmpty(userInfo.getPassword())) {
// Decoding Base64 encoded password
userStoreManager.updateCredentialByAdmin(username,
userInfo.getPassword());
log.debug("User credential of username: " + username + " has been changed");
}
List<String> currentRoles = this.getFilteredRoles(userStoreManager, username);
List<String> newRoles = new ArrayList<>();
if (userInfo.getRoles() != null) {
newRoles = Arrays.asList(userInfo.getRoles());
}
List<String> rolesToAdd = new ArrayList<>(newRoles);
List<String> rolesToDelete = new ArrayList<>();
for (String role : currentRoles) {
if (newRoles.contains(role)) {
rolesToAdd.remove(role);
} else {
rolesToDelete.add(role);
}
}
rolesToDelete.remove(ROLE_EVERYONE);
rolesToAdd.remove(ROLE_EVERYONE);
userStoreManager.updateRoleListOfUser(username,
rolesToDelete.toArray(new String[rolesToDelete.size()]),
rolesToAdd.toArray(new String[rolesToAdd.size()]));
userStoreManager.setUserClaimValues(username, defaultUserClaims, null);
// Outputting debug message upon successful addition of user
if (log.isDebugEnabled()) {
log.debug("User by username: " + username + " was successfully updated.");
}
BasicUserInfo updatedUserInfo = this.getBasicUserInfo(username);
return Response.ok().entity(updatedUserInfo).build();
} catch (UserStoreException e) {
String msg = "Error occurred while trying to update user '" + username + "'";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}
示例14: verifyUserForRecovery
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
/**
* Verifies user id with underline user store
*
* @param sequence TODO
* @param userDTO bean class that contains user and tenant Information
* @return true/false whether user is verified or not. If user is a tenant
* user then always return false
*/
public VerificationBean verifyUserForRecovery(int sequence, UserDTO userDTO) {
String userId = userDTO.getUserId();
int tenantId = userDTO.getTenantId();
boolean success = false;
VerificationBean bean = null;
try {
UserStoreManager userStoreManager = IdentityMgtServiceComponent.getRealmService().
getTenantUserRealm(tenantId).getUserStoreManager();
if (userStoreManager.isExistingUser(userId)) {
if (IdentityMgtConfig.getInstance().isAuthPolicyAccountLockCheck()) {
String accountLock = userStoreManager.
getUserClaimValue(userId, UserIdentityDataStore.ACCOUNT_LOCK, null);
if (!Boolean.parseBoolean(accountLock)) {
success = true;
}
} else {
success = true;
}
} else {
log.error("User with user name : " + userId
+ " does not exists in tenant domain : " + userDTO.getTenantDomain());
bean = new VerificationBean(VerificationBean.ERROR_CODE_INVALID_USER + " "
+ "User does not exists");
}
if (success) {
String internalCode = generateUserCode(sequence, userId);
String key = UUID.randomUUID().toString();
UserRecoveryDataDO dataDO =
new UserRecoveryDataDO(userId, tenantId, internalCode, key);
if (sequence != 3) {
dataStore.invalidate(userId, tenantId);
}
dataStore.store(dataDO);
log.info("User verification successful for user : " + userId +
" from tenant domain :" + userDTO.getTenantDomain());
bean = new VerificationBean(userId, getUserExternalCodeStr(internalCode));
}
} catch (Exception e) {
String errorMessage = "Error verifying user : " + userId;
log.error(errorMessage, e);
bean = new VerificationBean(VerificationBean.ERROR_CODE_UNEXPECTED + " "
+ errorMessage);
}
if (bean == null) {
bean = new VerificationBean(VerificationBean.ERROR_CODE_UNEXPECTED);
}
return bean;
}
示例15: validateCurrentUser
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
private boolean validateCurrentUser(String user) throws UserStoreException {
UserStoreManager userStoreManager = BPMNOSGIService.getUserRealm().getUserStoreManager();
return userStoreManager.isExistingUser(user);
}