Friday, September 29, 2017

CNTLM - Proxy Configuration

Proxy Server and Configuration:
Initially there were only Sever and Client. When client wants a resource from Sever, it sends a request using a protocol. eg: Browser sending a request for google.com home page from GOOGLE server using HTTP protocol.

But in a corporate environment, there exists a proxy server which is a middleman between application-clients and the websites 
1. To impose restrictions on web-browsing
2. To hide identity of the users/client-machine information

How Proxy sever works:
In a proxy environment scenario, 
1. An application such as a browser sends a request to Proxy server. Means, when you type a URL and click send, the HttpRequest for the actual server will be fwded to Proxy server by browser.
2. Proxy server verifies the request then forwards it to the website. It then receives the response and verifies the same. Finally the proxy server sends the response to Application that requested.

A proxy server needs authentication information from the applications that it needs to server. This information is configured in the applications(clients) via Proxy-Settings where the following details are provided..
Proxy Server name, Proxy port, Username and Password

Once the proxy settings are configured, the application sends request to the appropriate proxy server. This is called basic authentication.

Proxy server that needs NTLM:
Many applications now-a-days comes with an inbuilt feature where the proxy information can be provided/configured apart from being able to send a request to actual server. But sometimes, a proxy server needs NTLM authentication besides basic.
And some applications are not equipped to send NTLM authentication (just like they send basic authentication). In such cases we need another software that knows how to send NTLM information to the Proxy.

Cntlm is a software that stands between application-clients and Proxies. CNTLM acts like a local proxy server which is configured with authentication information. All applications now can be configured to send requests to CNTLM server that is running at a configured host and port usually at Localhost+3128.
Cntlm then sends that request to actual proxy server and receives the response from Proxy.

Future directions for applications to have:
1. Able to send http requests
2. Able to setup proxy to fwd http requests to Proxy server
3. Able to send NTLM data to NTLM server


Friday, September 1, 2017

How Client server communication works

The contents(files) that get exchanged between client(browser) and a sever(webserver) are html, css, javascript, images, pdf files etc. When a browser sends a request for a URL, the response can be html or html+css or html+css+javascript. Server wont send all the files in a single response if altogether makes it a large response. Rather it(here 'it' means server which in turn is nothing but the code(Java or c#.NET) written by developer...the way he intends to send) includes links to css,js files, images and other htmls in the response and sends it at the first time. Then server waits for another request to serve the rest of the content. After browser receives the first html response, it sends requests for other resources which are included as links while parsing the first html.
Server then responds with rest of the content.

So far so good. As long as server needs to send only static content, we can have all the html, css and Javascript readily developed to serve them immediately upon request. But, it is not always the case. In fact it never be one. The requests need to be processed based on the business logic and html content has to be rendered with some data retrieved from the database. 
In such case, we need to build html embedding data along with frontend event-handling code and Styling information dynamically.

Below are the techniques to dynamically render html+css+javascript+data:
1) Servlets: These are Java classes which create dynamic webpages by Println statements
2) JSP: A special kind of servlets which embed javacode inside html tags.
3) JSF: Yet another J2EE standard mechanism to handle requests

Ultimately, all such techniques create html response with backend data embedded. And necessary CSS and Javascript is obviously part of it.

How J2EE components work together in any Container - Spring or Application Server

In a Spring+Jersey+Hibernate RESTful webapplication, we can spot various J2EE components - JTA, JPA, Java Bean Validation, JSON-B API for B...