Sunday, January 3, 2016

SAML explained

You might have seen lot of web sites / services you access requesting you to login with an login page that you have used before.

To understand SAML, you might need to understand the following terms.

Identity Provider (IP): The company / enterprise holding the user credentials.
Service provder (SP): The company providing the service - say salesforce.
User: the person going to use the service.

Traditionally the credentials are maintained by Identity provider, but the credentials are also maintained in the Service provider so that whenever the user tries to access the SP he is authenticated within the service provider itself.
You might have seen in some sites where they ask you to register with a username and password to access the service.

Now the problems of using this approach is:
- the service provider have to maintain the user credentials even though the user credentials are in the Identity provider.
- the user has to remember different user credientials for the IP and the SPs.
- The identity provider has to follow a cumbersome process of disconnecting the access to the SPs whenever the user goes out of the company or his roles changed.

How its solved.

Typically, the user requests access to the Service (SP), the SP redirects him to the Identity provider (IP), the user gets his userid and password validated from the Identity provider.
The Identity provider provides a token (a file which contains user information - but not password) to the service provider.
The service provider now knows that its a valid user and allows him to access the service.

Now using this approach, the SP dont have to maintain password, the user has to remember only one password, and its easy for IP to manage user information and he has control over the services.

Now what is SAML: 
SAML is the token we talked about. Its the XML based data format for exchanging user information between the Identity provider and the service provider.

When the user is authenticated by the IP, the user can then access the services with the token provided by the IP.

How long can the user access the service with the token provided by IP, what if the user goes out of the company.
The token issued by the IP also has the expiry time. Whenever the SP receives the token, it is valid only till the time, after that the service provider redirects back to the identity provider. The user has to get another token with a revised expiry time on the token.


What does SAML describe:
- describe the structure of the data.
- explains how the data should get transported between the IP and SP


How does communication happens between the IP and the SP:

In the above picture you can see the sequence flow how the user is authenticated and he is allowed to access the resource in SP. 

Friday, January 1, 2016

AWS Glacier - Overview

Glacier storage service is meant for storing archival data. It is best suited for data that is not frequently accessed.

It is priced very low when compared to S3. Accessing the object in glacier is very slow - for example, the checkout job can take several hours for data to be available.
Integrates will with S3 life cycle.
With glacier you dont have to worry about the server provisioning, you can store as much data as you want - as usual.

A single archive can be as large as 40 TB.

You can configure glacier to be like "Write once read many" to prevent losing data by mistake.
You can also set the data retrieval policies such as maximum retrieval rate. you can also see which users have accessed the vault over the last one month, or identify who deleted the data.

You can use AWS console or use the AWS SDK APIs to store data into Glacier.
you can also setup policies in S3 so that every month data is archived back from S3 to Glacier. AWS Import / export product can be used to accelerate moving large amount of data.

Pricing is based on how much data you are planning to store and how much time you are planing to retrieve. Data transfer costs and PUT requests also matters but its low.

For example, if you want to store 100GB of data with no retrieval, it might approximately cost 7 cents per month.
You can use the AWS calculator to calculate how much it is going to cost you based on your data requirements.


Amazon S3 - overview

S3 is a storage product from AWS to help users store documents such as pdfs, pngs and any other files. An object in S3 can be called as a single file.

Characteristics: 
- an object can be up to 5TB.
- you can encrypt data before saving into S3 and decrypt before downloading into your desk.
- supports unlimited data upload and multi-threaded uploads.
- High availability: Automatically stores data in multiple zones within your region.
- you can add policies to a bucket, for example you can say after 2 months of data upload, you can configure to move the data to another storage such as glacier.
- supports versioning of objects within S3, which means when you accidentally delete an object, you can recover by accessing old versions of the object.
- secured storage, which means you can be sure that only you can store or set priveleges that only you can access the data.
- you can store as much data you want, it will scale based on your needs.

