java

java

How to import certificate to java key store

Background: There is a SLDAP(ldap over ssl) server, I would like to use jmeter ldap sampler to test authentication.

Target: I would like to test the ldap ssl connection
             This is involved with cert import to java key store

Below is the steps;
1. copy the cert file from ldap server to local
scp <username>@<ldap server>:/etc/openldap/cacerts/cacert.pem ./

2. import certificate into Java Key Store (JKS)
sudo keytool -import -alias afiliasldap1 -keystore cacerts -file /tmp/cacert.pem
Note: input keystore pass: changeit
Note: on jvm, location for cert: /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/security

3. Verify the import done successfully by showing the cert content:
keytool -list -v -alias afiliasldap1 -keystore cacerts -storepass changeit

In step3, you will see cert content shown, means import is done successfully

Now you can proceed to use your ldap sampler for ldap over ssl testing
Ensure that
– select “Use Secure LDAP Protocal” in LDAP thread bind
– and use ssl port(default 636) in LDAP Request Defaults

 

Maven step by step

1. Install Maven

2. Create a project
run comand below
‘mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false’

3. cd my-app
will see paths below
my-app
|– pom.xml
`– src
|– main
|   `– java
|       `– com
|           `– mycompany
|               `– app
|                   `– App.java
`– test
`– java
`– com
`– mycompany
`– app
`– AppTest.java

4. Build the project
run below command
‘mvn package’

5. run command
‘java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App’
will got command line output ‘Hellow World!’

Further
To make this project work with eclipse

6. cd my-app
modify pom.xml
– modify junit version from 3.8.1 to 4.1
–  add this for JDK 5.0 support as below:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>

7. mvn eclipse:eclipse -DdownloadSource
8. open eclipse, File > import
import existing maven project

About maven (java building tool)

Java Build Tools: Ant vs. Maven
http://kent.spillner.org/blog/work/2009/11/14/java-build-tools.html

What is Maven:
http://maven.apache.org/

what is POM:
http://maven.apache.org/guides/introduction/introduction-to-the-pom.html

Maven repository: to search component groupid artifact id and version info
http://mvnrepository.com/
for example: search sl4j in the above site, can find out below information that needed to add to POM.xml dependency section
<dependency>
<groupId>org.grlea.log.adapters</groupId>
<artifactId>simple-log-sl4j</artifactId>
<version>1.7</version>
</dependency>
Maven dependency scope types:
<scope>test</scope>
<scope>compile</scope>
<scope>provided</scope>

Whenever POM.xml is updated, run ‘mvn package’

Selenium IDE + Eclipse + Selenium Server(formerly Selenium RC)

Installations:
1. Add Selenium IDE plug-in to firefox
2. Install eclipse by Synaptic Package Manager or apt-get install
3. Download Selenium Server (formerly Selenium RC)
“selenium-server-standalone-2.11.0.jar”

Configuration:
1. Eclipse configuration:
1.1 Open Eclipse, create a project
1.2. select properties > java build path > click “Add library” > select Junit
1.3. select properties > java build path > click “Add external jars” > select “selenium-server-standalone-2.11.0.jar”
2. Start Selenium server
“java -jar selenium-server-standalone-2.11.0.jar”Steps

1. Go firefox browser > Tools > Selenium IDE
start record, when finish, stop recording

2. File > Export test case to a junit4 (Remote Control)
save it to path com/example/tests
name it as a .java file

3. Go back to Eclipse, import the com folder to the project

4. Click run as junit test

Done….