Search in sources :

Example 1 with ServiceType

use of com.sun.identity.policy.ServiceType in project OpenAM by OpenRock.

the class PrivilegeUtils method pavToPrav.

static Map<String, Boolean> pavToPrav(Map actionValues, String serviceName) throws PolicyException, SSOException {
    if (actionValues == null) {
        return null;
    }
    ServiceType serviceType = null;
    if (serviceName != null) {
        try {
            serviceType = svcTypeManager.getServiceType(serviceName);
        } catch (NameNotFoundException e) {
        //ignore
        }
    }
    Map av = new HashMap();
    Set keySet = (Set) actionValues.keySet();
    for (Object actionObj : keySet) {
        String action = (String) actionObj;
        Set values = (Set) actionValues.get(action);
        if ((values == null) || values.isEmpty()) {
            av.put(action, Boolean.FALSE);
        } else {
            if (serviceType != null) {
                try {
                    ActionSchema as = serviceType.getActionSchema(action);
                    if (as.getSyntax().equals(AttributeSchema.Syntax.BOOLEAN)) {
                        String trueValue = as.getTrueValue();
                        if (values.contains(trueValue)) {
                            av.put(action, Boolean.TRUE);
                        } else {
                            av.put(action, Boolean.FALSE);
                        }
                    } else {
                        // Append action value to action name
                        String value = values.iterator().next().toString();
                        av.put(action + "_" + value, Boolean.TRUE);
                    }
                } catch (InvalidNameException e) {
                    av.put(action, Boolean.parseBoolean((String) values.iterator().next()));
                }
            } else {
                av.put(action, Boolean.parseBoolean((String) values.iterator().next()));
            }
        }
    }
    return av;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) InvalidNameException(com.sun.identity.policy.InvalidNameException) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) HashMap(java.util.HashMap) ServiceType(com.sun.identity.policy.ServiceType) HashMap(java.util.HashMap) Map(java.util.Map) ActionSchema(com.sun.identity.policy.ActionSchema)

Example 2 with ServiceType

use of com.sun.identity.policy.ServiceType in project OpenAM by OpenRock.

the class PolicyModelImpl method getSvcTypeNameToActionsMap.

private Map getSvcTypeNameToActionsMap(Policy policy, String realmName) {
    if (mapSvcTypeNameToActions == null) {
        try {
            Set serviceTypeNames = getServiceTypeNames().keySet();
            int sz = serviceTypeNames.size();
            mapSvcTypeNameToActions = new HashMap(sz * 2);
            mapSvcTypeNameToResBundle = new HashMap(sz * 2);
            ServiceTypeManager mgr = getServiceTypeManager();
            for (Iterator i = serviceTypeNames.iterator(); i.hasNext(); ) {
                String serviceTypeName = (String) i.next();
                ServiceType serviceType = mgr.getServiceType(serviceTypeName);
                if (serviceType != null) {
                    ResourceBundle rb = getResourceBundle(serviceType, getUserLocale());
                    if (rb != null) {
                        mapSvcTypeNameToResBundle.put(serviceTypeName, rb);
                        Set as = getActionSchemas(serviceType);
                        filterActionSchemaWithI18nKey(as);
                        if ((as != null) && !as.isEmpty()) {
                            mapSvcTypeNameToActions.put(serviceTypeName, as);
                            if (requiresResourceName(policy, realmName, serviceTypeName, as, true)) {
                                requiredResourceNameService.add(serviceTypeName);
                            }
                            if (requiresResourceName(policy, realmName, serviceTypeName, as, false)) {
                                notRequiredResourceNameService.add(serviceTypeName);
                            }
                        }
                    }
                }
            }
        } catch (AMConsoleException e) {
            debug.warning("PolicyModelImppl.getSvcTypeNameToActionsMap", e);
        } catch (SSOException e) {
            debug.warning("PolicyModelImppl.getSvcTypeNameToActionsMap", e);
        } catch (NameNotFoundException e) {
            debug.warning("PolicyModelImppl.getSvcTypeNameToActionsMap", e);
        }
    }
    return mapSvcTypeNameToActions;
}
Also used : ServiceTypeManager(com.sun.identity.policy.ServiceTypeManager) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) ServiceType(com.sun.identity.policy.ServiceType) Iterator(java.util.Iterator) ResourceBundle(java.util.ResourceBundle) SSOException(com.iplanet.sso.SSOException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 3 with ServiceType

use of com.sun.identity.policy.ServiceType in project OpenAM by OpenRock.

the class PrivilegeUtils method pravToPav.

static Map pravToPav(Map<String, Boolean> actionValues, String serviceName) throws PolicyException, SSOException {
    if (actionValues == null) {
        return null;
    }
    ServiceType serviceType = null;
    try {
        serviceType = svcTypeManager.getServiceType(serviceName);
    } catch (NameNotFoundException e) {
    //ignore
    }
    Map av = new HashMap();
    Set<String> keySet = actionValues.keySet();
    for (String action : keySet) {
        try {
            Set values = new HashSet();
            Boolean value = actionValues.get(action);
            if (serviceType != null) {
                ActionSchema as = serviceType.getActionSchema(action);
                String trueValue = as.getTrueValue();
                String falseValue = as.getFalseValue();
                if (value.equals(Boolean.TRUE)) {
                    values.add(trueValue);
                } else {
                    values.add(falseValue);
                }
            } else {
                values.add(value.toString());
            }
            av.put(action, values);
        } catch (InvalidNameException e) {
            Boolean value = actionValues.get(action);
            Set values = new HashSet();
            values.add(value.toString());
            av.put(action, values);
        }
    }
    return av;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) InvalidNameException(com.sun.identity.policy.InvalidNameException) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) HashMap(java.util.HashMap) ServiceType(com.sun.identity.policy.ServiceType) HashMap(java.util.HashMap) Map(java.util.Map) ActionSchema(com.sun.identity.policy.ActionSchema) HashSet(java.util.HashSet)

Aggregations

NameNotFoundException (com.sun.identity.policy.NameNotFoundException)3 ServiceType (com.sun.identity.policy.ServiceType)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 ActionSchema (com.sun.identity.policy.ActionSchema)2 InvalidNameException (com.sun.identity.policy.InvalidNameException)2 Map (java.util.Map)2 SSOException (com.iplanet.sso.SSOException)1 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)1 ServiceTypeManager (com.sun.identity.policy.ServiceTypeManager)1 Iterator (java.util.Iterator)1 ResourceBundle (java.util.ResourceBundle)1