What operations you can perform using S3. 
- CRUD operations on Bucket.
- you can choose your region/zone you want to store the data and use S3 APIs to store the data.
- you can send event notifications whenever someone uploads a data into an bucket.
- Can be integrated with other AWS services such as "whenever an object is loaded into a bucket, you can send the data into Kinesis".
- use S3 as a backup storage or host static files for your web page.
- perform disaster recovery of your systems by storing backup images in S3.
- host static web sites or files.

S3 pricing: 
- Storage cost: You pay approximately $0.03 for every GB for the first 1 TB
- Request pricing:
you pay $0.004 per 10,000 requests for all GET requests.
You pay $0.005 per 1,000 requests for all PUT, COPY, POST requests, delete requests are not priced.
- Data transfer pricing:
Data transfer in to S3 is not charged
Data transfer OUT to same region is not charged.
Data transfer OUT to another region or over to internet is charged, first 1 GB transfer is free, after that it will be charged at 9 cents per GB.

You can use the AWS calculator to approximately determine how much it will cost for the services you choose based on the data you provide.
http://calculator.s3.amazonaws.com/index.html

Full pricing information can be found here - https://aws.amazon.com/s3/pricing/

How do you operate on S3: 
- use the AWS console to operate on S3
- use AWS SDK, supports different languages such as Java, .net, python, php, nodejs, ruby. You can also use AWS mobile SDK to directly upload data into S3 from the mobile.

S3 FAQ: https://aws.amazon.com/s3/faqs/

Monday, November 23, 2015

CloudFoundry – Getting started


This article helps you getting started on cloudfoundry. This does not explain on the cloudfoundry concepts.

Step 1: Create an account in pivotal cloudfoundry. 
                You can create a 2 months free subscription account from pivotal cloudfoundry services web site https://run.pivotal.io. An organization as the name specifies – can be your company name, project group or so.
The space is nothing but the environment you wish to create, you may want to have a development, qa and production spaces. In short applications are hosted in spaces (environemnts) and spaces belongs to an organization.



Step 2: Create a simple spring application, you can also create in Grails, Ruby etc., You can use maven, gradle as the build tool.
                You can use spring boot to create a simple application. Please refer http://ndeiveehan.blogspot.com/2015/11/spring-boot-getting-started.html to create a new spring application.

You can also create in other languages as Cloudfoundry offers other buildpacks.
Once created, you can generate the war or jar using the maven command.

Step 3: Login to cloudfoundry and create required organization and spaces.
From you PC, login to cloudfoundry using the CLI tools.
cf login -a https://api.run.pivotal.io

Enter your credentials to login.



Step 4: Deploy your application.
You can push the apps in the following ways:
- Use the Cloudfoundry CLI tool.
- Use cloufdoundry eclipse plugin.
- Use a build plugin to integrate deployment as part of your build tool.
 but this article shows you how to push application using the CLI tool.

Now issue the following cf command.
cf push springbootfirst -p target/springbootfirst-0.0.1-SNAPSHOT.jar
               
 This command uploads the spring jar file to the cloudfoundry site and starts the server. 

Step 5: You can now access the web application in the following web url:




Now there is a lot more you can do using CF tool such as:
-          Configuring your own domain instead of cfapps.io.
  • Scale up an application.
  • Deleting an app, renaming it, start or stop an application.
  • View logs for an application
  • Enable ssh for an application.
  • View services from the market place.
  •  Create, update organizations, spaces, buildpacks etc.,
  •  Perform user administration on organizations / projects.



See you in the next article on cloudfoundry. 

Spring boot - Getting started

Spring boot - Getting started


This article explains how to get started on Spring boot. Assuming you already have JDK, maven and eclipse installed in your PC, lets get started. 


Step 1: Create a simple maven project in eclipse.
Step 2: Create the following parent definition in pom
       <parent>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-parent</artifactId>
              <version>1.3.0.RELEASE</version>
       </parent>

Add the following dependencies
              <dependency>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-starter-web</artifactId>
              </dependency>
