// greetMe will use session to return last called name public String greetMe(String me) { LOG.info("Executing operation greetMe"); LOG.info("Message received: " + me); MessageContext mc = context.getMessageContext(); HttpServletRequest req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST); Cookie cookies[] = req.getCookies(); String val = ""; if (cookies != null) { for (Cookie cookie : cookies) { val += ";" + cookie.getName() + "=" + cookie.getValue(); } } HttpSession session = req.getSession(); // Get a session property "counter" from context if (session == null) { throw new WebServiceException("No session in WebServiceContext"); } String name = (String) session.getAttribute("name"); if (name == null) { name = me; LOG.info("Starting the Session"); } session.setAttribute("name", me); return "Hello " + name + val; }
/** * Metodo privado del webservice que permite la autenticacion basica por metodo * * @return */ @SuppressWarnings({"unused", "rawtypes"}) private String doAuthentication() { String resultado = "OK"; MessageContext mctx = context.getMessageContext(); Map http_headers = (Map) mctx.get(MessageContext.HTTP_REQUEST_HEADERS); ArrayList list = (ArrayList) http_headers.get("Authorization"); if (list == null || list.size() == 0) { resultado = "ESTE WEBSERVICE REQUIERE AUTENTICACIÓN BÁSICA."; } else { String userpass = (String) list.get(0); userpass = userpass.substring(5); byte[] buf = Base64.decodeBase64(userpass.getBytes()); String credentials = new String(buf); String username = null; String password = null; int p = credentials.indexOf(":"); if (p > -1) { username = credentials.substring(0, p); password = credentials.substring(p + 1); } else { resultado = "ERROR DECODIFICANDO USUARIO Y PASSWORD"; } try { if ("jmoreno".equalsIgnoreCase(username)) { resultado = "OK"; } else { resultado = "USUARIO Y PASSWORD INCORRECTOS"; } } catch (Exception e) { resultado = e.getMessage(); } } return resultado; }
/** * This method returns the OnPremise AuthPolicy and next two endpoint the mobile device should * call if this response to received successfully at the device end. This method is called by * device immediately after the first GET method calling for the same endpoint. * * @param discoveryRequest - Request bean comes via mobile phone * @param response - DiscoveryResponse bean for response */ @Override public void discover(DiscoveryRequest discoveryRequest, Holder<DiscoveryResponse> response) { ServletContext ctx = (ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT); WindowsPluginProperties windowsPluginProperties = (WindowsPluginProperties) ctx.getAttribute(Constants.WINDOWS_PLUGIN_PROPERTIES); DiscoveryResponse discoveryResponse = new DiscoveryResponse(); if (FEDERATED.equals(windowsPluginProperties.getAuthPolicy())) { discoveryResponse.setAuthPolicy(windowsPluginProperties.getAuthPolicy()); discoveryResponse.setEnrollmentPolicyServiceUrl( Constants.Discovery.CERTIFICATE_ENROLLMENT_POLICY_SERVICE_URL); discoveryResponse.setEnrollmentServiceUrl( Constants.Discovery.CERTIFICATE_ENROLLMENT_SERVICE_URL); discoveryResponse.setAuthenticationServiceUrl(Constants.Discovery.WAB_URL); } else { discoveryResponse.setAuthPolicy(windowsPluginProperties.getAuthPolicy()); discoveryResponse.setEnrollmentPolicyServiceUrl( Constants.Discovery.ONPREMISE_CERTIFICATE_ENROLLMENT_POLICY); discoveryResponse.setEnrollmentServiceUrl( Constants.Discovery.ONPREMISE_CERTIFICATE_ENROLLMENT_SERVICE_URL); discoveryResponse.setAuthenticationServiceUrl(null); } response.value = discoveryResponse; if (log.isDebugEnabled()) { log.debug("Discovery service end point was triggered via POST method"); } }
public Source invoke(Source source) { // TestLogger.logger.debug(">> SourceProvider: Request received.\n"); if (source == null) { return source; } if (context == null) { // TestLogger.logger.debug("[DynamicServiceProvider] the WebServiceContext was null."); throw new WebServiceException("A WebServiceException should have been injected."); } QName wsdlService = (QName) context.getMessageContext().get(MessageContext.WSDL_SERVICE); QName wsdlOperation = (QName) context.getMessageContext().get(MessageContext.WSDL_OPERATION); System.out.println("[DynamicServiceProvider] service name: " + wsdlService); System.out.println("[DynamicServiceProvider] operation name: " + wsdlOperation); // TestLogger.logger.debug("[DynamicServiceProvider] service name: " + wsdlService); // TestLogger.logger.debug("[DynamicServiceProvider] operation name: " + wsdlOperation); StringWriter writer = new StringWriter(); try { Transformer t = TransformerFactory.newInstance().newTransformer(); Result result = new StreamResult(writer); t.transform(source, result); } catch (TransformerConfigurationException e) { throw new WebServiceException(e); } catch (TransformerFactoryConfigurationError e) { throw new WebServiceException(e); } catch (TransformerException e) { throw new WebServiceException(e); } String text = writer.getBuffer().toString(); // TestLogger.logger.debug(">> Source Request on Server: \n" + text); if (text != null && text.contains("throwWebServiceException")) { throw new WebServiceException("provider"); } ByteArrayInputStream stream = new ByteArrayInputStream(text.getBytes()); Source srcStream = new StreamSource((InputStream) stream); return srcStream; }
/* * This complicated getter needed so the EditServiceHelper object will be in the Spring context */ public EditServiceHelper getEditServiceHelper() { if (editServiceHelper == null) { ServletContext servletContext = (ServletContext) context.getMessageContext().get("javax.xml.ws.servlet.context"); WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); editServiceHelper = webApplicationContext.getAutowireCapableBeanFactory().getBean(EditServiceHelper.class); } return editServiceHelper; }
@WebMethod public Long addActivity(Activity activity) { MessageContext mctx = wsctx.getMessageContext(); Map http_headers = (Map) mctx.get(MessageContext.HTTP_REQUEST_HEADERS); List<Object> tokenList = (List<Object>) http_headers.get(Const.AUTH_TOKEN); Long userId = new Long(tokenList.get(0).toString()); // TODO user extraction by token activity.setUser(new User(userId)); return activityService.addActivity(activity); }
private SocialApp getSocialApp() throws JAXBException, IOException { ServletContext application = (ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT); synchronized (application) { SocialApp socialApp = (SocialApp) application.getAttribute("socialApp"); if (socialApp == null) { socialApp = new SocialApp(); socialApp.setFilePath(application.getRealPath("users.xml")); application.setAttribute("socialApp", socialApp); } return socialApp; } }
public String queryPermission(FhiUser fu) { MessageContext ctx = context.getMessageContext(); HttpServletRequest request = (HttpServletRequest) ctx.get(AbstractHTTPDestination.HTTP_REQUEST); HttpSession session = request.getSession(); String str = ""; str = userServiceImple.queryWebService(fu); if ("true".equals(str.toString())) { session.setAttribute("wmsRFhiUser", fu); return "true"; } else { return "false"; } }
private static SOAPMessageContext getSOAPMessageContext(MessageContext jaxwsMessageContext) { org.apache.axis2.context.MessageContext msgContext = jaxwsMessageContext.getAxisMessageContext(); ServiceContext serviceContext = msgContext.getServiceContext(); SOAPMessageContext soapMessageContext = null; if (serviceContext != null) { WebServiceContext wsc = (WebServiceContext) serviceContext.getProperty(EndpointLifecycleManagerImpl.WEBSERVICE_MESSAGE_CONTEXT); if (wsc != null) { soapMessageContext = (SOAPMessageContext) wsc.getMessageContext(); } } return soapMessageContext; }
public int doubleIt(int numberToDouble) { // // Get the transformed SAML Assertion from the STS and check it // MessageContext context = wsc.getMessageContext(); final List<WSHandlerResult> handlerResults = CastUtils.cast((List<?>) context.get(WSHandlerConstants.RECV_RESULTS)); WSSecurityEngineResult actionResult = WSSecurityUtil.fetchActionResult(handlerResults.get(0).getResults(), WSConstants.UT); SamlAssertionWrapper assertion = (SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_TRANSFORMED_TOKEN); Assert.assertTrue(assertion != null && "DoubleItSTSIssuer".equals(assertion.getIssuerString())); return numberToDouble * 2; }
public void greetMeOneWay(String me) { LOG.info("Executing operation greetMeOneWay"); LOG.info("Message received: " + me); MessageContext mc = context.getMessageContext(); HttpServletRequest req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST); HttpSession session = req.getSession(); if (session == null) { throw new WebServiceException("No session in WebServiceContext"); } String name = (String) session.getAttribute("name"); if (name == null) { name = me; LOG.info("Starting the Session"); } session.setAttribute("name", me); }
public static final void disableMTOMResponse(WebServiceContext wsContext) { MessageContext msgCtx = wsContext.getMessageContext(); WrappedMessageContext wmc = (WrappedMessageContext) msgCtx; Exchange ex = wmc.getWrappedMessage().getExchange(); Message out = ex.getOutMessage(); if (out != null) { int i = 0; for (; MessageUtils.isTrue(out.getContextualProperty(Message.MTOM_ENABLED)) && i < 10; i++) { out.setContextualProperty(Message.MTOM_ENABLED, false); log.debug( "###### disableMTOM! enabled:{}", out.getContextualProperty(Message.MTOM_ENABLED)); } if (i > 1) log.warn( "###### disable MTOM needs " + i + " tries! enabled:{}", out.getContextualProperty(Message.MTOM_ENABLED)); } log.debug("###### MTOM enabled? {}:", out.getContextualProperty(Message.MTOM_ENABLED)); }
protected MessageContext getMessageContext() { MessageContext msgCtx = context.getMessageContext(); return msgCtx; }