Merge pull request #234 from ayyoob/das-ext

few changes while creating a role for android sense and virtual fi…
revert-dabc3590
Ruwan 9 years ago
commit b4371c3fc3

@ -26,6 +26,7 @@ import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -176,21 +177,23 @@ public class APIUtil {
return deviceAccessAuthorizationService; return deviceAccessAuthorizationService;
} }
public static void registerApiAccessRoles(String user) { public static void registerApiAccessRoles(String user) {
UserStoreManager userStoreManager = null; UserStoreManager userStoreManager = null;
try { try {
userStoreManager = getUserStoreManager(); userStoreManager = getUserStoreManager();
String[] userList = new String[]{user}; String[] userList = new String[]{user};
if (userStoreManager != null) { if (userStoreManager != null) {
String rolesOfUser[] = userStoreManager.getRoleListOfUser(user);
if (!userStoreManager.isExistingRole(Constants.DEFAULT_ROLE_NAME)) { if (!userStoreManager.isExistingRole(Constants.DEFAULT_ROLE_NAME)) {
userStoreManager.addRole(Constants.DEFAULT_ROLE_NAME, userList, Constants.DEFAULT_PERMISSION); userStoreManager.addRole(Constants.DEFAULT_ROLE_NAME, userList, Constants.DEFAULT_PERMISSION);
} else if (rolesOfUser != null && Arrays.asList(rolesOfUser).contains(Constants.DEFAULT_ROLE_NAME)) {
return;
} else { } else {
userStoreManager.updateUserListOfRole(Constants.DEFAULT_ROLE_NAME, null, userList); userStoreManager.updateUserListOfRole(Constants.DEFAULT_ROLE_NAME, new String[0], userList);
} }
} }
} catch (UserStoreException e) { } catch (UserStoreException e) {
log.error("Error while creating a role and adding a user for android_sense.", e); log.error("Error while creating a role and adding a user for virtual_firealarm.", e);
} }
} }

@ -22,6 +22,7 @@ import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -192,10 +193,13 @@ public class APIUtil {
userStoreManager = getUserStoreManager(); userStoreManager = getUserStoreManager();
String[] userList = new String[]{user}; String[] userList = new String[]{user};
if (userStoreManager != null) { if (userStoreManager != null) {
String rolesOfUser[] = userStoreManager.getRoleListOfUser(user);
if (!userStoreManager.isExistingRole(Constants.DEFAULT_ROLE_NAME)) { if (!userStoreManager.isExistingRole(Constants.DEFAULT_ROLE_NAME)) {
userStoreManager.addRole(Constants.DEFAULT_ROLE_NAME, userList, Constants.DEFAULT_PERMISSION); userStoreManager.addRole(Constants.DEFAULT_ROLE_NAME, userList, Constants.DEFAULT_PERMISSION);
} else if (rolesOfUser != null && Arrays.asList(rolesOfUser).contains(Constants.DEFAULT_ROLE_NAME)) {
return;
} else { } else {
userStoreManager.updateUserListOfRole(Constants.DEFAULT_ROLE_NAME, null, userList); userStoreManager.updateUserListOfRole(Constants.DEFAULT_ROLE_NAME, new String[0], userList);
} }
} }
} catch (UserStoreException e) { } catch (UserStoreException e) {

Loading…
Cancel
Save