Thursday, July 2, 2009

Shibboleth Relational Database DataConnector

Example Shibboleth Relational Database DataConnector configuration for MySQL with column mapping of AES encrypted attribute.


xmlns="urn:mace:shibboleth:2.0:resolver:dc"
id="MyDatabase">

jdbcURL="jdbc:mysql://localhost:3306/handle"
jdbcUserName="test"
jdbcPassword="test" />


SELECT AES_DECRYPT(password, 'key') FROM handle WHERE username='$requestContext.principalName'
]]>





Wednesday, July 1, 2009

Jsp Insert into MySQL database, AES encryption

Jsp code that inserts into a MySQL database, using AES_ENCRYPTION for 128 bit AES encryption of one of the database columns with ON DUPLICATE KEY UPDATE syntax.



<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>

<%
String username = request.getParameter("username");
String password = request.getParameter("password");
String connectionURL = "jdbc:mysql://localhost:3306/handle";
Connection connection = null;
PreparedStatement pstatement = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
int updateQuery = 0;
if(username!=null && password!=null){
try {
connection = DriverManager.getConnection (connectionURL, "test", "test");
String queryString = "INSERT INTO handle(username, password, last_login) VALUES (?, AES_ENCRYPT(?, 'key'), now()) ON DUPLICATE KEY UPDATE last_login=now()";
/* createStatement() is used for create statement
object that is used for sending sql statements to
the specified database. */
pstatement = connection.prepareStatement(queryString);
pstatement.setString(1, username);
pstatement.setString(2, password);
pstatement.setString(3, password);
updateQuery = pstatement.executeUpdate();
if (updateQuery != 0) { %>




<%

}
}
catch (Exception ex) { %>




<%

}

finally {
// close all the connections.
pstatement.close();
connection.close();
}
}
%>

Half-Marathon Training

I follow the training regimens on running.about.com to train for races - I've run several 5k's and 10k's. This summer I am entered in the 2009 Rock 'n' Roll Chicago Half Marathon on August 2, 2009 as a charity runner for the American Cancer Society. To train for the race I'm using the Half-Marathon Advanced Beginner training program on running.about.com. I'm on week 9, currently - I repeat some weeks to pad out the time until the race. The long 10 mile+ runs are pretty brutal - I made the mistake last week trying to do a 10 mile run in the 90+ degree heat. I'll probably write more about this stuff later on.