Spring boot starter web dependency takes care of loading required jars for the web such as spring web etc., No more hassles on the need to remember the spring jars and version names.

Step 3: Create a simple web controller
@RestController
@EnableAutoConfiguration
public class SampleController {

       @RequestMapping("/")
       String home() {
              return "Hi Buddy";
       }
      
       public static void main(String args[]) {
              SpringApplication.run(SampleController.class, args);
       }
}
The EnableAutoConfiguration annotation informs boot to automatically configure required annotations based on the jars that you have added in your application. Cool isn’t it.
Run the Above Sample Controller as a java application
What just happened. When did I start the web server ??
Actually Spring boot takes care of that. When you actually run SpringApplication.run, it internally runs a web server and then loads the controller into that server.




Step 4: Invoke the controller in the web browser: 


Simple and easy to develop without having to worry about dependencies or the server. 

Now if you don’t want to add the parent pom for whatever reasons like you want to add your own project parent pom or so, you can add the following dependencies.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.3.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>

You may also want to add the following to package your project as an executable jar.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>






Monday, August 10, 2015

Amazon Web Services - Products overview

Following are the list of products Amazon web services offers. 


Compute
  • EC2: A service which allows user to rent servers with different configurations. You can choose the instance based on memory, diskspace, speed and other attributes and you pay on a per hour basis. You can shut down the instance at any time, and you pay for what you use. There are preconfigured machine images available that you can choose from different OS available ranging from Ubuntu, Windows and other OSs. 
  • ECS: EC2 container services make developer/network person life easy by making it easy to deploy, manage and scale Docker containers. 
  • Lamda: A compute service that executes developer’s code in response to events. The developer don’t need to have a developer environment, he can directly code in the AWS browser console or upload code. The events to respond can be “whenever an artifact has been uploaded into S3”. The main advantage is you donate have to worry about the infrastructure at all. You pay pay for the time taken for the code to get executed. Its a new approach to event driven computing. 
Storage
  • S3: S3 is storage solution, you pay for the storage and the bandwidth. S3 is very reliable and 99.99% available. With S3, you might want to store static content of a web site or data generated out of a project in a storage service so that it is available globally. S3 is often used with other AWS products such as EC2. Its very easy to use. Following are different ways by which you can store and retrieve data. 
      • Using Command line interface. 
      • using AWS console. 
      • Using AWS SDK. 
  • Elastic File system: is a new sharable file storage service that provides multiple EC2 instances to access a fully managed file system using NFSv4 protocol. You will be able to access using the CLI, console and AWS SDK. 
  • Glacier:  a low cost data archival storage for storing less frequently used data but for a much lower cost than S3. This service is effective for archiving. You have to use if you don’t want to access daily. The retrieval time is slow but cheaper. 
  • Cloudfront: is a content delivery service. You can use Cloudfront console / API to easily distribute content to end users with low latency, high data transfer speeds. You can use HTTP/HTTPS or RTMP to stream the content stored in cloud front. 

Network: 
  • VPC: This service lets you configure your instance in a virtual network that you define. You have complete control over your networking environment. You can control which port to open to which group and can leverage multiple layers of security. 
  • Direct Connect: This service helps you in establishing a dedicated connection from your office infrastructure to AWS environment. This can reduce the network cost and increase the bandwidth throughput. 
  • Route 54: This is a domain naming service from Amazon which helps you in mapping your domain name to the instance you have. 

Database
  • RDS: A service which helps in setting up and managing an RDBMS, scaling them in a easy and cost efficient way. 
  • DynamoDB: A no-sql database solution from Amazon which developers can use to store the content in a faster manner. Its a fully managed service which stores in document and key-value pair format. 
  • ElasticCache: An in memory caching engine that makes it easy to deploy, operate and scale an in memory cache in the cloud. It supports memcached and redis. 

