<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cake Solutions Team Blog &#187; Aleksa&#8217;s Blog</title>
	<atom:link href="http://www.cakesolutions.net/teamblogs/category/aleksas-blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cakesolutions.net/teamblogs</link>
	<description>void magic() { }</description>
	<lastBuildDate>Tue, 07 Feb 2012 12:02:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Hibernate and primary key unique constaint exception</title>
		<link>http://www.cakesolutions.net/teamblogs/2009/04/23/hibernate-and-primary-key-unique-constaint-exception/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hibernate-and-primary-key-unique-constaint-exception</link>
		<comments>http://www.cakesolutions.net/teamblogs/2009/04/23/hibernate-and-primary-key-unique-constaint-exception/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 10:24:22 +0000</pubDate>
		<dc:creator>Aleksa Vukotic</dc:creator>
				<category><![CDATA[Aleksa's Blog]]></category>
		<category><![CDATA[cake solutions]]></category>
		<category><![CDATA[collections mapping]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[hibernate collection mapping]]></category>
		<category><![CDATA[inverse mapping]]></category>
		<category><![CDATA[list mapping hibernate]]></category>
		<category><![CDATA[open source central]]></category>
		<category><![CDATA[open source centre of excellence]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/?p=194</guid>
		<description><![CDATA[Its one of those things &#8211; you have the same problem every now and then, but not often enough to remember what the solution was. I was implementing some hibernate code, but the tests for it failed due to primary &#8230; <a href="http://www.cakesolutions.net/teamblogs/2009/04/23/hibernate-and-primary-key-unique-constaint-exception/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Its one of those things &#8211; you have the same problem every now and then, but not often enough to remember what the solution was.<br />
I was implementing some hibernate code, but the tests for it failed due to primary key constraint exception (basically hibernate was trying to save already save object using same primary key). I can clearly remember that i have seen this exception before, but the cause and solution were lost somewhere between all those NonUniqueObjectExceptions and jsp exceptions that i had problems with few weeks ago <img src='http://www.cakesolutions.net/teamblogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br />
So i had to dig into in once more, and promise to myself that i will blog it after i diagnose the problem, so i don&#8217;t forget about it ever again (and save someone else the trouble as well). So here it is:</p>
<p>The domain model and hibernate mapping were really basic &#8211; Descriptor object has reference to List of Note objects:</p>
<pre>
<code>
public class Descriptor{
    private Long id;
    private List&lt;Note&gt; notes = new ArrayList&lt;Note&gt;;

    public void addNote(Note note){
       note.setDescriptor(note);
       this.notes.add(note);
   }
   //getters and setters omitted for clarity
}
public class Note{
    private Long id;
    private String text;
    private Descriptor descriptor;
    //getters and setters omitted for clarity
}
&lt;class name="Descriptor" table="t_descriptor"&gt;
        &lt;id name="id" type="long" unsaved-value="null"&gt;
            &lt;generator class="sequence"&gt;
                &lt;param name="sequence"&gt;s_descriptor_id&lt;/param&gt;
            &lt;/generator&gt;
        &lt;/id&gt;

        &lt;list name="notes" cascade="all"
            &lt;key column="descriptor"/&gt;
            &lt;index column="id"/&gt;
            &lt;one-to-many class="Note"/&gt;
        &lt;/list&gt;
&lt;/class&gt;
&lt;class name="Note" table="t_note"&gt;
        &lt;id name="id" type="long" unsaved-value="null"&gt;
            &lt;generator class="sequence"&gt;
                &lt;param name="sequence"&gt;s_note&lt;/param&gt;
            &lt;/generator&gt;
        &lt;/id&gt;
        &lt;property name="text" column="text" not-null="true"/&gt;
        &lt;many-to-one name="descriptor" column="descriptor" not-null="true"
                     class="Descriptor"/&gt;
    &lt;/class&gt;
</code>
</pre>
<p>Looks simple, but when i run the test for the code above, i got dreaded primary key unique constraint exception.<br />
After a bit of though, i was able to kick myself for not noticing the problem:<br />
The notes property of Descriptor class is mapped with cascade=&#8221;all&#8221; meaning all save, updates, deletes with apply for the child objects as well. However, the inverse is set to false (inverse property is missing, defaults to inverse=&#8221;false&#8221;) &#8211; making both sides of the bi-directional relationship responsible of taking care of the relationship. SO Hibernate generates two insert statements, one because of cascade=&#8221;all&#8221;, and one as part of inverse=&#8221;false&#8221; rule.<br />
The solutions is to set inverse=&#8221;true&#8221; on notes property mapping &#8211; this will make just one side of bi-directional relationship responsible for relationship, and the Hibernate will issue just one insert statement for the Note object.<br />
Here is the correct piece of mapping:</p>
<pre>
        &lt;list name="notes" cascade="all" <strong>inverse="true"&gt;</strong>
            &lt;key column="descriptor"/&gt;
            &lt;index column="id"/&gt;
            &lt;one-to-many class="Note"/&gt;
        &lt;/list&gt;
</pre>
<p>Huh! Cascade and inverse properties when mapping collections in hibernate simplify the development, and improve performance if used correctly, but beware of the pitfalls of unsuspected exception.<br />
To read more go to the Hibernate website or read this blog: <a href="http://www.codeweblog.com/hibernate-in-the-inverse-and-cascade/">http://www.codeweblog.com/hibernate-in-the-inverse-and-cascade/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2009/04/23/hibernate-and-primary-key-unique-constaint-exception/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>UTF-8 encoding and Spring message sources</title>
		<link>http://www.cakesolutions.net/teamblogs/2009/04/02/utf-8-encoding-and-message-sources/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=utf-8-encoding-and-message-sources</link>
		<comments>http://www.cakesolutions.net/teamblogs/2009/04/02/utf-8-encoding-and-message-sources/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 13:59:49 +0000</pubDate>
		<dc:creator>Aleksa Vukotic</dc:creator>
				<category><![CDATA[Aleksa's Blog]]></category>
		<category><![CDATA[MessageSource]]></category>
		<category><![CDATA[properties]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[spring mvc]]></category>
		<category><![CDATA[utf-8]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/?p=113</guid>
		<description><![CDATA[Take a look at the update from October 2011&#8242;s perspective here. I was working on a pretty much straight-forward web application. As usual, i used Spring&#8217;s org.springframework.context.MessageSourcesupport, to be more precise, i used standard implementation &#8211; ResourceBundleMessageSource. Simple configuration, as &#8230; <a href="http://www.cakesolutions.net/teamblogs/2009/04/02/utf-8-encoding-and-message-sources/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Take a look at the update from October 2011&#8242;s perspective <a href="http://www.cakesolutions.net/teamblogs/2011/11/08/utf-8-encoding-revisited/" title="UTF-8 encoding revisited">here</a>.</p>
<p>I was working on a pretty much straight-forward web application. As usual, i used Spring&#8217;s org.springframework.context.MessageSourcesupport, to be more precise, i used standard implementation &#8211;  ResourceBundleMessageSource. Simple configuration, as following:</p>
<pre>&lt;bean id="messageSource"
                 class="org.springframework.context.support.ResourceBundleMessageSource"&gt;
          &lt;property name="basename" value="messages"/&gt;
&lt;/bean&gt;
</pre>
<p>My messages properties file was standard as well, country names, so i had something like this:</p>
<pre>country.name.unitedkindom=UK
country.name.ireland=Ireland
country.name.belgium=België
country.name.iceland=Ísland
country.name.israel=Israel...</pre>
<p>As you can guess, the problems developed with specific characters in country names(ë, Í&#8230;). When i run the application, i got &#8216;???&#8217; characters instead of specific UTF-8 characters for countries (so &#8216;België&#8217; become &#8216;Belgi???&#8217;).</p>
<p>After some research, and digging in Spring source code, i located the problem, and the solution!</p>
<p>The problem was that ResourceBundleMessageSource uses the standard  java.util.ResourceBundle and<br />
java.util.Properties, which only support ISO-8859-1 encoding &#8211; so no UTF-8 encoding, no support for any special French, Spanish or Asian characters.</p>
<p>The solutions is very simple, and it comes with Spring as well. Use ReloadableResourceBundleMessageSource instead! Here is the correct configuration:</p>
<pre>&lt;bean id="messageSource";
                     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
         &lt;property name="basename" value="classpath:messages"/&gt;
         &lt;property name="defaultEncoding" value="UTF-8"/&gt;
&lt;/bean&gt;</pre>
<p>As you can see, we are now able ot set default encoding explicitelly, so the countries names in my example worked like charm. The only other change was that the basename is now specified as Resource, so i was able to use convenient classpath: identifier to specify my messages.properties wherever i need it in the source code</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2009/04/02/utf-8-encoding-and-message-sources/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>&#8216;Oracle Database Security and Compliance&#8217; Conference</title>
		<link>http://www.cakesolutions.net/teamblogs/2009/03/03/oracle-database-security-and-compliance-conference/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=oracle-database-security-and-compliance-conference</link>
		<comments>http://www.cakesolutions.net/teamblogs/2009/03/03/oracle-database-security-and-compliance-conference/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 17:39:24 +0000</pubDate>
		<dc:creator>Aleksa Vukotic</dc:creator>
				<category><![CDATA[Aleksa's Blog]]></category>
		<category><![CDATA[10g]]></category>
		<category><![CDATA[11g]]></category>
		<category><![CDATA[data encryption]]></category>
		<category><![CDATA[data masking]]></category>
		<category><![CDATA[database security]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[oracle security]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/?p=102</guid>
		<description><![CDATA[I have attended Oracle one-day conference titled &#8216;Database Security and Compliance&#8217; in London last week, and here is the brief report. There were 3 very useful talks (and a very good lunch after:) &#8211; as expected of Oracle I guess. &#8230; <a href="http://www.cakesolutions.net/teamblogs/2009/03/03/oracle-database-security-and-compliance-conference/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have attended Oracle one-day conference titled &#8216;Database Security and Compliance&#8217; in London last week, and here is the brief report.</p>
<p>There were 3 very useful talks (and a very good lunch after:) &#8211; as expected of Oracle I guess.</p>
<p>The conference was aimed at large organizations, with considerable amounts of sensitive data stored in Oracle databases and the way in which they store and transport the data. </p>
<p>i) Oracle provides pretty useful tool for encrypting all data in a database transparently, so applications and users still see data as normal, but the data is encrypted internally. It is the question of just turning it on and selecting the encryption algorithm for it to be used (from Enterprise Manager Web Interface) and the actual data stored in data files on hard disk drive will be encrypted on the actual medium.<br />
With encryption turned on,  if anyone gets hands on the hard drive from database server, or if someone nicks the entire server from the data centre (not unheard-of <img src='http://www.cakesolutions.net/teamblogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) for example, actual data will be scribbled and so of no use to the intruder.</p>
<p>ii) Another utility shown provides a way to encrypt the database backups and exports as well, which can then be transported without fear of losing it (even if someone leave the DVD on the train or it gets lost in the post), the data will actually be encrypted, therefore unreadable, before it reaches the destination. The Oracle 10g+ Data Pump utility for data import/export support this out of the box.</p>
<p>iii) Finally, a couple of very useful tools for data masking. Imagine a complex application that deals with large amounts of data. In order for it to be developed as scalable, and to perform good, without bugs, the development and testing teams would require the real world data for the development process. However, since the data contains sensitive information, it cannot be given to them in its raw form. What development teams then resort to is the local database, with imaginary data. However, development or testing databases populated in this way usually don&#8217;t have the required amount of data (which may be in millions on the production system). What would be better is to use the actual production data, but with the sensitive columns masked, so they are unreadable, and therefore unavailable for any misuse while held at development and testing machines.<br />
The demo shown used just a couple of mouse clicks to mask all sensitive data columns (names, email addresses, NI numbers&#8230;) &#8211; so &#8216;John Smith&#8217; becomes &#8216;jhkjh laskjlkjlk&#8217; for example. There are advance features as well, so you can mask sensitive columns but keep them human-readable, by using a set of rules or even an another set of data – so you can mask &#8216;John Smith&#8217; to &#8216;Peter Taylor&#8217; in the masked database. The masking process can be deterministic or not, depending on the security constraints. The deterministic approach is a bit less secure, but the data will always be masked in the same way, no matter how many times the masking process is run (therefore &#8216;John Smith&#8217; from production database will always be masked as &#8216;Peter Taylor&#8217; – so the testing teams can pick the &#8216;peter Taylor&#8217; record every time, and each time be sure they are using the same database row as before). The non-deterministic approach will mask the data differently every time the masking is applied.</p>
<p>Each of these looks very useful and easy to use (on the demo at least:)). The demos shown used an Oracle Enterprise Manager web application to do the tasks, from the browser, but it is possible to run each of the from the command line or sqlplus as well.</p>
<p><em>Further resources:</em><br />
<a href="http://www.oracle.com/technology/deploy/security/database-security/index.html">http://www.oracle.com/technology/deploy/security/database-security/index.html</a><br />
<a href="http://www.oracle.com/technology/products/oem/pdf/ds_datamasking.pdf">http://www.oracle.com/technology/products/oem/pdf/ds_datamasking.pdf</a><br />
<a href="http://www.oracle.com/technology/deploy/security/database-security/transparent-data-encryption/index.html">http://www.oracle.com/technology/deploy/security/database-security/transparent-data-encryption/index.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2009/03/03/oracle-database-security-and-compliance-conference/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Spring WebFlow &#8211; Passing Objects Between Parent Flow and Subflows</title>
		<link>http://www.cakesolutions.net/teamblogs/2008/07/16/spring-webflow-passing-objects-between-parent-flow-and-subflows/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=spring-webflow-passing-objects-between-parent-flow-and-subflows</link>
		<comments>http://www.cakesolutions.net/teamblogs/2008/07/16/spring-webflow-passing-objects-between-parent-flow-and-subflows/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 15:56:58 +0000</pubDate>
		<dc:creator>Aleksa Vukotic</dc:creator>
				<category><![CDATA[Aleksa's Blog]]></category>
		<category><![CDATA[input parameters]]></category>
		<category><![CDATA[input-mapper]]></category>
		<category><![CDATA[output parameters]]></category>
		<category><![CDATA[output-mapper]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[spring webflow]]></category>
		<category><![CDATA[subflow]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/?p=57</guid>
		<description><![CDATA[While I was implementing web application using Spring WebFlow, I came to the point where i wanted to pass object created in the subflow to its parent flow. I looked at the WebFlow documentation, and forums and blogs as well, &#8230; <a href="http://www.cakesolutions.net/teamblogs/2008/07/16/spring-webflow-passing-objects-between-parent-flow-and-subflows/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While I was implementing web application using Spring WebFlow, I came to the point where i wanted to pass object created in the subflow to its parent flow.<br />
I looked at the WebFlow documentation, and forums and blogs as well, and it seems that there is a bit of confusion with the webflow configuration of input and output parameters.<br />
So here is what i have done to make it work:</p>
<p>If you want to pass object from subflow to its parent flow, you should declare it as output parameter in the end state of the subflow:<br />
<code>
<pre>
    &lt;end-state id="endUpload" view="endupload" &gt;
        &lt;output-mapper&gt;
            &lt;mapping source="${flowScope.subflowResult}" target="subflowResult"/&gt;
        &lt;/output-mapper&gt;
    &lt;/end-state&gt;
</pre>
<p></code></p>
<p>Note that the source argument is the parameter value as it is referenced in current flow (subflow), including the scope qualifier. Target is the text value, which will be the key in the generic parameters map that is transfered between subflow and its parent.</p>
<p>In the parent flow, you must declare output-mapper in the subflow-state section:<br />
<code>
<pre>
   &lt;subflow-state id="uploadFile" flow="upload-flow">
        &lt;attribute-mapper&gt;
            &lt;output-mapper&gt;
                &lt;mapping source="${subflowResult}" target="flowScope.result"/&gt;
            &lt;/output-mapper&gt;
        &lt;/attribute-mapper&gt;
        &lt;transition on="endUpload" to="startPublication"/&gt;
    &lt;/subflow-state&gt;
</pre>
<p></code></p>
<p>Now there is one very important difference in the output mapper: the source parameter is now the text, defining the key in the generic parameter map transfered from subflow, and the source is the the parameter name in the current flow (now parent flow) &#8211; including the scope qualifier.</p>
<p>And thats it!</p>
<p>If you want to do the oposite, pass the object as a parameter from the parent flow to the subflow, you will do similiar thing, only this time you will be dealing with input-mappers:<br />
In parent flow definition, you will add input-mapper to the subflow-state definition:<br />
<code>
<pre>
&lt;subflow-state id="transition" flow="workflow-flow"&gt;
        &lt;attribute-mapper&gt;
            &lt;input-mapper/&gt;
                &lt;mapping source="flowScope.parentFlowParameter" target="parentFlowParameter"/&gt;
            &lt;/input-mapper&gt;
        &lt;/attribute-mapper&gt;
        &lt;transition on="done" to="done"/&gt;
    &lt;/subflow-state&gt;
</pre>
<p></code></p>
<p>And it the subflow, input mapper is needed at the beginning of the flow definition file:<br />
<code>
<pre>
&lt;input-mapper/&gt;
        &lt;mapping source="parentFlowParameter" target="flowScope.myparameter"/&gt;
&lt;/input-mapper&gt;
</pre>
<p></code></p>
<p>I hope this will help some of you dealing with the same problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2008/07/16/spring-webflow-passing-objects-between-parent-flow-and-subflows/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Acegi Concurrent Login</title>
		<link>http://www.cakesolutions.net/teamblogs/2008/05/08/acegi-concurrent-login/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=acegi-concurrent-login</link>
		<comments>http://www.cakesolutions.net/teamblogs/2008/05/08/acegi-concurrent-login/#comments</comments>
		<pubDate>Thu, 08 May 2008 09:05:05 +0000</pubDate>
		<dc:creator>Aleksa Vukotic</dc:creator>
				<category><![CDATA[Aleksa's Blog]]></category>
		<category><![CDATA[acegi]]></category>
		<category><![CDATA[concurrent login]]></category>
		<category><![CDATA[concurrentloginexception]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/2008/05/08/acegi-concurrent-login/</guid>
		<description><![CDATA[It is a security requirement for most web sites to disable concurrent logins, so users cannot login from different machines using same login details. Let&#8217;s see how to enable this functionality with Acegi Security. Firstly, add org.acegisecurity.concurrent.SessionRegistry implementation bean to &#8230; <a href="http://www.cakesolutions.net/teamblogs/2008/05/08/acegi-concurrent-login/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It is a security requirement for most web sites to disable concurrent logins, so users cannot login from different machines using same login details.</p>
<p>Let&#8217;s see how to enable this functionality with Acegi Security.</p>
<p>Firstly, add <code>org.acegisecurity.concurrent.SessionRegistry</code> implementation bean to your security context:<br />
<code>
<pre>
&lt;bean id="sessionRegistry" class="org.acegisecurity.concurrent.SessionRegistryImpl" /&gt;
</pre>
<p></code></p>
<p>We are using default Acegi implementation <code>org.acegisecurity.concurrent.SessionRegistryImpl</code>.</p>
<p>Next, define the <code>org.acegisecurity.concurrent.SessionController bean</code>:</p>
<pre>
<code>
    &lt;bean id="sessionController" class="org.acegisecurity.
           concurrent.ConcurrentSessionControllerImpl"&gt;
        &lt;property name="exceptionIfMaximumExceeded" value="true"/&gt;
        &lt;property name="maximumSessions" value="1" /&gt;
        &lt;property name="sessionRegistry" ref="sessionRegistry"/&gt;
    &lt;/bean&gt;
</code>
</pre>
<p>As you can see, it takes <code>sessionRegistry</code> property, as well as two additional properties <code>maximumSessions</code> and <code>exceptionIfMAximumExceeded</code>.<br />
<code>maximumSessions</code> says how meny concurrent login sessions  are allowed (in our case just one)<br />
if <code>exceptionIfMAximumExceeded</code> property is set to true, exception will be thrown every time the user tries to login concurrently. You can check this exception in your login controller and display user with a message.<br />
Otherwise, if <code>exceptionIfMAximumExceeded property</code> is set to false, exception will NOT be thrown. If user tries to login concurrently, he will be allowed, but his last login session (before the concurrent one) will be invalidated.</p>
<p>Last step is to add  <code>sessionController</code> property to your <code>ProviderManager</code> bean:<br />
<code>
<pre>
     &lt;bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager"&gt;
		&lt;property name="providers"&gt;
			&lt;list&gt;
				&lt;ref local="daoAuthenticationProvider"/&gt;
			&lt;/list&gt;
		&lt;/property&gt;
        &lt;property name="sessionController" ref="sessionController"/&gt;
    &lt;/bean&gt;
</pre>
<p></code></p>
<p>And you&#8217;re ready to run.</p>
<p>Some users have encountered problems with concurrent logins: If a user logs out, and then tries to log in again, the <code>ConcurrentLoginException</code> is thrown, so user cannot log in again. This happens when Acegi logout does not remove the session data for the user that has been logout out (before his login session has expired)<br />
In order to fix this, you can manually clear the authentication session for the user that&#8217;s logged out:<br />
<code>
<pre>
public void logout() {
        SecurityContext context = SecurityContextHolder.getContext();
        if (context == null) return;
        Authentication authentication = context.getAuthentication();
        if (authentication == null) return;
        String sessionId = SessionRegistryUtils.obtainSessionIdFromAuthentication(authentication);
        this.sessionRegistry.removeSessionInformation(sessionId);
}
</pre>
<p></code><br />
You will also need this code to be run when Acegi session gets unpublished.<br />
For this implement <code>org.acegisecurity.ui.session.HttpSessionEventPublisher</code>, and configure listener for it in your web.xml:<br />
<code>
<pre>
public class MyHttpSessionEventPublisher extends HttpSessionEventPublisher {
    private static final Log logger = LogFactory.getLog(MyHttpSessionEventPublisher.class);
    private UserContext userContext;

    public void sessionDestroyed(HttpSessionEvent event) {
        logger.info("unpublishing session");
        if (userContext == null) {
            this.userContext = lookupBean(
                        WebApplicationContextUtils.
                             getWebApplicationContext(
                              event.getSession().getServletContext()),
                       "userContext",
                       UserContext.class);
        }

        this.userContext.invalidate();
        super.sessionDestroyed(event);
    }

    private  T lookupBean(final ApplicationContext applicationContext, final String beanName, final Class c) {
        //noinspection unchecked
        return (T) applicationContext.getBean(beanName, c);
    }
}
</pre>
<p></code></p>
<p>In web.xml you will have:<br />
<code>
<pre>
&lt;listener&gt;
        &lt;listener-class&gt;net.cakesolutions.service.security.acegi.BimHttpSessionEventPublisher&lt;/listener-class&gt;
&lt;/listener&gt;
</pre>
<p></code><br />
And you&#8217;re ready to go.</p>
<p>Hope this article has helped anyone in configuring concurrent logins with Acegi Security.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2008/05/08/acegi-concurrent-login/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Email Header Injection security</title>
		<link>http://www.cakesolutions.net/teamblogs/2008/05/08/email-header-injection-security/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=email-header-injection-security</link>
		<comments>http://www.cakesolutions.net/teamblogs/2008/05/08/email-header-injection-security/#comments</comments>
		<pubDate>Thu, 08 May 2008 08:31:08 +0000</pubDate>
		<dc:creator>Aleksa Vukotic</dc:creator>
				<category><![CDATA[Aleksa's Blog]]></category>
		<category><![CDATA[email header injection]]></category>
		<category><![CDATA[email security]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/2008/05/08/email-header-injection-security/</guid>
		<description><![CDATA[If you web application sends emails based on information entered in the form, you should pay attention to the possibility of Email header injection attack. Email header injection attack is based on flaws in the email protocol. Headers in the &#8230; <a href="http://www.cakesolutions.net/teamblogs/2008/05/08/email-header-injection-security/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you web application sends emails based on information entered in the form, you should pay attention to the possibility of Email header injection attack.<br />
Email header injection attack is based on flaws in the email protocol. Headers in the MIME message are recognized by SMTP servers by the line feed ([LF]). So typical email message looks like this:<br />
<code><br />
[LF]to: recipient@domain.com<br />
[LF]Subject: recipient@domain.com<br />
[LF]Content type: recipient@domain.com<br />
[LF]Message body<br />
</code><br />
Now if a user can enter recipient email in the form he/she can do something like this:<br />
<code><br />
recipient email: johndoe@serbiancafe.com%0Asubject:this is new even subject.<br />
</code><br />
%0A is actually line feed.<br />
Now, it will depend from SMTP server and email client which subject will it show, some use first one, some the lates one, some append all subjects to email.</p>
<p>Malicious user can change any header of your message this way, to, cc, bcc fields, content-type, even the actual message.</p>
<p>Message body can be changed in the same way, only without the header name. But note that body added like this will be PREPENDED to the email message. So if someone uses your email form to send an email message with new body he/she can enter the follwing in the available form filed (in our case recipient address):<br />
<code><br />
recipient email: johndoe@serbiancafe.com%0Asubject:this is new even subject.%0AThe Spam message body, you didnt want this, but it will come to your inbox<br />
</code><br />
And without knowing it, your &#8216;email this page to a friend&#8217; form will become the source of spam!</p>
<p>Now how to resolve this issue?<br />
You shpuld check all the fields that are available for user input in your email form for  and  characters (&#8216;\n&#8217; and &#8216;\r&#8217; in your java code).</p>
<p>You have two approaches available. You can either:<br />
1. reject to send any email that contains any of these characters (recommended)<br />
2. remove the characters and send the email as it is </p>
<p>The java code that does this is very simple:</p>
<p><code><br />
public static boolean isHeaderInjection(String value) {<br />
        if (value == null) return false;<br />
        if ((value.indexOf("\n") != -1 || value.indexOf("\r") != -1) || value.indexOf("%0A") != -1) {<br />
            return true;<br />
        }<br />
         return false;<br />
     }<br />
</code></p>
<p>Make sure to check all your email form fields, and you should be safe from this kind of attack.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2008/05/08/email-header-injection-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My First Post</title>
		<link>http://www.cakesolutions.net/teamblogs/2008/01/23/my-first-post-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=my-first-post-2</link>
		<comments>http://www.cakesolutions.net/teamblogs/2008/01/23/my-first-post-2/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 09:11:23 +0000</pubDate>
		<dc:creator>Aleksa Vukotic</dc:creator>
				<category><![CDATA[Aleksa's Blog]]></category>
		<category><![CDATA[ana ivanovic]]></category>
		<category><![CDATA[australian open]]></category>
		<category><![CDATA[djokovic]]></category>
		<category><![CDATA[ivanovic]]></category>
		<category><![CDATA[novak djokovic]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/?p=11</guid>
		<description><![CDATA[Finally my first post. It comes after sleepless night watching Australian Open (Djokovic and Ivanovic joined Jankovic in the semis, and in style, was worth it:)). Some interesting times ahead, with Pro Spring 2.5 book work nearing the end, and &#8230; <a href="http://www.cakesolutions.net/teamblogs/2008/01/23/my-first-post-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Finally my first post.</p>
<p>It comes after sleepless night watching Australian Open (Djokovic and Ivanovic joined Jankovic in the semis, and in style, was worth it:)).</p>
<p>Some interesting times ahead, with Pro Spring 2.5 book work nearing the end, and few new projects coming.</p>
<p>I am currently working on some JMX management on Weblogic 9.2, will keep you posted how it goes.</p>
<p>Hopefully this is just a start of regular blog posting for me.</p>
<p>See you soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2008/01/23/my-first-post-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

