本文整理汇总了Java中org.wso2.carbon.user.core.UserStoreManager.addUser方法的典型用法代码示例。如果您正苦于以下问题:Java UserStoreManager.addUser方法的具体用法?Java UserStoreManager.addUser怎么用?Java UserStoreManager.addUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wso2.carbon.user.core.UserStoreManager
的用法示例。
在下文中一共展示了UserStoreManager.addUser方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addUserWithClaims
import org.wso2.carbon.user.core.UserStoreManager; //导入方法依赖的package包/类
private void addUserWithClaims(String username, String[] line, UserStoreManager userStore)
throws UserStoreException, UserAdminException {
String roleString = null;
String[] roles = null;
String password = line[1];
Map<String, String> claims = new HashMap<String, String>();
for (int i = 2; i < line.length; i++) {
if (line[i] != null && !line[i].isEmpty()) {
String[] claimStrings = line[i].split("=");
if (claimStrings.length != 2) {
throw new UserAdminException("Claims and values are not in correct format");
} else {
String claimURI = claimStrings[0];
String claimValue = claimStrings[1];
if (claimURI.contains("role")) {
roleString = claimValue;
} else {
if (!claimURI.isEmpty()) {
// Not trimming the claim values as we should not restrict the claim values not to have
// leading or trailing whitespaces.
claims.put(claimURI.trim(), claimValue);
}
}
}
}
}
if (roleString != null && !roleString.isEmpty()) {
roles = roleString.split(":");
}
userStore.addUser(username, password, roles, claims, null, true);
}
示例2: addUserWithClaims
import org.wso2.carbon.user.core.UserStoreManager; //导入方法依赖的package包/类
private void addUserWithClaims(String username, String[] line, UserStoreManager userStore)
throws UserStoreException, UserAdminException {
String roleString = null;
String[] roles = null;
String password = line[1];
Map<String, String> claims = new HashMap<String, String>();
for (int i = 2; i < line.length; i++) {
if (line[i] != null && !line[i].isEmpty()) {
String[] claimStrings = line[i].split("=");
if (claimStrings.length != 2) {
throw new UserAdminException("Claims and values are not in correct format");
} else {
if (claimStrings[0].contains("role")) {
roleString = claimStrings[1];
} else {
claims.put(claimStrings[0], claimStrings[1]);
}
}
}
}
if (roleString != null && !roleString.isEmpty()) {
roles = roleString.split(":");
}
userStore.addUser(username, password, roles, claims, null, true);
}
示例3: addUser
import org.wso2.carbon.user.core.UserStoreManager; //导入方法依赖的package包/类
private void addUser(String userName, String password, Map<String, String> claimList,
String profileName, UserRealm realm) throws IdentityException {
UserStoreManager admin = null;
Permission permission = null;
try {
// get config from tenant registry
TenantRegistrationConfig tenantConfig = getTenantSignUpConfig(realm.getUserStoreManager().getTenantId());
// set tenant config specific sign up domain
if (tenantConfig != null && !"".equals(tenantConfig.getSignUpDomain())) {
int index = userName.indexOf(UserCoreConstants.DOMAIN_SEPARATOR);
if (index > 0) {
userName = tenantConfig.getSignUpDomain().toUpperCase() + UserCoreConstants.DOMAIN_SEPARATOR
+ userName.substring(index + 1);
} else {
userName = tenantConfig.getSignUpDomain().toUpperCase() + UserCoreConstants.DOMAIN_SEPARATOR
+ userName;
}
}
// add user to the relevant user store
admin = realm.getUserStoreManager();
if (!isUserNameWithAllowedDomainName(userName, realm)) {
throw IdentityException.error("Domain does not permit self registration");
}
// add user
admin.addUser(userName, password, null, claimList, profileName);
// after adding the user, assign specif roles
List<String> roleNamesArr = getRoleName(userName, tenantConfig);
if (claimList.get(SelfRegistrationConstants.SIGN_UP_ROLE_CLAIM_URI) != null) {
// check is a user role is specified as a claim by the client, if so add it to the roles list
if (tenantConfig != null) {
roleNamesArr.add(tenantConfig.getSignUpDomain().toUpperCase()
+ UserCoreConstants.DOMAIN_SEPARATOR
+ claimList.get(SelfRegistrationConstants.SIGN_UP_ROLE_CLAIM_URI));
} else {
roleNamesArr.add(UserCoreConstants.INTERNAL_DOMAIN
+ UserCoreConstants.DOMAIN_SEPARATOR
+ claimList.get(SelfRegistrationConstants.SIGN_UP_ROLE_CLAIM_URI));
}
}
String[] identityRoleNames = roleNamesArr.toArray(new String[roleNamesArr.size()]);
for (int i = 0; i < identityRoleNames.length; i++) {
// if this is the first time a user signs up, needs to create role
doAddUser(i, admin, identityRoleNames, userName, permission);
}
} catch (UserStoreException e) {
throw IdentityException.error("Error occurred while adding user : " + userName + ". " + e.getMessage(), e);
}
}
示例4: addUser
import org.wso2.carbon.user.core.UserStoreManager; //导入方法依赖的package包/类
private void addUser(String userName, String password, Map<String, String> claimList,
String profileName, UserRealm realm) throws IdentityException {
UserStoreManager admin = null;
Permission permission = null;
try {
// get config from tenant registry
TenantRegistrationConfig tenantConfig = getTenantSignUpConfig(realm.getUserStoreManager().getTenantId());
// set tenant config specific sign up domain
if (tenantConfig != null && !"".equals(tenantConfig.getSignUpDomain())) {
int index = userName.indexOf(UserCoreConstants.DOMAIN_SEPARATOR);
if (index > 0) {
userName = tenantConfig.getSignUpDomain().toUpperCase() + UserCoreConstants.DOMAIN_SEPARATOR
+ userName.substring(index + 1);
} else {
userName = tenantConfig.getSignUpDomain().toUpperCase() + UserCoreConstants.DOMAIN_SEPARATOR
+ userName;
}
}
// add user to the relevant user store
admin = realm.getUserStoreManager();
if (!isUserNameWithAllowedDomainName(userName, realm)) {
throw IdentityException.error("Domain does not permit self registration");
}
// add user
admin.addUser(userName, password, null, claimList, profileName);
// after adding the user, assign specif roles
List<String> roleNamesArr = getRoleName(userName, tenantConfig);
if (claimList.get(SelfRegistrationConstants.SIGN_UP_ROLE_CLAIM_URI) != null) {
// check is a user role is specified as a claim by the client, if so add it to the roles list
if (tenantConfig != null) {
roleNamesArr.add(tenantConfig.getSignUpDomain().toUpperCase()
+ UserCoreConstants.DOMAIN_SEPARATOR
+ claimList.get(SelfRegistrationConstants.SIGN_UP_ROLE_CLAIM_URI));
} else {
roleNamesArr.add(UserCoreConstants.INTERNAL_DOMAIN
+ UserCoreConstants.DOMAIN_SEPARATOR
+ claimList.get(SelfRegistrationConstants.SIGN_UP_ROLE_CLAIM_URI));
}
}
String[] identityRoleNames = roleNamesArr.toArray(new String[roleNamesArr.size()]);
for (int i = 0; i < identityRoleNames.length; i++) {
// if this is the first time a user signs up, needs to create role
doAddUser(i,admin, identityRoleNames,userName,permission);
}
} catch (UserStoreException e) {
throw IdentityException.error("Error occurred while adding user : " + userName + ". " + e.getMessage(), e);
}
}