diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/component/RunReportPopupPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/component/RunReportPopupPanel.java index ea84095d019..2de38a6ea79 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/component/RunReportPopupPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/component/RunReportPopupPanel.java @@ -190,6 +190,9 @@ private void runConfirmPerformed(AjaxRequestTarget target, IModel mod reportParamValue.revive(getPrismContext()); paramContainer.add(reportParamValue); for (JasperReportParameterDto paramDto : params){ + if (paramDto.getValue() == null){ + continue; + } QName typeName = null; if (XmlTypeConverter.canConvert(paramDto.getType())){ typeName = XsdTypeMapper.toXsdType(paramDto.getType()); diff --git a/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/MidPointClientConfiguration.java b/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/MidPointClientConfiguration.java new file mode 100644 index 00000000000..6d72339ac23 --- /dev/null +++ b/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/MidPointClientConfiguration.java @@ -0,0 +1,86 @@ +package com.evolveum.midpoint.report.ds.impl; + +import java.util.HashMap; +import java.util.Map; + +import javax.xml.ws.BindingProvider; + +import org.apache.cxf.frontend.ClientProxy; +import org.apache.cxf.interceptor.LoggingInInterceptor; +import org.apache.cxf.interceptor.LoggingOutInterceptor; +import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; +import org.apache.wss4j.dom.WSConstants; +import org.apache.wss4j.dom.handler.WSHandlerConstants; + +import com.evolveum.midpoint.xml.ns._public.report.report_3.ReportPortType; +import com.evolveum.midpoint.xml.ns._public.report.report_3.ReportService; + +public class MidPointClientConfiguration { + + private String username; + private String password; + private String endpoint; + + public MidPointClientConfiguration() { + System.out.println("client configuration init"); + } + + + public ReportPortType createReportPort() { + System.out.println("creating endpoint with credentials " + username + ": " + password); + System.out.println("Endpoint URL: "+ endpoint); + ClientPasswordHandler.setPassword(password); + + // uncomment this if you want to use Fiddler or any other proxy + //ProxySelector.setDefault(new MyProxySelector("127.0.0.1", 8888)); + + ReportService reportService = new ReportService(); + ReportPortType reportPort = reportService.getReportPort(); + BindingProvider bp = (BindingProvider)reportPort; + Map requestContext = bp.getRequestContext(); + requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint); + + org.apache.cxf.endpoint.Client client = ClientProxy.getClient(reportPort); + org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint(); + + Map outProps = new HashMap(); + + outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); + outProps.put(WSHandlerConstants.USER, username); + outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST); + outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName()); + + WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps); + cxfEndpoint.getOutInterceptors().add(wssOut); + // enable the following to get client-side logging of outgoing requests and incoming responses + cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor()); + cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor()); + + return reportPort; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getEndpoint() { + return endpoint; + } + + public void setEndpoint(String endpoint) { + this.endpoint = endpoint; + } + +} diff --git a/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/MidPointRemoteQueryExecutor.java b/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/MidPointRemoteQueryExecutor.java index 5c78b50cfdc..0d2d8a5e6e0 100644 --- a/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/MidPointRemoteQueryExecutor.java +++ b/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/MidPointRemoteQueryExecutor.java @@ -1,11 +1,9 @@ package com.evolveum.midpoint.report.ds.impl; import java.io.Serializable; -import java.util.HashMap; import java.util.Map; import javax.xml.bind.JAXBElement; -import javax.xml.ws.BindingProvider; import net.sf.jasperreports.engine.JRDataSource; import net.sf.jasperreports.engine.JRDataset; @@ -16,12 +14,8 @@ import net.sf.jasperreports.engine.base.JRBaseParameter; import net.sf.jasperreports.engine.query.JRAbstractQueryExecuter; -import org.apache.cxf.frontend.ClientProxy; -import org.apache.cxf.interceptor.LoggingInInterceptor; -import org.apache.cxf.interceptor.LoggingOutInterceptor; -import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; -import org.apache.wss4j.dom.WSConstants; -import org.apache.wss4j.dom.handler.WSHandlerConstants; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; import com.evolveum.midpoint.prism.query.InOidFilter; import com.evolveum.midpoint.prism.query.ObjectFilter; @@ -36,14 +30,13 @@ import com.evolveum.midpoint.xml.ns._public.common.common_3.EntryType; import com.evolveum.midpoint.xml.ns._public.common.common_3.ParamsType; import com.evolveum.midpoint.xml.ns._public.report.report_3.ReportPortType; -import com.evolveum.midpoint.xml.ns._public.report.report_3.ReportService; public class MidPointRemoteQueryExecutor extends JRAbstractQueryExecuter{ // Configuration - public static final String ADM_USERNAME = "administrator"; - public static final String ADM_PASSWORD = "5ecr3t"; - private static final String DEFAULT_ENDPOINT_URL = "http://localhost:8080/midpoint/ws/report-3"; +// public static final String ADM_USERNAME = "administrator"; +// public static final String ADM_PASSWORD = "5ecr3t"; +// private static final String DEFAULT_ENDPOINT_URL = "http://localhost:8080/midpoint/ws/report-3"; private String query; private ReportPortType reportPort; @@ -59,15 +52,6 @@ public String getQuery() { @Override protected void parseQuery() { query = getStringQuery(); - -// ParamsType params = getParameters(); -// LOGGER.trace("Report query: " + queryString); -// ObjectQuery q; -// if (StringUtils.isEmpty(queryString)) { -// q = null; -// } else { -// query = reportPort.parseQuery(queryString, params); -// } } @@ -85,7 +69,25 @@ private boolean containsExpression(ObjectFilter subFilter){ protected MidPointRemoteQueryExecutor(JasperReportsContext jasperReportsContext, JRDataset dataset, Map parametersMap) { super(jasperReportsContext, dataset, parametersMap); - reportPort = createReportPort(null); + ApplicationContext applicationContext = new ClassPathXmlApplicationContext("ctx-report-ds-context.xml"); + MidPointClientConfiguration clientConfig = (MidPointClientConfiguration) applicationContext.getBean("clientConfig"); +// Properties prop = new Properties(); +// String propFileName = "client.properties"; +// +// InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName); +// +// try { +// prop.load(inputStream); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// +// MidPointClientConfiguration clientConfig = new MidPointClientConfiguration(); +// clientConfig.setEndpoint((String) prop.get("service.endpoint")); +// clientConfig.setUsername((String) prop.get("auth.username")); +// clientConfig.setPassword((String) prop.get("auht.password")); + reportPort = clientConfig.createReportPort(); +// reportPort = createReportPort(); parseQuery(); } @@ -136,42 +138,42 @@ protected String getParameterReplacement(String parameterName) { throw new UnsupportedOperationException("QueryExecutor.getParameterReplacement() not supported"); } - private static ReportPortType createReportPort(String[] args) { - String endpointUrl = DEFAULT_ENDPOINT_URL; - - if (args != null && args.length > 0) { - endpointUrl = args[0]; - } - - System.out.println("Endpoint URL: "+endpointUrl); - - // uncomment this if you want to use Fiddler or any other proxy - //ProxySelector.setDefault(new MyProxySelector("127.0.0.1", 8888)); - - ReportService reportService = new ReportService(); - ReportPortType reportPort = reportService.getReportPort(); - BindingProvider bp = (BindingProvider)reportPort; - Map requestContext = bp.getRequestContext(); - requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl); - - org.apache.cxf.endpoint.Client client = ClientProxy.getClient(reportPort); - org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint(); - - Map outProps = new HashMap(); - - outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); - outProps.put(WSHandlerConstants.USER, ADM_USERNAME); - outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST); - outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName()); - - WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps); - cxfEndpoint.getOutInterceptors().add(wssOut); - // enable the following to get client-side logging of outgoing requests and incoming responses - cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor()); - cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor()); - - return reportPort; - } +// private static ReportPortType createReportPort(String[] args) { +// String endpointUrl = DEFAULT_ENDPOINT_URL; +// +// if (args != null && args.length > 0) { +// endpointUrl = args[0]; +// } +// +// System.out.println("Endpoint URL: "+endpointUrl); +// +// // uncomment this if you want to use Fiddler or any other proxy +// //ProxySelector.setDefault(new MyProxySelector("127.0.0.1", 8888)); +// +// ReportService reportService = new ReportService(); +// ReportPortType reportPort = reportService.getReportPort(); +// BindingProvider bp = (BindingProvider)reportPort; +// Map requestContext = bp.getRequestContext(); +// requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl); +// +// org.apache.cxf.endpoint.Client client = ClientProxy.getClient(reportPort); +// org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint(); +// +// Map outProps = new HashMap(); +// +// outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); +// outProps.put(WSHandlerConstants.USER, ADM_USERNAME); +// outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST); +// outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName()); +// +// WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps); +// cxfEndpoint.getOutInterceptors().add(wssOut); +// // enable the following to get client-side logging of outgoing requests and incoming responses +// cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor()); +// cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor()); +// +// return reportPort; +// } private String getStringQuery(){ if (dataset.getQuery() == null){ diff --git a/model/report-ds-impl/src/main/resources/client.properties b/model/report-ds-impl/src/main/resources/client.properties new file mode 100644 index 00000000000..d929e328bc9 --- /dev/null +++ b/model/report-ds-impl/src/main/resources/client.properties @@ -0,0 +1,5 @@ +#client configuration for jasper remote query executer +service.endpoint=http://localhost:8080/midpoint/ws/report-3 + +auth.username=administrator +auht.password=5ecr3t \ No newline at end of file diff --git a/model/report-ds-impl/src/main/resources/ctx-report-ds-context.xml b/model/report-ds-impl/src/main/resources/ctx-report-ds-context.xml new file mode 100644 index 00000000000..ac39a7ea57a --- /dev/null +++ b/model/report-ds-impl/src/main/resources/ctx-report-ds-context.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportCreateTaskHandler.java b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportCreateTaskHandler.java index 5ef51333159..44bf62b9d1a 100644 --- a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportCreateTaskHandler.java +++ b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportCreateTaskHandler.java @@ -160,34 +160,18 @@ public TaskRunResult run(Task task) { Map parameters = completeReport(parentReport, result); PrismContainer reportParams = (PrismContainer) task.getExtensionItem(ReportConstants.REPORT_PARAMS_PROPERTY_NAME); - if (reportParams != null){ - PrismContainerValue reportParamsValues = reportParams.getValue(); - List> items = reportParamsValues.getItems(); - for (Item item : items){ - PrismProperty pp = (PrismProperty) item; - Object value = pp.getRealValue(); - String paramName = ItemPath.getName(pp.getPath().lastNamed()).getLocalPart(); - parameters.put(paramName, value); - } - - - -// -// for (PrismPropertyValue paramValue : getV){ -// ReportParameterType val = paramValue.getValue(); -// Class clazz = Class.forName(val.getType()); -// Object value = null; -// if (XmlTypeConverter.canConvert(clazz)){ -// value = XmlTypeConverter.toJavaValue(val.getValue(), clazz); -// } else { -// XNode xnode = prismContext.getParserDom().parse(val.getValue()); -// value = prismContext.getBeanConverter().unmarshall(xnode, clazz); -// -// } - -// } - } - + if (reportParams != null) { + PrismContainerValue reportParamsValues = reportParams.getValue(); + List> items = reportParamsValues.getItems(); + if (items != null) { + for (Item item : items) { + PrismProperty pp = (PrismProperty) item; + Object value = pp.getRealValue(); + String paramName = ItemPath.getName(pp.getPath().lastNamed()).getLocalPart(); + parameters.put(paramName, value); + } + } + } JasperReport jasperReport = ReportTypeUtil.loadJasperReport(parentReport); LOGGER.trace("compile jasper design, create jasper report : {}", jasperReport); diff --git a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportManagerImpl.java b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportManagerImpl.java index 2da8cce27cd..c03d274d854 100644 --- a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportManagerImpl.java +++ b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportManagerImpl.java @@ -163,14 +163,7 @@ public void runReport(PrismObject object, PrismContainer propertyDef = prismContext.getSchemaRegistry().findContainerDefinitionByElementName(ReportConstants.REPORT_PARAMS_PROPERTY_NAME); -// PrismContainer container = propertyDef.instantiate(); -// for (ReportParameterType reportParam : params){ -// container.add(reportParam.asPrismContainerValue()); -// } - task.setExtensionContainer(paramContainer); - } } catch (SchemaException e) { throw new SystemException(e); diff --git a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportWebService.java b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportWebService.java index d2831198a36..090e620bc66 100644 --- a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportWebService.java +++ b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportWebService.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Map; +import javax.xml.bind.JAXBElement; import javax.xml.namespace.QName; import org.springframework.beans.factory.annotation.Autowired; @@ -178,7 +179,14 @@ private Map getParamsMap(ParamsType parameters){ if (parameters != null) { params = new HashMap(); for (EntryType entry : parameters.getEntry()) { - params.put(new QName(entry.getKey()), (Serializable) entry.getEntryValue()); + Object obj = entry.getEntryValue(); + Serializable value = null; + if (obj instanceof JAXBElement){ + value = (Serializable) ((JAXBElement) obj).getValue(); + } else { + value = (Serializable) entry.getEntryValue(); + } + params.put(new QName(entry.getKey()), value); } } return params;