Analytics
  • Redshift: a data warehouse solution from AWS to analyse all your data using existing BI tools. 
  • EMR: This is a managed hadoop environment which can be used out of the box to run hadoop jobs. With this service you don’t have to worry about the environment. You just have to upload the job file, input and output folders in S3. You can define the no. of instances you need - EMR will run the job - output the job content in the S3 file you define. EMR can also terminate the instances once the job is complete. 
  • Kinesis: Kinesis is a managed cloud service from Amazon to process real time data over large distributed data streams. The data can be captured from variety of stores such as web site click streams, social feeds, financial data transactions, sensor data, IT logs and location tracking events. 
  • Data pipeline: AWS Data Pipeline is a cloud-based data workflow service that helps you process and move data between different AWS services and on-premise data sources.
  • Amazon Machine learning: using this service, developers of any skill level can use the ML apis. It provides visualization tools and wizards that guides you through the process of creating ML models. This is highly scalable and is capable of predicting billions of predictions daily. 

Enterprise applications
  • Amazon Workspaces: a managed desktop computing service in the cloud. Using this the network engineers can easily provision cloud based desktops that the users can use their iPads, desktops, laptops to access the content. 
  • WorkMail: an email and calendering service from AWS for existing desktop and mobile email clients. 
  • Workdocs: A fully managed solution to store electronic documents with more features such as security, access provision, share and edit features. 

Application
  • SQS: A simple managed message queuing service that is fast reliable and scalable. It makes it simple and cost effective solution to send and receive messages to SQS. 
  • SWF: a workflow services which can be used to co-ordinate between application components. 
  • SES: a cost effective email sending service. The service can be used via AWS SDK that comes in different languages. 
  • SNS: with SNS you can send notifications to mobile phones - Apple APNS, GCIM for google, windows and other major mobile platforms. 
  • CloudSearch: With this service, you can quickly build a cost-effective solution to setup, manage and scale a search solution for your web site. 
  • AppStream: With this service, you can stream your existing application from the cloud, reaching more users without code modifications. 
Deployment & management
  • Elastic Beanstalk: A PAAS solution from AWS to help users deploy their application from their desktop in a easier way. There are Eclipse plugins available which you can use to move the artifact/scale up in AWS with a click of a button in the eclipse. 
  • OpsWorks: An application management service that helps you in deploy and operate applications of all shapes and sizes. With this you can automate server scaling, software configuration, database setups. This also provides operation to automatic instance scaling, instance monitoring etc., With this you create your entire application as stacks on top of layers. These layers are blueprints that helps you in deploying in a easy way. 
  • Cloud Formation: provides network engineers templates so that they can easily create and manage a collection of related AWS resources. 
  • Code Deploy: a service that automates code deploy to any instance. helps you rapidly release new resources. 
  • Code Pipeline:  a continuous delivery service for faster and reliable application updates. 
  • Code commit: a service that makes it easy for companies to host private GIT repositories. It eliminates the need to manage your own code versioning system. 

Security & Administration
  • CloudWatch: A monitoring tool for AWS products. 
  • Config: lets you have the full visibility of all AWS resources. 
  • CloudTrail: service that records AWS API calls you have made and provides the log files for analysis. It stores information such as IP address of the caller, request parameters etc., 
  • IAM: fine grained granular control of AWS services
  • Directory: A managed directory service. 
  • KMS: encryiption and key management service for the cloud. 


Sunday, August 9, 2015

AngularJS Basics

AngularJS is a Javascript framework which makes it incredibly easy to build web applications

Features of AngularJS: There are many features in AngularJS, primarily 2-way data binding, OO way of JS development, easy mapping between dom and JS model, Create custom tags, Dirty check on objects, implementing Routers.

Components:
  • RouteProvider
  • AngularJS templates (or) partials. 
  • Module
  • Controller

MVC: 
  • View holds the html fragments
  • Controller - holds the action to be performed
  • Model: holds data by getting from the REST services. 

