You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by zooxmusic <br...@109forest.com> on 2010/12/15 19:12:31 UTC

Re: Storing sessins in an RDBMS instead of an enterprise cache?

Les, how would I go about doing this in a Spring application where I am not
using the INI type of initialization?
-- 
View this message in context: http://shiro-user.582556.n2.nabble.com/Storing-sessins-in-an-RDBMS-instead-of-an-enterprise-cache-tp5645213p5838231.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Storing sessins in an RDBMS instead of an enterprise cache?

Posted by Les Hazlewood <lh...@apache.org>.
Hi Brian,

I had planned on trying to help with this before the holidays, but
couldn't get around to it.  I'm back from vacation now and glad to try
and help.

Typically the attributes are serialized into a byte array and saved as
a blob column.  Hibernate has a 'blob' property type that can be
specified.  You can also specify convenience methods on your
SimpleSession subclass that only Hibernate would use:

public byte[] getAttributeBytes() {
    return serialize(getAttributes());
}

public void setAttributeBytes(byte[] bytes) {
    setAttributes(deserialize(bytes));
}

your 'serialize' and 'deserialize' methods above could delegate to an
org.apache.shiro.io.DefaultSerializer instance to make your life easy.

All of this could also be externalized into an
org.hibernate.usertype.UserType implementation as well, and then you
specify that UserType for the 'attributes' property.

A slightly more robust idea is to use the same UserType technique, but
instead of a byte array, serialize the map to a text output, e.g.
using YAML, JSON, or XML and save that in a large text (e.g. clob)
column.  This is better in case you (or a 3rd party) introduce any
backwards-incompatible binary serialization changes to anything that
is stored in the attribute map. Using text will help avoid that
problem since objects would be recreated via reflection instead of
binary deserialization - at the expense of the added size and
serialization time.

HTH!

Les

On Tue, Dec 21, 2010 at 10:45 AM, zooxmusic <br...@109forest.com> wrote:
>
> Hello?
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/Storing-sessins-in-an-RDBMS-instead-of-an-enterprise-cache-tp5645213p5855606.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>

Re: Storing sessins in an RDBMS instead of an enterprise cache?

Posted by zooxmusic <br...@109forest.com>.
Hello?
-- 
View this message in context: http://shiro-user.582556.n2.nabble.com/Storing-sessins-in-an-RDBMS-instead-of-an-enterprise-cache-tp5645213p5855606.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Storing sessins in an RDBMS instead of an enterprise cache?

Posted by zooxmusic <br...@109forest.com>.
Actually all I need is your SimpleSession.hbm.xml file and how you mapped the
"Map<Object, Object> attributes" property. No matter what I do it complains. 



Anyone? Anyone? 
-- 
View this message in context: http://shiro-user.582556.n2.nabble.com/Storing-sessins-in-an-RDBMS-instead-of-an-enterprise-cache-tp5645213p5853474.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Storing sessins in an RDBMS instead of an enterprise cache?

Posted by zooxmusic <br...@109forest.com>.
Les, I have to say the fact that SimpleSession implements the attributes
property as an explicit Map<Object, Object> has caused me much heartache all
day. I am curious, you mentioned that the "easy" way was to map
SimpleSession in the hibernate xml file. Have you actually done this? Do you
have an example? Map<Object,Object> does not play nice with serialization
into hibernate or even json


If you do happen to have a working hibernate project that simply maps
SimpleSession as well as an easy DAO to persist it I would love to see it
because I am either missing something very obvious or you may have possibly
had as much heartache as I have had all day


Brian
-- 
View this message in context: http://shiro-user.582556.n2.nabble.com/Storing-sessins-in-an-RDBMS-instead-of-an-enterprise-cache-tp5645213p5847402.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Storing sessins in an RDBMS instead of an enterprise cache?

Posted by zooxmusic <br...@109forest.com>.
Got it, I didn't realize that nested property names were allowed, (DUH)


        <bean id="securityManager"
class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
	  	<property name="sessionMode" value="native"/>
		<property name="sessionManager.sessionDAO" ref="mySessionDAO"/> 
		<property name="sessionManager.sessionFactory" ref="mySessionFactory"/> 
	    <property name="realm" ref="mySecurityRealm"/>
	</bean>
-- 
View this message in context: http://shiro-user.582556.n2.nabble.com/Storing-sessins-in-an-RDBMS-instead-of-an-enterprise-cache-tp5645213p5843755.html
Sent from the Shiro User mailing list archive at Nabble.com.