Package org.wso2.carbon.user.core

Examples of org.wso2.carbon.user.core.UserRealm


    public boolean isProfileExisting(String username, String sessionId) throws RegistryException {
        UserRegistry registry = (UserRegistry) getRootRegistry();
        try {
            if (registry != null && registry.getUserRealm() != null &&
                    registry.getUserRealm().getUserStoreManager() != null) {
                UserRealm realm = registry.getUserRealm();
                boolean isAdmin = false;
                String[] userRoles = realm.getUserStoreManager().getRoleListOfUser(
                        registry.getUserName());
                for (String userRole: userRoles) {
                    if (userRole.equals(realm.getRealmConfiguration().getAdminRoleName())) {
                        isAdmin = true;
                        break;
                    }
                }
                if (!username.equals(registry.getUserName()) && !isAdmin) {
                    return false;   
                }
                UserStoreManager reader = realm.getUserStoreManager();
                return (reader.getUserClaimValue(username,
                        UserCoreConstants.ClaimTypeURIs.EMAIL_ADDRESS,
                        UserCoreConstants.DEFAULT_PROFILE)) != null;
            }
        } catch (UserStoreException ignore) {
View Full Code Here


    public boolean isRoleProfileExisting(String role, String sessionId) throws RegistryException {
        UserRegistry registry = (UserRegistry) getRootRegistry();
        try {
            if (registry != null && registry.getUserRealm() != null &&
                    registry.getUserRealm().getUserStoreManager() != null) {
                UserRealm realm = registry.getUserRealm();
                boolean isAdmin = false;
                String[] userRoles = realm.getUserStoreManager().getRoleListOfUser(
                        registry.getUserName());
                for (String userRole: userRoles) {
                    if (userRole.equals(realm.getRealmConfiguration().getAdminRoleName())) {
                        isAdmin = true;
                        break;
                    }
                }
                return Arrays.asList(userRoles).contains(role) || isAdmin;
View Full Code Here

            String pathToAuthorize,
            String roleToAuthorize,
            String actionToAuthorize,
            String permissionType) throws Exception {

        UserRealm userRealm ;
        try {
            userRealm = userRegistry.getUserRealm();
            userRealm.getAuthorizationManager();
        } catch (Exception e) {
            String msg =
                    "Couldn't get access control admin for changing authorizations. Caused by: " +
                            e.getMessage();
            log.error(msg, e);
            throw new RegistryException(msg, e);
        }

        try {
            String notificationResponse = "The following authorization has been added.";
            if (actionToAuthorize.equals("2")) {

                if (permissionType.equals("1")) {
                    userRealm.getAuthorizationManager().authorizeRole(roleToAuthorize, pathToAuthorize, ActionConstants.GET);
                    notificationResponse += " READ: Allowed.";
                } else {
                    userRealm.getAuthorizationManager().denyRole(roleToAuthorize, pathToAuthorize, ActionConstants.GET);
                    notificationResponse += " READ: Denied.";
                }
            }

            if (actionToAuthorize.equals("3")) {

                if (permissionType.equals("1")) {
                    userRealm.getAuthorizationManager().authorizeRole(roleToAuthorize, pathToAuthorize, ActionConstants.PUT);
                    notificationResponse += " WRITE: Allowed.";
                } else {
                    userRealm.getAuthorizationManager().denyRole(roleToAuthorize, pathToAuthorize, ActionConstants.PUT);
                    notificationResponse += " WRITE: Denied.";
                }
            }

            if (actionToAuthorize.equals("4")) {

                if (permissionType.equals("1")) {
                    userRealm.getAuthorizationManager().authorizeRole(roleToAuthorize, pathToAuthorize, ActionConstants.DELETE);
                    notificationResponse += " DELETE: Allowed.";
                } else {
                    userRealm.getAuthorizationManager().denyRole(roleToAuthorize, pathToAuthorize, ActionConstants.DELETE);
                    notificationResponse += " DELETE: Denied.";
                }
            }

            if (actionToAuthorize.equals("5")) {

                if (permissionType.equals("1")) {
                    userRealm.getAuthorizationManager().authorizeRole(roleToAuthorize, pathToAuthorize, AccessControlConstants.AUTHORIZE);
                    notificationResponse += " AUTHORIZE: Allowed.";
                } else {
                    userRealm.getAuthorizationManager().denyRole(roleToAuthorize, pathToAuthorize, AccessControlConstants.AUTHORIZE);
                    notificationResponse += " AUTHORIZE: Denied.";
                }
            }

            String message = "Permissions have been added for the role " + roleToAuthorize + " on resource " +
View Full Code Here

    private String getPathFromId(String id) {
        return id.substring(0, id.lastIndexOf("tenantId"));
    }

    private boolean isAuthorized(UserRegistry registry, String resourcePath, String action) throws RegistryException {
        UserRealm userRealm = registry.getUserRealm();
        String userName = getLoggedInUserName();

        try {
            if (!userRealm.getAuthorizationManager().isUserAuthorized(userName,
                    resourcePath, action)) {
                return false;
            }
        } catch (UserStoreException e) {
            throw new RegistryException("Error while authorizing " + resourcePath
View Full Code Here

        if (reviewer == null) {
            throw new RegistryException("No " + REVIEWER + " property");
        }

        try {
            UserRealm userRealm = CurrentSession.getUserRealm();
            if (!userRealm.getUserStoreManager().isExistingUser(reviewer)) {
                throw new RegistryException("No such user '" + reviewer + "'");
            }
        } catch (UserStoreException e) {
            throw new RegistryException("User Store Exception", e);
        }
View Full Code Here

//   
//  }

    public static boolean isAuthorized(UserRegistry registry, String resourcePath, String action)
                            throws RegistryException{
        UserRealm userRealm = registry.getUserRealm();
        String userName = registry.getUserName();
        try {
            if (!userRealm.getAuthorizationManager().isUserAuthorized(userName,
                    resourcePath, action)) {
                return false;
            }
        } catch (UserStoreException e) {
            throw new RegistryException("Error at Authorizing " + resourcePath
View Full Code Here

            String userName, String resourcePath, UserRegistry userRegistry)
            throws RegistryException {

        boolean putAllowed = false;

        UserRealm userRealm = userRegistry.getUserRealm();

        try {
            if (userRealm.getAuthorizationManager().isUserAuthorized(
                    userName, resourcePath, ActionConstants.PUT)) {
                putAllowed = true;
            }
        } catch (UserStoreException e) {
View Full Code Here

            String userName, String resourcePath, UserRegistry userRegistry)
            throws RegistryException {

        boolean putAllowed = false;

        UserRealm userRealm = userRegistry.getUserRealm();

        try {
            if (userRealm.getAuthorizationManager().isUserAuthorized(
                    userName, resourcePath, ActionConstants.DELETE)) {
                putAllowed = true;
            }
        } catch (UserStoreException e) {
View Full Code Here

            String userName, String resourcePath, UserRegistry userRegistry)
            throws RegistryException {

        boolean putAllowed = false;

        UserRealm userRealm = userRegistry.getUserRealm();

        try {
            if (userRealm.getAuthorizationManager().isUserAuthorized(
                    userName, resourcePath, ActionConstants.GET)) {
                putAllowed = true;
            }
        } catch (UserStoreException e) {
View Full Code Here

            String userName, String resourcePath, UserRegistry userRegistry)
            throws RegistryException {

        boolean putAllowed = false;

        UserRealm userRealm = userRegistry.getUserRealm();

        try {
            if (userRealm.getAuthorizationManager().isUserAuthorized(
                    userName, resourcePath, AccessControlConstants.AUTHORIZE)) {
                putAllowed = true;
            }
        } catch (UserStoreException e) {
View Full Code Here

TOP

Related Classes of org.wso2.carbon.user.core.UserRealm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.