Some attributes: 
  • ng-app: tell that this html page contains angularJS app
  • ng-model: bind the model to the div
  • ng-bind: used to bind the input tag to the model
  • ng-repeat: used to iterate through a list of model and display content. 
  • ng-controller: defines the controller that will be used for this div or section. 
  • ng-show | ng-hide: hide or show a div or section
  • ng-include: include another file in the html


AngularJS Directives: 
You can use directives in different ways:
  • As an attribute to a tag. 
  • As an element
  • As a class
  • As a comment
ng-init: used to initialise angularJS variables

You can also create custom directives: 

You have to use .directive method in the module to define a directive
myAppModule.directive('colorList', function () {
    return {
        restrict: 'AE',
        template:
              "<button ng-click='showHideColors()' type='button'>"
            + "{{isHidden ? 'Show Available Colors' : 'Hide Available Colors'}}"
            + "</button><div ng-hide='isHidden' id='colorContainer'>"
            + "</div>"

        }
});

AngularJS validation: 
  • $dirty
  • $valid
  • $invalid
  • $pristine

AngularJS Expressions: 
<p>My first expression: {{ 5 + 5 }}</p>
(or) 
<p>My first expression: {{ emp.getValue }}</p>
where emp is a angularJS model. 

AngularJS Filters: used to filter a list of values and display 
<div ng-app="myApp" ng-controller="personCtrl">
<p>The name is {{ lastName | uppercase }}</p>
</div>

You can also create custom filters in AngularJS:


Events:
  • ng-click
  • ng-double-click

Angular Services:
$http: 
app.controller('customersCtrl', function($scope, $http) {
    $http.get("http://www.w3schools.com/angular/customers.php")
    .success(function(response) {$scope.names = response.records;});
});

var promise = $http({method: 'POST', url: 'memberservices/register', data: theData});

$window: represents browser window object. 
$location: gets information about the url and gives it to your application
$document: jqlite reference

You can also create custom services: 



—————————— Code Snippets ————————
Simplest AngularJS program
Enter your name : <input type="text" ng-model="ename">
Hello {{ ename }}
<script type="text/javascript" src="../js/lib/angular.min.js"></script>

Sample app code: 
<div ng-app="myApp" ng-controller="myCtrl">

First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.firstName= "John";
    $scope.lastName= "Doe";
});
</script>

RouteProvider: used to define which AngularJS controller to call when you hit a URL
helloWorldApp.config(['$routeProvider', '$locationProvider', 
function($routeProvider, $locationProvider){ 
 $routeProvider. 
   when('/', { 
     templateUrl: 'partials/main.html', 
     controller: 'MainCtrl' }).
   when('/show', { 
     templateUrl: 'partials/show.html', 
     controller: 'ShowCtrl' 
}); 

AngularJS Templates: 
  • ng-view

AngularJS Controllers: 
  • Define methods which would inturn get the data from the server
      • use $http
var addonsControllers = 
  angular.module('addonsControllers', []);

addonsControllers.controller('AddonsCtrl', 
  ['$scope', 'checkCreds', '$location', 'AddonsList', '$http', 'getToken',
    function AddonsCtrl($scope, checkCreds, $location, AddonsList, 
      $http, getToken) {
        if (checkCreds() !== true) {
            $location.path('/loginForm');
        }

        $http.defaults.headers.common['Authorization'] = 
          'Basic ' + getToken();
        AddonsList.getList({},
           function success(response) { 
              console.log("Success:" + 
                     JSON.stringify(response));
                    $scope.addonsList = response;
           },
           function error(errorResponse) {
              console.log("Error:" + 
                     JSON.stringify(errorResponse));                   
           }
        );
        $scope.addonsActiveClass = "active";
}]);

ng-repeat
<li ng-repeat="phone in phones | filter:query">
          {{phone.name}}
          <p>{{phone.snippet}}</p>
        </li>


External controllers: 
<div ng-app="myApp" ng-controller="personCtrl">

First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}

</div>


<script src="personController.js"></script>