Skip to content

Commit

Permalink
Ability to send credentials to web soap client
Browse files Browse the repository at this point in the history
  • Loading branch information
aeraln committed Nov 25, 2014
1 parent 53d71f6 commit f5c7e58
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/interfaces/web/wsdl-client/target/
18 changes: 18 additions & 0 deletions interfaces/web/wsdl-client/nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
</properties>
</project-shared-configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package eu.impact_project.wsclient;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Base64;

public class Security {
public static String encrypt(String input, String key){
byte[] crypted = null;
try{
SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skey);
crypted = cipher.doFinal(input.getBytes());
}catch(Exception e){
System.out.println(e.toString());
}
return new String(Base64.encodeBase64(crypted));
}

public static String decrypt(String input, String key){
byte[] output = null;
try{
SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, skey);
output = cipher.doFinal(Base64.decodeBase64(input));
}catch(Exception e){
System.out.println("Error: " + e.toString());
}
return new String(output);
}

public static void main(String[] args) {
String key = "1234567891234567";
String data = "example";
System.out.println(Security.decrypt(Security.encrypt(data, key), key));
System.out.println(Security.encrypt(data, key));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ protected void doGet(HttpServletRequest request,
session.setAttribute("wsName", wsName);
}

//pasar user y pass decodificados por sesion

String key = "1234567891234567";

String wsUser = "";
if(request.getParameter("user") != null)
{
if(request.getParameter("user") != "")
{
wsUser = Security.decrypt(request.getParameter("user"),key);
session.setAttribute("wsUser", wsUser);
}
}

String wsPass = "";
if(request.getParameter("pass") != null)
{
if(request.getParameter("pass") != "")
{
wsPass = Security.decrypt(request.getParameter("pass"),key);
session.setAttribute("wsPass", wsPass);
}
}

logger.info("URL WSDL: " + wsdlURL);
SoapService serviceObject = new SoapService(wsdlURL);

Expand Down Expand Up @@ -158,6 +182,31 @@ protected void doPost(HttpServletRequest request,
session.setAttribute("wsName", wsName);
}

//pasar user y pass decodificados por sesion

String key = "1234567891234567";

String wsUser = "";
if(request.getParameter("user")!=null)
{
if(request.getParameter("user") != "")
{
wsUser = Security.decrypt(request.getParameter("user"),key);
session.setAttribute("wsUser", wsUser);
}
}

String wsPass = "";
if(request.getParameter("pass")!=null)
{
if(request.getParameter("pass") != "")
{
wsPass = Security.decrypt(request.getParameter("pass"),key);
session.setAttribute("wsPass", wsPass);
}
}


logger.info("URL WSDL: " + wsdlURL);
SoapService serviceObject = new SoapService(wsdlURL);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/WS-Client"/>
2 changes: 2 additions & 0 deletions interfaces/web/wsdl-client/src/main/webapp/config.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
servicesXml=http://impact.dlsi.ua.es/Services.xml

styleSheet=css/style.css


loadDefaultWebService = false
defaultWsdl = http://impact.dlsi.ua.es/services/IMPACTGimpImageConversionService?wsdl
Expand Down
3 changes: 1 addition & 2 deletions interfaces/web/wsdl-client/src/main/webapp/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,4 @@ select {
-moz-appearance:none;
appearance:none;
cursor:pointer;
}
}
33 changes: 24 additions & 9 deletions interfaces/web/wsdl-client/src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@

<%@page import="org.slf4j.Logger"%>
<%@page import="org.slf4j.LoggerFactory"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
<title>IMPACT Web Service Client</title>
</head>
<body onload="document.forms['defaultForm'].submit()">


<%
Expand All @@ -67,16 +61,29 @@ if (separatedURLServices)
String defaultWsdl = props.getProperty("defaultWsdl");
String userCrypt = request.getParameter("user");
String passCrypt = request.getParameter("pass");
String style = props.getProperty("styleSheet");
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<%=style%>" media="screen" />
<title>IMPACT Web Service Client</title>
</head>
<body onload="document.forms['defaultForm'].submit()">

<%
if (loadDefault.equals("true")) {
%>

<form name="defaultForm" action="WSDLinfo" method="post">
<input type="hidden" name="wsName" value="user_defined">

<input type="hidden" name="wsdlURL" value="<%= defaultWsdl %>">
<input type="hidden" name="wsdlURL" value="<%=defaultWsdl%>">

</form>

Expand Down Expand Up @@ -117,6 +124,12 @@ if (loadDefault.equals("true")) {
logger.debug("Got service " + s.getIdentifier());
out.print("<form name=\"myForm" + s.getIdentifier()
+ "\" action=\"WSDLinfo\" method=\""+ method + "\">");
out.print("<input type=\"hidden\" name=\"user\" value=\""
+ userCrypt!=null?userCrypt:"" + "\">");
out.print("<input type=\"hidden\" name=\"pass\" value=\""
+ passCrypt!=null?passCrypt:"" + "\">");
out.print("<input type=\"hidden\" name=\"wsName\" value=\""
+ s.getTitle() + "\">");
out.print("<input type=\"hidden\" name=\"wsId\" value=\""
Expand All @@ -132,7 +145,6 @@ if (loadDefault.equals("true")) {
}catch(RuntimeException e) {
out.print("IMPACT services list could not be loaded");
}
%>

<br>
Expand All @@ -141,8 +153,11 @@ if (loadDefault.equals("true")) {

<form action="WSDLinfo" method="post">
<input type="hidden" name="wsName" value="user_defined">
<input type="hidden" name="user" value="<%=userCrypt!=null?userCrypt:""%>">
<input type="hidden" name="pass" value="<%=passCrypt!=null?passCrypt:""%>">

<h4>Other</h4>

<input type="text" size="70" name="wsdlURL" value="<%if (session.getAttribute("wsdlURL") != null)
out.print(session.getAttribute("wsdlURL"));%>">
<br>
Expand Down
80 changes: 46 additions & 34 deletions interfaces/web/wsdl-client/src/main/webapp/interface.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,6 @@
<%@page import="java.util.Properties"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.net.URL"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/index.js" type="text/javascript"></script>
<title>IMPACT Web Service Client</title>
<script language="JavaScript">
function getUrl(id) {
var url = document.getElementById(id).value;
var detailsWindow = window.open(url,"", "resizable,width=800,height=700,scrollbars,left=200,top=100");
detailsWindow.focus();
}
function setStyle(element) {
element.style.textDecoration = "underline";
element.style.cursor = "pointer";
}
function removeStyle(element) {
element.style.textDecoration = "none";
element.style.cursor = "default";
}
</script>
</head>
<%
Expand All @@ -86,15 +58,55 @@ boolean supportFileUpload = Boolean.parseBoolean(props.getProperty("supportFileU
boolean showResultFilesOnly = Boolean.parseBoolean(props.getProperty("showResultFilesOnly"));
boolean editableInputs = Boolean.parseBoolean(props.getProperty("editableInputs"));
boolean security = Boolean.parseBoolean(props.getProperty("security"));
/*
String user = props.getProperty("user");
String pass = props.getProperty("pass");
*/
//Ahora los cojo de la sesion
String user = (String) session.getAttribute("wsUser");
String pass = (String) session.getAttribute("wsPass");
String style = props.getProperty("styleSheet");
//filtro null
user = user!=null?user:"";
pass = pass!=null?pass:"";
SoapService serviceObject = null;
if(session.getAttribute("serviceObject") != null) {
serviceObject = (SoapService)session.getAttribute("serviceObject");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<%=style%>" media="screen" />
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/index.js" type="text/javascript"></script>
<title>IMPACT Web Service Client</title>
<script language="JavaScript">
function getUrl(id) {
var url = document.getElementById(id).value;
var detailsWindow = window.open(url,"", "resizable,width=800,height=700,scrollbars,left=200,top=100");
detailsWindow.focus();
}
function setStyle(element) {
element.style.textDecoration = "underline";
element.style.cursor = "pointer";
}
function removeStyle(element) {
element.style.textDecoration = "none";
element.style.cursor = "default";
}
</script>
</head>
<body <%if(loadDefault && request.getAttribute("round2") == null && request.getAttribute("round3") == null)
{ %>onload="document.forms['defaultForm'].submit()"<%} %>>

Expand Down Expand Up @@ -129,10 +141,10 @@ if(session.getAttribute("serviceObject") != null) {
out.print("<h1>" + session.getAttribute("wsName") + "</h1>");
out.print("<br>");
out.print("<span class=\"btn1\">");
out.print("<a id=\"back\" href=\"http://www.digitisation.eu/tools/browse/interoperability-framework/demonstrator-platform/ \" ONCLICK=\"window.parent.location='http://www.digitisation.eu/tools/interoperability-framework/demonstrator-platform/'\">");
out.print("<span>Back to Selection</span>");
out.print("</a></span>");
//out.print("<span class=\"btn1\">");
//out.print("<a id=\"back\" href=\"http://www.digitisation.eu/tools/browse/interoperability-framework/demonstrator-platform/ \" ONCLICK=\"window.parent.location='http://www.digitisation.eu/tools/interoperability-framework/demonstrator-platform/'\">");
//out.print("<span>Back to Selection</span>");
//out.print("</a></span>");
out.print("<p>" + serviceObject.getDocumentation() + "</p>");
Expand Down Expand Up @@ -213,10 +225,10 @@ if(session.getAttribute("serviceObject") != null) {
<tr>
<td>
User:<br>
<input type="text" name="user" value="">
<input type="text" name="user" value="<%=user%>">
</td>
<td>
Password:<br> <input type="password" name="pass" value="">
Password:<br> <input type="password" name="pass" value="<%=pass%>">
</td>
</tr>
<td>
Expand Down

0 comments on commit f5c7e58

Please sign in to comment.