Advertisement
Guest User

ntlmv2tibco

a guest
May 3rd, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.69 KB | None | 0 0
  1.  
  2. א) פניה ל WEB ב NTLM2.
  3.  
  4. ב) פניה ל WEB עם NTLM2 ו SSL.
  5.  
  6. יש לקחת בחשבון שהתעודות נמצאות בקובץ C:\tibco\tibcojre64\1.8.0\lib\security\cacerts, כאשר משתמשים ב JAVA.
  7. אפשר להוסיף תעודות בעזרת קוד ב JAVA, או על ידי תוכנית בשם KeyStore Explorer 5.2.2
  8. הסיסמה לקובץ היא changeit זו בררת המחדל של JAVA.
  9.  
  10. בקובץ המצורף NTLM.ZP יש דוגמאות ל PROCESS ים, שאני משתמש בהם.(כדי להשתמש, יש להעתיק לספריה במנוע קיים ולבדוק אם לא חסרים משתנים גלובלים, בנוסף יש ללחוץ ב JAVA ACTIVITY על כפתור COMPILE.)
  11.  
  12. צירפתי גם צילום מסך כדי שתזהה את Java Code Activity ותדע איך למקם בתוכו את הקוד.
  13.  
  14. 2. "BW_ntlmv2" זה PROXY להפעלה של NTLM, זה המקור למה שפיתחתי.
  15.  
  16.  
  17.  
  18.  
  19. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  20. 1) NTLM2.SendHTTPRequestNTLM Java Code Activity
  21. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  22.  
  23. package Processes.SubProcesses.NTLM2.SendHTTPRequestNTLM;
  24.  
  25. import java.io.BufferedReader;
  26. import java.io.IOException;
  27. import java.io.InputStream;
  28. import java.io.InputStreamReader;
  29. import java.io.OutputStreamWriter;
  30. import java.net.Authenticator;
  31. import java.net.CookieHandler;
  32. import java.net.CookieManager;
  33. import java.net.CookiePolicy;
  34. import java.net.MalformedURLException;
  35. import java.net.PasswordAuthentication;
  36. import java.net.URL;
  37. import java.net.URLConnection;
  38.  
  39. public class SendHTTPRequestNTLMDo_NTLM{
  40. /****** START SET/GET METHOD, DO NOT MODIFY *****/
  41. protected String stringURL = "";
  42. protected String SoapAction = "";
  43. protected String SOAPxml = "";
  44. protected String UserName = "";
  45. protected String Password = "";
  46. protected String Domain = "";
  47. protected String ContentType = "";
  48. protected String charset = "";
  49. protected String Reply_SOAPxml = "";
  50. public String getstringURL() {
  51. return stringURL;
  52. }
  53. public void setstringURL(String val) {
  54. stringURL = val;
  55. }
  56. public String getSoapAction() {
  57. return SoapAction;
  58. }
  59. public void setSoapAction(String val) {
  60. SoapAction = val;
  61. }
  62. public String getSOAPxml() {
  63. return SOAPxml;
  64. }
  65. public void setSOAPxml(String val) {
  66. SOAPxml = val;
  67. }
  68. public String getUserName() {
  69. return UserName;
  70. }
  71. public void setUserName(String val) {
  72. UserName = val;
  73. }
  74. public String getPassword() {
  75. return Password;
  76. }
  77. public void setPassword(String val) {
  78. Password = val;
  79. }
  80. public String getDomain() {
  81. return Domain;
  82. }
  83. public void setDomain(String val) {
  84. Domain = val;
  85. }
  86. public String getContentType() {
  87. return ContentType;
  88. }
  89. public void setContentType(String val) {
  90. ContentType = val;
  91. }
  92. public String getcharset() {
  93. return charset;
  94. }
  95. public void setcharset(String val) {
  96. charset = val;
  97. }
  98. public String getReply_SOAPxml() {
  99. return Reply_SOAPxml;
  100. }
  101. public void setReply_SOAPxml(String val) {
  102. Reply_SOAPxml = val;
  103. }
  104. /****** END SET/GET METHOD, DO NOT MODIFY *****/
  105. public SendHTTPRequestNTLMDo_NTLM() {
  106. }
  107. public void invoke() throws Exception {
  108. /* Available Variables: DO NOT MODIFY
  109. In : String stringURL
  110. In : String SoapAction
  111. In : String SOAPxml
  112. In : String UserName
  113. In : String Password
  114. In : String Domain
  115. In : String ContentType
  116. In : String charset
  117. Out : String Reply_SOAPxml
  118. * Available Variables: DO NOT MODIFY *****/
  119. CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
  120. Authenticator.setDefault(new MyAuthenticator(getDomain()+"\\"+ getUserName(), getPassword()));
  121. try {
  122. URL url = new URL( getstringURL()); // new URL("http://IISSistemaProduccionDes.santillana.local:82/WebService/WebServiceIntegrador.asmx");
  123. URLConnection connection = url.openConnection();
  124. connection.setDoInput(true);
  125. connection.setDoOutput(true);
  126.  
  127. connection.setReadTimeout(20000);
  128. connection.setConnectTimeout(20000);
  129.  
  130. connection.setUseCaches(false);
  131. connection.setDefaultUseCaches(false);
  132.  
  133. connection.setRequestProperty("Content-Type", getContentType());
  134. connection.setRequestProperty("SOAPAction", getSoapAction());
  135.  
  136. OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
  137. writer.write(getSOAPxml());
  138. writer.flush();
  139. writer.close();
  140.  
  141. InputStream is = connection.getInputStream();
  142. InputStreamReader isr = new InputStreamReader(is, getcharset());
  143. BufferedReader br = new BufferedReader(isr);
  144. while (true) {
  145. String s = br.readLine();
  146. if (s == null)
  147. break;
  148. setReply_SOAPxml(s); //System.out.println(s);
  149. }
  150. // System.out.println("Done");
  151. } catch (MalformedURLException e) {
  152. // TODO Auto-generated catch block
  153. //e.printStackTrace();
  154. } catch (IOException e) {
  155. // TODO Auto-generated catch block
  156. //e.printStackTrace();
  157. }
  158. }
  159.  
  160. class MyAuthenticator extends Authenticator {
  161. private String httpUsername;
  162. private String httpPassword;
  163.  
  164. public MyAuthenticator(String httpUsername, String httpPassword) {
  165. this.httpUsername = httpUsername;
  166. this.httpPassword = httpPassword;
  167. }
  168.  
  169. @Override
  170. protected PasswordAuthentication getPasswordAuthentication() {
  171. return new PasswordAuthentication(httpUsername, httpPassword.toCharArray());
  172. }
  173. }
  174.  
  175. }
  176.  
  177. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  178. 2) NTLM2_SSL.SendHTTPRequestNTLM Java Code Activity
  179. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  180.  
  181. package Processes.SubProcesses.NTLM2_SSL.SendHTTPRequestNTLM;
  182.  
  183. import java.io.BufferedReader;
  184. import java.io.DataOutputStream;
  185. import java.io.IOException;
  186. import java.io.InputStream;
  187.  
  188. import java.io.InputStreamReader;
  189. import java.net.Authenticator;
  190. import java.net.PasswordAuthentication;
  191. import java.net.URL;
  192. import javax.net.ssl.HttpsURLConnection;
  193.  
  194. public class SendHTTPRequestNTLMDo_NTLM{
  195. /****** START SET/GET METHOD, DO NOT MODIFY *****/
  196. protected String stringURL = "";
  197. protected String SoapAction = "";
  198. protected String SOAPxml = "";
  199. protected String UserName = "";
  200. protected String Password = "";
  201. protected String Domain = "";
  202. protected String ContentType = "";
  203. protected String charset = "";
  204. protected String Reply_SOAPxml = "";
  205. public String getstringURL() {
  206. return stringURL;
  207. }
  208. public void setstringURL(String val) {
  209. stringURL = val;
  210. }
  211. public String getSoapAction() {
  212. return SoapAction;
  213. }
  214. public void setSoapAction(String val) {
  215. SoapAction = val;
  216. }
  217. public String getSOAPxml() {
  218. return SOAPxml;
  219. }
  220. public void setSOAPxml(String val) {
  221. SOAPxml = val;
  222. }
  223. public String getUserName() {
  224. return UserName;
  225. }
  226. public void setUserName(String val) {
  227. UserName = val;
  228. }
  229. public String getPassword() {
  230. return Password;
  231. }
  232. public void setPassword(String val) {
  233. Password = val;
  234. }
  235. public String getDomain() {
  236. return Domain;
  237. }
  238. public void setDomain(String val) {
  239. Domain = val;
  240. }
  241. public String getContentType() {
  242. return ContentType;
  243. }
  244. public void setContentType(String val) {
  245. ContentType = val;
  246. }
  247. public String getcharset() {
  248. return charset;
  249. }
  250. public void setcharset(String val) {
  251. charset = val;
  252. }
  253. public String getReply_SOAPxml() {
  254. return Reply_SOAPxml;
  255. }
  256. public void setReply_SOAPxml(String val) {
  257. Reply_SOAPxml = val;
  258. }
  259. /****** END SET/GET METHOD, DO NOT MODIFY *****/
  260. public SendHTTPRequestNTLMDo_NTLM() {
  261. }
  262. public void invoke() throws Exception {
  263. /* Available Variables: DO NOT MODIFY
  264. In : String stringURL
  265. In : String SoapAction
  266. In : String SOAPxml
  267. In : String UserName
  268. In : String Password
  269. In : String Domain
  270. In : String ContentType
  271. In : String charset
  272. Out : String Reply_SOAPxml
  273. * Available Variables: DO NOT MODIFY *****/
  274.  
  275. Reply_SOAPxml = getAuthenticatedResponse(stringURL, Domain,UserName, Password,charset,ContentType,SOAPxml);
  276. }
  277.  
  278. class MyAuthenticator extends Authenticator {
  279. private String httpUsername;
  280. private String httpPassword;
  281.  
  282. public MyAuthenticator(String httpUsername, String httpPassword) {
  283. this.httpUsername = httpUsername;
  284. this.httpPassword = httpPassword;
  285. }
  286.  
  287. @Override
  288. protected PasswordAuthentication getPasswordAuthentication() {
  289. return new PasswordAuthentication(httpUsername, httpPassword.toCharArray());
  290. }
  291. }
  292. private static String getAuthenticatedResponse(final String urlStr,
  293. final String domain, final String userName, final String password,final String charset,final String ContentType,final String SOAPxml)
  294. throws IOException {
  295. StringBuilder response = new StringBuilder();
  296. Authenticator.setDefault(new Authenticator() {
  297. @Override
  298. public PasswordAuthentication getPasswordAuthentication() {
  299. return new PasswordAuthentication(domain + "\\" + userName, password.toCharArray());
  300. }
  301. });
  302. // String requestMessage =null;
  303. String requestMessage = SOAPxml;
  304.  
  305. URL urlRequest = new URL(urlStr);
  306. HttpsURLConnection conn = (HttpsURLConnection) urlRequest
  307. .openConnection();
  308. conn.setDoOutput(true);
  309. conn.setDoInput(true);
  310. conn.setRequestMethod("POST");
  311. conn.setDoInput(true);
  312. conn.setDoOutput(true);
  313. // use caching
  314. conn.setUseCaches(false);
  315. conn.setRequestProperty("Content-Type", ContentType + "; charset="+charset);
  316. // Write post data
  317. DataOutputStream out = new DataOutputStream(conn.getOutputStream());
  318. out.writeBytes(requestMessage);
  319. out.flush();
  320. out.close();
  321. InputStream stream = conn.getInputStream();
  322. BufferedReader in = new BufferedReader(new InputStreamReader(stream));
  323. String str = "";
  324. while ((str = in.readLine()) != null) {
  325. response.append(str);
  326. }
  327. in.close();
  328. return response.toString();
  329. }
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement