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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations