Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- א) פניה ל WEB ב NTLM2.
- ב) פניה ל WEB עם NTLM2 ו SSL.
- יש לקחת בחשבון שהתעודות נמצאות בקובץ C:\tibco\tibcojre64\1.8.0\lib\security\cacerts, כאשר משתמשים ב JAVA.
- אפשר להוסיף תעודות בעזרת קוד ב JAVA, או על ידי תוכנית בשם KeyStore Explorer 5.2.2
- הסיסמה לקובץ היא changeit זו בררת המחדל של JAVA.
- בקובץ המצורף NTLM.ZP יש דוגמאות ל PROCESS ים, שאני משתמש בהם.(כדי להשתמש, יש להעתיק לספריה במנוע קיים ולבדוק אם לא חסרים משתנים גלובלים, בנוסף יש ללחוץ ב JAVA ACTIVITY על כפתור COMPILE.)
- צירפתי גם צילום מסך כדי שתזהה את Java Code Activity ותדע איך למקם בתוכו את הקוד.
- 2. "BW_ntlmv2" זה PROXY להפעלה של NTLM, זה המקור למה שפיתחתי.
- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- 1) NTLM2.SendHTTPRequestNTLM Java Code Activity
- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- package Processes.SubProcesses.NTLM2.SendHTTPRequestNTLM;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.net.Authenticator;
- import java.net.CookieHandler;
- import java.net.CookieManager;
- import java.net.CookiePolicy;
- import java.net.MalformedURLException;
- import java.net.PasswordAuthentication;
- import java.net.URL;
- import java.net.URLConnection;
- public class SendHTTPRequestNTLMDo_NTLM{
- /****** START SET/GET METHOD, DO NOT MODIFY *****/
- protected String stringURL = "";
- protected String SoapAction = "";
- protected String SOAPxml = "";
- protected String UserName = "";
- protected String Password = "";
- protected String Domain = "";
- protected String ContentType = "";
- protected String charset = "";
- protected String Reply_SOAPxml = "";
- public String getstringURL() {
- return stringURL;
- }
- public void setstringURL(String val) {
- stringURL = val;
- }
- public String getSoapAction() {
- return SoapAction;
- }
- public void setSoapAction(String val) {
- SoapAction = val;
- }
- public String getSOAPxml() {
- return SOAPxml;
- }
- public void setSOAPxml(String val) {
- SOAPxml = val;
- }
- public String getUserName() {
- return UserName;
- }
- public void setUserName(String val) {
- UserName = val;
- }
- public String getPassword() {
- return Password;
- }
- public void setPassword(String val) {
- Password = val;
- }
- public String getDomain() {
- return Domain;
- }
- public void setDomain(String val) {
- Domain = val;
- }
- public String getContentType() {
- return ContentType;
- }
- public void setContentType(String val) {
- ContentType = val;
- }
- public String getcharset() {
- return charset;
- }
- public void setcharset(String val) {
- charset = val;
- }
- public String getReply_SOAPxml() {
- return Reply_SOAPxml;
- }
- public void setReply_SOAPxml(String val) {
- Reply_SOAPxml = val;
- }
- /****** END SET/GET METHOD, DO NOT MODIFY *****/
- public SendHTTPRequestNTLMDo_NTLM() {
- }
- public void invoke() throws Exception {
- /* Available Variables: DO NOT MODIFY
- In : String stringURL
- In : String SoapAction
- In : String SOAPxml
- In : String UserName
- In : String Password
- In : String Domain
- In : String ContentType
- In : String charset
- Out : String Reply_SOAPxml
- * Available Variables: DO NOT MODIFY *****/
- CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
- Authenticator.setDefault(new MyAuthenticator(getDomain()+"\\"+ getUserName(), getPassword()));
- try {
- URL url = new URL( getstringURL()); // new URL("http://IISSistemaProduccionDes.santillana.local:82/WebService/WebServiceIntegrador.asmx");
- URLConnection connection = url.openConnection();
- connection.setDoInput(true);
- connection.setDoOutput(true);
- connection.setReadTimeout(20000);
- connection.setConnectTimeout(20000);
- connection.setUseCaches(false);
- connection.setDefaultUseCaches(false);
- connection.setRequestProperty("Content-Type", getContentType());
- connection.setRequestProperty("SOAPAction", getSoapAction());
- OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
- writer.write(getSOAPxml());
- writer.flush();
- writer.close();
- InputStream is = connection.getInputStream();
- InputStreamReader isr = new InputStreamReader(is, getcharset());
- BufferedReader br = new BufferedReader(isr);
- while (true) {
- String s = br.readLine();
- if (s == null)
- break;
- setReply_SOAPxml(s); //System.out.println(s);
- }
- // System.out.println("Done");
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- }
- }
- class MyAuthenticator extends Authenticator {
- private String httpUsername;
- private String httpPassword;
- public MyAuthenticator(String httpUsername, String httpPassword) {
- this.httpUsername = httpUsername;
- this.httpPassword = httpPassword;
- }
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(httpUsername, httpPassword.toCharArray());
- }
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- 2) NTLM2_SSL.SendHTTPRequestNTLM Java Code Activity
- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- package Processes.SubProcesses.NTLM2_SSL.SendHTTPRequestNTLM;
- import java.io.BufferedReader;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.Authenticator;
- import java.net.PasswordAuthentication;
- import java.net.URL;
- import javax.net.ssl.HttpsURLConnection;
- public class SendHTTPRequestNTLMDo_NTLM{
- /****** START SET/GET METHOD, DO NOT MODIFY *****/
- protected String stringURL = "";
- protected String SoapAction = "";
- protected String SOAPxml = "";
- protected String UserName = "";
- protected String Password = "";
- protected String Domain = "";
- protected String ContentType = "";
- protected String charset = "";
- protected String Reply_SOAPxml = "";
- public String getstringURL() {
- return stringURL;
- }
- public void setstringURL(String val) {
- stringURL = val;
- }
- public String getSoapAction() {
- return SoapAction;
- }
- public void setSoapAction(String val) {
- SoapAction = val;
- }
- public String getSOAPxml() {
- return SOAPxml;
- }
- public void setSOAPxml(String val) {
- SOAPxml = val;
- }
- public String getUserName() {
- return UserName;
- }
- public void setUserName(String val) {
- UserName = val;
- }
- public String getPassword() {
- return Password;
- }
- public void setPassword(String val) {
- Password = val;
- }
- public String getDomain() {
- return Domain;
- }
- public void setDomain(String val) {
- Domain = val;
- }
- public String getContentType() {
- return ContentType;
- }
- public void setContentType(String val) {
- ContentType = val;
- }
- public String getcharset() {
- return charset;
- }
- public void setcharset(String val) {
- charset = val;
- }
- public String getReply_SOAPxml() {
- return Reply_SOAPxml;
- }
- public void setReply_SOAPxml(String val) {
- Reply_SOAPxml = val;
- }
- /****** END SET/GET METHOD, DO NOT MODIFY *****/
- public SendHTTPRequestNTLMDo_NTLM() {
- }
- public void invoke() throws Exception {
- /* Available Variables: DO NOT MODIFY
- In : String stringURL
- In : String SoapAction
- In : String SOAPxml
- In : String UserName
- In : String Password
- In : String Domain
- In : String ContentType
- In : String charset
- Out : String Reply_SOAPxml
- * Available Variables: DO NOT MODIFY *****/
- Reply_SOAPxml = getAuthenticatedResponse(stringURL, Domain,UserName, Password,charset,ContentType,SOAPxml);
- }
- class MyAuthenticator extends Authenticator {
- private String httpUsername;
- private String httpPassword;
- public MyAuthenticator(String httpUsername, String httpPassword) {
- this.httpUsername = httpUsername;
- this.httpPassword = httpPassword;
- }
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(httpUsername, httpPassword.toCharArray());
- }
- }
- private static String getAuthenticatedResponse(final String urlStr,
- final String domain, final String userName, final String password,final String charset,final String ContentType,final String SOAPxml)
- throws IOException {
- StringBuilder response = new StringBuilder();
- Authenticator.setDefault(new Authenticator() {
- @Override
- public PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(domain + "\\" + userName, password.toCharArray());
- }
- });
- // String requestMessage =null;
- String requestMessage = SOAPxml;
- URL urlRequest = new URL(urlStr);
- HttpsURLConnection conn = (HttpsURLConnection) urlRequest
- .openConnection();
- conn.setDoOutput(true);
- conn.setDoInput(true);
- conn.setRequestMethod("POST");
- conn.setDoInput(true);
- conn.setDoOutput(true);
- // use caching
- conn.setUseCaches(false);
- conn.setRequestProperty("Content-Type", ContentType + "; charset="+charset);
- // Write post data
- DataOutputStream out = new DataOutputStream(conn.getOutputStream());
- out.writeBytes(requestMessage);
- out.flush();
- out.close();
- InputStream stream = conn.getInputStream();
- BufferedReader in = new BufferedReader(new InputStreamReader(stream));
- String str = "";
- while ((str = in.readLine()) != null) {
- response.append(str);
- }
- in.close();
- return response.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement