Search in sources :

Example 1 with WorkSecurityMap

use of org.glassfish.connectors.config.WorkSecurityMap in project Payara by payara.

the class ConnectorWorkSecurityMapResourceManager method createResource.

private WorkSecurityMap createResource(Resources param, Properties props) throws PropertyVetoException, TransactionFailure {
    WorkSecurityMap newResource = createConfigBean(param);
    param.getResources().add(newResource);
    return newResource;
}
Also used : WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap)

Example 2 with WorkSecurityMap

use of org.glassfish.connectors.config.WorkSecurityMap in project Payara by payara.

the class WorkSecurityMapHelper method getSecurityMap.

static WorkSecurityMap getSecurityMap(String mapName, String raName, Resources resources) {
    List<WorkSecurityMap> maps = ConnectorsUtil.getWorkSecurityMaps(raName, resources);
    WorkSecurityMap map = null;
    if (maps != null) {
        for (WorkSecurityMap wsm : maps) {
            if (wsm.getName().equals(mapName)) {
                map = wsm;
                break;
            }
        }
    }
    return map;
}
Also used : WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap)

Example 3 with WorkSecurityMap

use of org.glassfish.connectors.config.WorkSecurityMap in project Payara by payara.

the class WorkContextHandlerImpl method getWorkContextMap.

/**
 * get the security work context map (if any) for the resource-adapter
 * look for <[raname]-principals-map> & <[raname]-groups-map> jvm-options
 * to generate the map
 *
 * @param raName resource-adapter name
 * @return security-map
 */
/*
    private Map getSecurityWorkContextMap(String raName) {
        HashMap eisASMap = new HashMap();

        String principalsMap = System.getProperty(raName + "-principals-map");
        if (principalsMap != null) {
            StringTokenizer tokenizer = new StringTokenizer(principalsMap, ",");
            while (tokenizer.hasMoreElements()) {
                String nameValue = (String) tokenizer.nextElement();
                if (nameValue != null && nameValue.contains("=")) {
                    int delimiterLocation = nameValue.indexOf("=");
                    String eisPrincipal = nameValue.substring(0, delimiterLocation);
                    String appserverPrincipal = nameValue.substring(delimiterLocation + 1);
                    eisASMap.put(new PrincipalImpl(eisPrincipal), new PrincipalImpl(appserverPrincipal));
                }
            }
        }

        //TODO V3 refactor (common code for principals & groups)
        String groupsMap = System.getProperty(raName + "-groups-map");
        if (groupsMap != null) {
            StringTokenizer tokenizer = new StringTokenizer(groupsMap, ",");
            while (tokenizer.hasMoreElements()) {
                String nameValue = (String) tokenizer.nextElement();
                if (nameValue != null && nameValue.contains("=")) {
                    int delimiterLocation = nameValue.indexOf("=");
                    String eisGroup = nameValue.substring(0, delimiterLocation);
                    String appserverGroup = nameValue.substring(delimiterLocation + 1);
                    eisASMap.put(new Group(eisGroup), new Group(appserverGroup));
                }
            }
            return eisASMap;
        }
        return null;
    }
*/
/**
 * Given a resource-adapter name, get all its work-context-map
 * @param raName resource-adapter-name
 * @return work-context-map
 */
private Map getWorkContextMap(String raName) {
    List<WorkSecurityMap> maps = runtime.getWorkSecurityMap(raName);
    List<PrincipalMap> principalsMap = getPrincipalsMap(maps);
    List<GroupMap> groupsMap = getGroupsMap(maps);
    HashMap eisASMap = new HashMap();
    for (PrincipalMap map : principalsMap) {
        eisASMap.put(new PrincipalImpl(map.getEisPrincipal()), new PrincipalImpl(map.getMappedPrincipal()));
    }
    for (GroupMap map : groupsMap) {
        eisASMap.put(new Group(map.getEisGroup()), new Group(map.getMappedGroup()));
    }
    return eisASMap;
}
Also used : Group(org.glassfish.security.common.Group) PrincipalMap(org.glassfish.connectors.config.PrincipalMap) GroupMap(org.glassfish.connectors.config.GroupMap) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) PrincipalImpl(org.glassfish.security.common.PrincipalImpl)

Example 4 with WorkSecurityMap

use of org.glassfish.connectors.config.WorkSecurityMap in project Payara by payara.

the class CreateConnectorWorkSecurityMap method execute.

