there is absolutely nothing wrong with having authenticate() on
session. this kind of thinking is exactly what is wrong with the
current state of java technology.
session is an object in wicket, why should it fall prey to the anemic
data model antipattern? why should it contain data only and no
behavior?
what looks better?
session.setuserid(long id);
session.getuserid();
or
session.authenticate(credentials cred);
session.getuserid();
the former has absolutely no encapsulation or protection of data,
anyone can set whatever id they want via a simple call to setuserid().
the latter properly encapsulates the user id and protects against code
abuse.
there are a number of technologies that allow you to break out of the
anemic data model mold by allowing, in this case the session, objects
to hold on to references to services and yet remain lightweight.
wicket provides the lightweight serializable proxies which can be used
inside any object.
class mysession extends websession {
@SpringBean/@Inject
private SessionFactory sf;
private long id; <== id is private with no direct setter
public mysession(webrequest req) {
super(req);
injectionholder.getinjector().inject(this); <== injects sf var
}
public void authenticate(credentials creds) throws AuthException {
user u=sf.getnamedquery("auth")..........
id=u.getid();
}
salve.googlecode.com removes the reference field altogether and
rewrites field access with a lookup.
class mysession extends websession {
@Dependency
private SessionFactory sf; <== field will be removed via bytecode
instrumentation leaving the session object lightweight and
serializable
private long id; <== id is private with no direct setter
public mysession(webrequest req) {
super(req);
}
public void authenticate(credentials creds) throws AuthException {
user u=sf.getnamedquery("auth") <== this access to the removed sf
field will be rewritten as a lookup from configured ioc container
.......
id=u.getid();
}
-igor
On Tue, Apr 28, 2009 at 9:49 PM, Marc Ende <[email protected]> wrote:
> Hmm... I'm not sure why it's done this way in the
> AuthenticatedWebSession but
> nevertheless it's the only task of a session object to keep informations
> between
> two requests. From this point of view a authenticate(String,String)
> doesnt' really
> make sense in the Class. May be there is someone here who can explain this
> point. I wouldn't say that this is wrong, but unusual... :)
>
> May be you can get the database connection from inside the method for
> authentication purposes,
> Then you haven't got any private or public members which should be
> serialized and contains a database connection.
>
> m.
>
>
> Jan Torben Heuer schrieb:
>> Marc Ende wrote:
>>
>>
>>> webapps do. In this case you've got to serialize the connection. I don't
>>> think that's easy/possible to seralize a database connection.
>>> I would go another approach which uses the session only as a
>>> information-container and get those needed information from the
>>> database in the page-lifecycle. That keeps the session-object small
>>> (which is also an aspect).
>>>
>>
>> Hmm, following your argumentation, would you say that the
>> AuthenticatedWebSession is implemented wrong because it contains a
>> #authenticate method (which clearly needs a reference to some kind of
>> database)?
>>
>> Or would marking the field as "transient" be fine?
>>
>>
>> Cheers,
>>
>> Jan
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]