Thursday, August 30, 2012

Grant access Mysql DB to any other computer in your LAN

This is very useful post because when you are going to run the application with Centralized DB you have to give the privileges to the other computers to access Single database hosted in your LAN.

So what you need to do is just run the single database in one computer then go to MySQL console and type the following commands

[sourcecode language="sql"]

mysql> grant all privileges on *.* to 'root'@'%' identified by 'root_password';

mysql> flush privileges;

[/sourcecode]

By replacing the '%' to any IP address you can grant for the given IP

XACML policy load testing with Jmeter

This will help you to do the load testing on wso2 IS server
Fist follow my article Xacml policy testing with SoapUi

You don't need to take the soapui here what you have to do is
Download the Jmeter and import this jmeter-project
You can see the Jmeter project as follows



"UserAuthentication" Soap request is used to send the username and password to
authenticate the user



"SOAP/XML-RPC Request" is used to send the XACML request

Run the jmeter script and see the results under 'view results tree'



Check this jmeter file as well - This is with one time login to the  server and make the cookie and run the xacml  requests



There is another jmeter with Basic oauth headers as follows
The major change is there is no separate request for authorization

XACML policy testing with soapUi

This blog post will help you to do the XACML testing on Wso2 Identity Server
You need to have wso2 Identity Server(take the binary) and SoapUi

First go to IS_Home/repository/conf/ and open the carbon.xml then find this property

[sourcecode language="xml"]<HideAdminServiceWSDLs>true</HideAdminServiceWSDLs>[/sourcecode]

and change to

[sourcecode language="xml"]<HideAdminServiceWSDLs>false</HideAdminServiceWSDLs>[/sourcecode]

to up the Identity Server run the relevant file

In Windows - IS_Home/bin/wso2server.bat
In Linux - IS_Home/bin/wso2server.sh

Assuming there is no any other server running on the local machine
then you can access the management console in
https://localhost:9443/carbon/admin/login.jsp
username - admin
password - admin

go to Administration->Import new Entitlement policy and upload this policy



Open SoapUI and create a new project by using this wsdl URL
https://localhost:9443/services/EntitlementService?wsdl



You will get the project as mentioned bellow then click the "Request 1" under "getDecision"


now clear the request and insert given request bellow

[sourcecode language="xml"]

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://org.apache.axis2/xsd">
<soapenv:Header/>
<soapenv:Body>
<xsd:getDecision>
<xsd:request><![CDATA[
<Request xmlns="urn:oasis:names:tc:xacml:2.0:context:schema:os" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Subject>
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id"
DataType="http://www.w3.org/2001/XMLSchema#string">
<AttributeValue>admin</AttributeValue>
</Attribute>
<Attribute AttributeId="group"
DataType="http://www.w3.org/2001/XMLSchema#string">
<AttributeValue>admin</AttributeValue>
</Attribute>
</Subject>
<Resource>
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" DataType="http://www.w3.org/2001/XMLSchema#string">
<AttributeValue>http://localhost:8280/services/echo/echoString</AttributeValue>
</Attribute>
</Resource>
<Action>
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" DataType="http://www.w3.org/2001/XMLSchema#string">
<AttributeValue>read</AttributeValue>
</Attribute>
</Action>
</Request>]]></xsd:request>
</xsd:getDecision>
</soapenv:Body>
</soapenv:Envelope>

[/sourcecode]

Before send the request you have to set the authentication properties for the request
as follows
Username- admin
Password -admin



Now send the request and you will get the response as bellow


Now you can upload your own xacml policy and try out

Wednesday, August 29, 2012

Videos of EJB with netbeans

[youtube http://www.youtube.com/watch?v=uJGWI1ImyeM]

[youtube http://www.youtube.com/watch?v=tetLzF3qwTM&w=420&h=315]

Share your Twitter update in your facebook wall

This is very simple just go to the following link

1. Go to Twitter

2. Then Log in to your twitter account and go to profile then click the button "post your tweets to Facebook"

3. You will get the popup window - Log in to the facebook and give the permission

4. Now your twitter account connected to the facebook

when you are tweeting its automatically post in your facebook wall

enjoy yourself with twitter

Read XL file in Java

This is basic sample class for read the xl sheet in java
Download source with "jxl-2.6.jar" and "users.xls" here

To run this you have to put the "jxl-2.6.jar" in your class path
[sourcecode language="java"]
package mysamples;

import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
/**
*
* @author dinuka
*/
public class ReadXL {
private String inputFile;

public void setInputFile(String inputFile)
{
this.inputFile = inputFile;
}

public void read() throws IOException
{
File inputWorkbook = new File(inputFile);
Workbook w;
try
{
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);

for (int j = 0; j &lt; sheet.getColumns(); j++)
{
for (int i = 0; i &lt; sheet.getRows(); i++)
{
Cell cell = sheet.getCell(j, i);
System.out.println(cell.getContents());
}
}
}
catch (BiffException e)
{
e.printStackTrace();
}
}

public static void main(String[] args) throws IOException
{
ReadXL test = new ReadXL();
test.setInputFile("users.xls");
test.read();
}
}
[/sourcecode]

Tuesday, August 28, 2012

Java with property file

This is a basic property file sample. You can take the source then
do the necessary changes and apply to your code
PropertyFileSample.java

[sourcecode language="java"]
package mysamples;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
*
* @author dinuka
*/
public class PropertyFileSample {

public static void write() {
Properties prop = new Properties();

try {
//set the properties value
prop.setProperty("database", "localhost");
prop.setProperty("dbuser", "root");
prop.setProperty("dbpassword", "123");

//save properties to project root folder
prop.store(new FileOutputStream("config.properties"), null);

} catch (IOException ex) {
ex.printStackTrace();
}
}

public static void read() {

Properties prop = new Properties();
try {
prop.load(new FileInputStream("config.properties"));
String database = prop.getProperty("database");
String user = prop.getProperty("dbuser");
String pw = prop.getProperty("dbpassword");
System.out.println("Database: " + database);
System.out.println("DB User: " + user);
System.out.println("DB User: " + pw);
} catch (Exception e) {
}

}

public static void main(String[] args) {
PropertyFileSample.write();
PropertyFileSample.read();
}
}
[/sourcecode]

Output file
[sourcecode language="java"]
#Tue Aug 28 17:33:26 IST 2012
dbpassword=123
database=localhost
dbuser=root
[/sourcecode]