// TODO common code replicated in ConnectorWorkSecurityMapManager
/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    if (mapName == null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.noMapName", "No mapname defined for connector work security map."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (raName == null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.noRaName", "No raname defined for connector work security map."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (principalsMap == null && groupsMap == null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.noMap", "No principalsmap or groupsmap defined for connector work security map."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (principalsMap != null && groupsMap != null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.specifyPrincipalsOrGroupsMap", "A work-security-map can have either (any number of) group mapping  " + "or (any number of) principals mapping but not both. Specify" + "--principalsmap or --groupsmap."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // ensure we don't already have one of this name
    if (hasDuplicate(domain.getResources(), report))
        return;
    // TODO ASR : need similar validation while creating app-scoped-resource of w-s-m
    String appName = raName;
    if (!ConnectorsUtil.isStandAloneRA(raName)) {
        appName = ConnectorsUtil.getApplicationNameOfEmbeddedRar(raName);
        Application application = applications.getApplication(appName);
        if (application != null) {
            // embedded RAR
            String resourceAdapterName = ConnectorsUtil.getRarNameFromApplication(raName);
            Module module = application.getModule(resourceAdapterName);
            if (module != null) {
                Resources msr = module.getResources();
                if (msr != null) {
                    if (hasDuplicate(msr, report))
                        return;
                }
            }
        }
    } else {
        // standalone RAR
        Application application = applications.getApplication(appName);
        if (application != null) {
            Resources appScopedResources = application.getResources();
            if (appScopedResources != null) {
                if (hasDuplicate(appScopedResources, report))
                    return;
            }
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                WorkSecurityMap workSecurityMap = param.createChild(WorkSecurityMap.class);
                workSecurityMap.setName(mapName);
                workSecurityMap.setResourceAdapterName(raName);
                if (principalsMap != null) {
                    for (Map.Entry e : principalsMap.entrySet()) {
                        PrincipalMap principalMap = workSecurityMap.createChild(PrincipalMap.class);
                        principalMap.setEisPrincipal((String) e.getKey());
                        principalMap.setMappedPrincipal((String) e.getValue());
                        workSecurityMap.getPrincipalMap().add(principalMap);
                    }
                } else if (groupsMap != null) {
                    for (Map.Entry e : groupsMap.entrySet()) {
                        GroupMap groupMap = workSecurityMap.createChild(GroupMap.class);
                        groupMap.setEisGroup((String) e.getKey());
                        groupMap.setMappedGroup((String) e.getValue());
                        workSecurityMap.getGroupMap().add(groupMap);
                    }
                } else {
                // no mapping
                }
                param.getResources().add(workSecurityMap);
                return workSecurityMap;
            }
        }, domain.getResources());
    } catch (TransactionFailure tfe) {
        Logger.getLogger(CreateConnectorWorkSecurityMap.class.getName()).log(Level.SEVERE, "create-connector-work-security-map failed", tfe);
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.fail", "Unable to create connector work security map {0}.", mapName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PrincipalMap(org.glassfish.connectors.config.PrincipalMap) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) GroupMap(org.glassfish.connectors.config.GroupMap) Map(java.util.Map) PrincipalMap(org.glassfish.connectors.config.PrincipalMap) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) GroupMap(org.glassfish.connectors.config.GroupMap)

Example 5 with WorkSecurityMap

use of org.glassfish.connectors.config.WorkSecurityMap in project Payara by payara.

the class DeleteConnectorWorkSecurityMap method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    // ensure we already have this resource
    if (!isResourceExists()) {
        report.setMessage(localStrings.getLocalString("delete.connector.work.security.map.notFound", "A connector work security map named {0} for resource adapter {1} does not exist.", mapName, raName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        // delete connector-work-security-map
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            Collection<WorkSecurityMap> workSecurityMaps = domain.getResources().getResources(WorkSecurityMap.class);

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                for (WorkSecurityMap resource : workSecurityMaps) {
                    if (resource.getName().equals(mapName) && resource.getResourceAdapterName().equals(raName)) {
                        param.getResources().remove(resource);
                        break;
                    }
                }
                return workSecurityMaps;
            }
        }, domain.getResources());
    } catch (TransactionFailure tfe) {
        Logger.getLogger(DeleteConnectorWorkSecurityMap.class.getName()).log(Level.SEVERE, "delete-connector-work-security-map failed", tfe);
        report.setMessage(localStrings.getLocalString("" + "delete.connector.work.security.map.fail", "Unable to delete connector work security map {0} for resource adapter {1}", mapName, raName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport)

Aggregations

WorkSecurityMap (org.glassfish.connectors.config.WorkSecurityMap)12 ActionReport (org.glassfish.api.ActionReport)4 GroupMap (org.glassfish.connectors.config.GroupMap)4 PrincipalMap (org.glassfish.connectors.config.PrincipalMap)4 Resources (com.sun.enterprise.config.serverbeans.Resources)3 PropertyVetoException (java.beans.PropertyVetoException)3 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)3 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)2 Resource (com.sun.enterprise.config.serverbeans.Resource)2 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)2 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)2 ResourceAdapterConfig (org.glassfish.connectors.config.ResourceAdapterConfig)2 Module (com.sun.enterprise.config.serverbeans.Module)1 ConnectorApplication (com.sun.enterprise.connectors.module.ConnectorApplication)1 HashMap (java.util.HashMap)1 Group (org.glassfish.security.common.Group)1 PrincipalImpl (org.glassfish.security.common.PrincipalImpl)1