Package org.glassfish.connectors.config

Examples of org.glassfish.connectors.config.SecurityMap


                public Object run(ConnectorConnectionPool ccp) throws PropertyVetoException, TransactionFailure {

                    List<SecurityMap> securityMaps = ccp.getSecurityMap();

                    SecurityMap newResource = ccp.createChild(SecurityMap.class);
                    newResource.setName(securityMapName);

                    if (principals != null) {
                        for (String p : principals) {
                            newResource.getPrincipal().add(p);
                        }
                    }

                    if (userGroups != null) {
                        for (String u : userGroups) {
                            newResource.getUserGroup().add(u);
                        }
                    }

                    BackendPrincipal backendPrincipal = newResource.createChild(BackendPrincipal.class);
                    backendPrincipal.setUserName(mappedusername);
                    if (mappedpassword != null && !mappedpassword.isEmpty()) {
                        backendPrincipal.setPassword(mappedpassword);
                    }
                    newResource.setBackendPrincipal(backendPrincipal);
                    securityMaps.add(newResource);
                    return newResource;
                }
            }, connPool);
View Full Code Here


                    return;
                }
            }
        }

        SecurityMap map = getSecurityMap(securityMapName, poolName, ccPools);
        final List<String> existingPrincipals = new ArrayList(map.getPrincipal());
        final List<String> existingUserGroups = new ArrayList(map.getUserGroup());

         if (existingPrincipals.isEmpty() && addPrincipals != null) {
            report.setMessage(localStrings.getLocalString("update.connector.security.map." +
                    "addPrincipalToExistingUserGroupsWorkSecurityMap",
                    "Failed to add principals to a security map with user groups."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }

        if (existingUserGroups.isEmpty() && addUserGroups != null) {
            report.setMessage(localStrings.getLocalString("update.connector.security.map." +
                    "addUserGroupsToExistingPrincipalsWorkSecurityMap",
                    "Failed to add user groups to a security map with principals."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }

        //check if there is any invalid principal in removePrincipals.
        if (removePrincipals != null) {
            boolean principalExists = true;
            String principal = null;
            for (String p : removePrincipals) {
                if (!existingPrincipals.contains(p)) {
                    principalExists = false;
                    principal = p;
                    break;
                }
            }
            if (!principalExists) {
                report.setMessage(localStrings.getLocalString("update.connector.security.map.principal_does_not_exists",
                        "The principal {0} that you want to delete does not exist in connector connection pool {1}. Please give a valid principal name.",
                        principal, poolName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }

        //check if there is any invalid usergroup in removeUserGroups.
        if (removeUserGroups != null) {
            boolean userGroupExists = true;
            String userGroup = null;
            for (String ug : removeUserGroups) {
                if (!existingUserGroups.contains(ug)) {
                    userGroupExists = false;
                    userGroup = ug;
                    break;
                }
            }
            if (!userGroupExists) {
                report.setMessage(localStrings.getLocalString("update.connector.security.map.usergroup_does_not_exists",
                        "The usergroup {0} that you want to delete does not exist in connector connection pool {1}. Please give a valid user-group name.",
                        userGroup, poolName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }

        //FIX : Bug 4914883.
        //The user should not delete all principals and usergroups in the map.
        // Atleast one principal or usergroup must exists.

        if (addPrincipals == null && addUserGroups == null) {
            boolean principalsEmpty = false;
            boolean userGroupsEmpty = false;

            if (removePrincipals == null && existingPrincipals.isEmpty()) {
                principalsEmpty = true;
            }
            if (removeUserGroups == null && existingUserGroups.isEmpty()) {
                userGroupsEmpty = true;
            }

            if ((removePrincipals != null) &&
                    (removePrincipals.size() == existingPrincipals.size())) {
                principalsEmpty = true;
            }

            if ((removeUserGroups != null) &&
                    (removeUserGroups.size() == existingUserGroups.size())) {
                userGroupsEmpty = true;
            }
            if (userGroupsEmpty && principalsEmpty) {
                report.setMessage(localStrings.getLocalString("update.connector.security.map.principals_usergroups_will_be_null",
                        "The values in your command will delete all principals and usergroups. You cannot delete all principals and usergroups. Atleast one of them must exist."));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }

        //add principals to the existingPrincipals arraylist.
        if (addPrincipals != null) {
            for (String principal : addPrincipals) {
                if (!existingPrincipals.contains(principal)) {
                    existingPrincipals.add(principal);
                } else {
                    report.setMessage(localStrings.getLocalString("create.connector.security.map.principal_exists",
                            "The principal {0} already exists in connector connection pool {1}. Please give a different principal name.",
                            principal, poolName));
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    return;
                }
            }
        }

        //removing principals from existingPrincipals arraylist.
        if (removePrincipals != null) {
            for (String principal : removePrincipals) {
                existingPrincipals.remove(principal);
            }
        }

        //adding user-groups....
        if (addUserGroups != null) {
            for (String userGroup : addUserGroups) {
                if (!existingUserGroups.contains(userGroup)) {
                    existingUserGroups.add(userGroup);
                } else {
                    report.setMessage(localStrings.getLocalString("create.connector.security.map.usergroup_exists",
                            "The user-group {0} already exists in connector connection pool {1}. Please give a different user-group name.",
                            userGroup, poolName));
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    return;
                }
            }
        }

        //removing user-groups....
        if (removeUserGroups != null) {
            for (String userGroup : removeUserGroups) {
                existingUserGroups.remove(userGroup);
            }
        }

        BackendPrincipal backendPrincipal = map.getBackendPrincipal();

        try {
            ConfigSupport.apply(new ConfigCode() {

                public Object run(ConfigBeanProxy... params) throws PropertyVetoException, TransactionFailure {
                    SecurityMap sm = (SecurityMap) params[0];
                    BackendPrincipal bp = (BackendPrincipal) params[1];
                    //setting the updated principal user-group arrays....
                    if (existingPrincipals != null) {
                        sm.getPrincipal().clear();
                        for (String principal : existingPrincipals) {
                            sm.getPrincipal().add(principal);
                        }
                    }
                    if (existingUserGroups != null) {
                        sm.getUserGroup().clear();
                        for (String userGroup : existingUserGroups) {
                            sm.getUserGroup().add(userGroup);
                        }
                    }

                    //updating the backend-principal.......
                    //get the backend principal for the given security map and pool...
View Full Code Here

         return pool;
    }

    SecurityMap getSecurityMap(String mapName, String poolName, Collection<ConnectorConnectionPool> ccPools) {
        List<SecurityMap> maps = getAllSecurityMapsForPool(poolName, ccPools);
        SecurityMap map = null;
        if (maps != null) {
            for (SecurityMap sm : maps) {
                if (sm.getName().equals(mapName)) {
                    map = sm;
                    break;
View Full Code Here

TOP

Related Classes of org.glassfish.connectors.config.SecurityMap

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.