@RequestHeader in Spring MVC

by Administrator 21. June 2014 20:01

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class RequestHeaderExampleController{
    @RequestMapping(value = "/example", method = RequestMethod.GET)
    public String  getHello(@RequestHeader ("host") String hostName,
            @RequestHeader ("Accept") String acceptType,
            @RequestHeader ("Accept-Language") String acceptLang,
            @RequestHeader ("Accept-Encoding") String acceptEnc,
            @RequestHeader ("Cache-Control") String cacheCon,
            @RequestHeader ("Cookie") String cookie,
            @RequestHeader ("User-Agent") String userAgent){
        System.out.println("Host : " + hostName);
        System.out.println("Accept : " + acceptType);
        System.out.println("Accept Language : " + acceptLang);
        System.out.println("Accept Encoding : " + acceptEnc);
        System.out.println("Cache-Control : " + cacheCon);
        System.out.println("Cookie : " + cookie);
        System.out.println("User-Agent : " + userAgent);
        return "example";
    }
}


Tags:

Spring

https test using certificate & keystore

by Administrator 13. June 2014 20:58

 

package org.springframework.integration.samples.rest;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

public class HttpsTest {
    public static void main(String[] args) {
        System.setProperty("javax.net.ssl.keyStore","/azizkhani/keystore.jks");
        System.setProperty("javax.net.ssl.keyStorePassword", "pass");

        // full log for debugging
        System.setProperty("javax.net.debug", "all");

        try {
            try {
                javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
                        new javax.net.ssl.HostnameVerifier(){
                     
                            public boolean verify(String hostname,
                                    javax.net.ssl.SSLSession sslSession) {
                                if (hostname.equals("ansarrootca")) {
                                    return true;
                                }
                                return false;
                            }
                        });
                URL url = new URL("https://site:3443");
                InputStream is = url.openStream();
                BufferedReader in = new BufferedReader(new InputStreamReader(is));
                String inputLine = null;
                while ((inputLine = in.readLine()) != null)
                    System.out.println(inputLine);
                in.close();
                is.close();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 

Tags: , ,

Security

using keystore & trust store in java

by Administrator 13. June 2014 20:51

 

add this code for run application that use  keystore

option1

System.setProperty("javax.net.ssl.keyStore","/azizkhani/Java/pdf/EIA/keystore.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "pass");
System.setProperty("javax.net.debug", "all");

 

option2

 

-Djavax.net.ssl.keyStore=/azizkhani/Java/pdf/EIA/keystore.jks

-Djavax.net.ssl.keyStorePassword=pass;

 

Tags: ,

Security

disable java check for subject alternative names in certificate

by Administrator 13. June 2014 20:41

when i want to invoke https webservice by certificate(keystore.jks) .

i get this exception

 java.security.cert.CertificateException: No subject alternative names present

ip of webservice is 192.168.1.10 but certificate is created for 192.168.1.20

java check this in client and throw this exception 

i add host for 192.168.1.20  in my os and add this line in application

this code disable this check


javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
                new javax.net.ssl.HostnameVerifier(){
            
                    public boolean verify(String hostname,
                            javax.net.ssl.SSLSession sslSession) {
                        if (hostname.equals("azizkhanihost")) {
                            return true;
                        }
                        return false;
                    }
        });

 

Tags: , ,

Security

add host in mac os

by Administrator 13. June 2014 20:36

sudo nano /private/etc/hosts

and add line like this

77.237.70.93    azizkhani.net

save and ..

sudo dscacheutil -flushcache

 

 

ping azizkhani.net Cool



Tags:

Import PKCS12 private keys into JKS keystores using Java Keytool

by Administrator 8. June 2014 20:31
  1. Create an empty JKS store
    keytool -genkey -alias alice -keystore alice.jks
    keytool -delete -alias alice -keystore alice.jks
  2. Import alice.p12 into alice.jks
    keytool -v -importkeystore -srckeystore alice.p12 -srcstoretype PKCS12 
    -destkeystore truststore.jks -deststoretype JKS

Tags:

Security

managing and examining keystores by (Portecle software)

by Administrator 8. June 2014 20:24

Portecle is a user friendly GUI application for creating, managing and examining keystores, keys, certificates, certificate requests, certificate revocation lists and more.

  • Create, load, save, and convert keystores.
  • Generate DSA and RSA key pair entries with self-signed version 1 X.509 certificates.
  • Import X.509 certificate files as trusted certificates.
  • Import key pairs from PKCS #12 and PEM bundle files.
  • Clone and change the password of key pair entries and keystores.
  • View the details of certificates contained within keystore entries, certificate files, and SSL/TLS connections.
  • Export keystore entries in a variety of formats.
  • Generate and view certification requests (CSRs).
  • Import Certificate Authority (CA) replies.
  • Change the password of key pair entries and keystores.
  • Delete, clone, and rename keystore entries.
  • View the details of certificate revocation list (CRL) files.

http://portecle.sourceforge.net/images/portecle.png

Tags:

Security

create trustStore from .cert file

by Administrator 8. June 2014 20:09

 

keytool -import -file C:\certificate.cert -alias firstCA -keystore myTrustStore

 

Tags:

Security

create client-side web service using wsimport

by Administrator 6. June 2014 13:00

 

create java code

wsimport -keep -verbose soap.wsdl

 

 

create jar file

wsimport -clientjar wsclient.jar soap.wsdl

 

Tags:

j2ee

Reusable components in AngularJS

by Administrator 4. June 2014 21:14
angular.module('components', []).directive('category', function () {
return {
    restrict: 'E',
    scope: {},
    templateUrl: '/Scripts/app/partials/CategoryComponent.html',
    controller: function ($scope, $http, $attrs) {
        $http({
            url: "api/FeaturedProducts/" + $attrs.catName,
            method: "get"
        }).success(function (data, status, headers, config) {
            $scope.Cat = data;
        }).error(function (data, status, headers, config) {
            $scope.data = data;
            $scope.status = status;
        });

    }
}
});

CategoryComponent.html
<a href="#/Categories/{{Cat.CategoryName}}">
    <h4>{{Cat.CategoryName}}</h4>
</a>
<div ng-switch on="status">
    <div ng-switch-when="500" class="alert alert-error">
        {{status}}
        {{data}}
    </div>
    <div ng-switch-default>
        <ul class="unstyled columns">
            <li class="pin" ng-repeat="p in Cat.Products">
                <a href="#/reviews/{{p.UPC}}">
                    <h5>{{p.ProductName}}</h5>
                    <img src="{{p.ImageUrl}}">
                </a>
            </li>
        </ul>
    </div>
</div>


usage
<ul class="unstyled">
    <li>
    <category cat-name="Ultrabooks"></category>
    </li>
    <li>
    <category cat-name="Tablets"></category>
    </li>
    <li>
    <category cat-name="Laptops"></category>
    </li>
    <li>
    <category cat-name="Digital SLR Cameras"></category>
    </li>
</ul>

Tags:

angular

About the author

 Welcome to the web site of Azizkhani. This page has two purposes: Sharing information about my professional life such as articles, presentations, etc.
This website is also a place where I would like to share content I enjoy with the rest of the world. Feel free to take a look around, read my blog


Java,J2EE,Spring Framework,JQuery,

Hibernate,NoSql,Cloud,SOA,Rest WebService and Web Stack tech...

RecentPosts

Month List