Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Spring Extensions > Spring se-jcr

Reply
 
Thread Tools Display Modes
  #1  
Old Oct 15th, 2009, 12:55 PM
lowerymb77 lowerymb77 is offline
Junior Member
 
Join Date: Aug 2005
Location: Orlando, FL
Posts: 19
Default Session per user

I have a requirement that session.login be called with the user that is logged into a web application. (The web application uses Spring Security.) The password is not important as the web application has already authenticated the user. But passing in the user on login is important as it enables features like auditing the user's behavior. I can envision a configurable credentials "strategy" in SE-JCR's SessionFactory implementation. One strategy implementation would be to get the current user from Spring Security and create a SimpleCredentials from it. Another strategy implementation would simply return a hard coded Credentials instance. From what I can tell, this approach will work however I am concerned that the presence of transactions might cause problems. For example, is it ever possible that UserB would get a session from a transaction in progress with a session for UserA? I would be more comfortable if I could have an assert that checks the user on a session before using it but where would that code go?

In general, SE-JCR assumes that sessions are created by logging in as a "master" user much like is done for JDBC. Do you find this to be a common paradigm? Has no one asked for per-user sessions yet?

Thanks for any feedback!

CredentialsStrategy:
Code:
public interface CredentialsStrategy {
  Credentials getCredentials();
}
SpringSecurityCredentialsStrategy:
Code:
public class SpringSecurityCredentialsStrategy implements CredentialsStrategy {

  public Credentials getCredentials() {
    String username = getUsername();
    return new SimpleCredentials(username, "ignored".toCharArray());
  }

  private String getUsername() {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    if (auth.getPrincipal() instanceof UserDetails) {
      return ((UserDetails) auth.getPrincipal()).getUsername();
    } else {
      return auth.getPrincipal().toString();
    }
  }
}
ConstantCredentialsStrategy:
Code:
  private Credentials credentials;

  /**
   * Null credentials.
   */
  public ConstantCredentialsStrategy() {
    super();
  }
  
  public ConstantCredentialsStrategy(final Credentials credentials) {
    super();
    this.credentials = credentials;
  }

  public Credentials getCredentials() {
    return credentials;
  }
CredentialsStrategySessionFactory:
Code:
public class CredentialsStrategySessionFactory implements InitializingBean, DisposableBean, SessionFactory {
// rest omitted

  public Session getSession() throws RepositoryException {
      Session session = repository.login(credentialsStrategy.getCredentials(), workspaceName);
      return addListeners(session);
  }

// rest omitted
}
__________________
Mat Lowery
Pentaho Developer
Reply With Quote
  #2  
Old Oct 16th, 2009, 02:35 AM
Monkiki Monkiki is offline
Junior Member
 
Join Date: Jul 2009
Posts: 7
Default

I have the same problem and I have no seen any good solution in months. Spring-jcr handle a JCR connection like a JDBC one, but I don't believe this is a good choice because in Jackrabbit the access to the repository nodes or properties are managed by an AccessManager, and this it not possible if all web users log into a Jackrabbit repository with the same credentials.
Reply With Quote
  #3  
Old Oct 21st, 2009, 07:26 AM
SalvatoreIncandela SalvatoreIncandela is offline
Junior Member
 
Join Date: May 2009
Location: Rome
Posts: 21
Default

You're right, we absolutely must do this otherwise useless. I open an issue so quickly track them down and release it soon, if you need this patch I can create a snapshot before the release of version 1.0 with COM and Jackrabbit 2.0. What do you think?
Reply With Quote
  #4  
Old Oct 21st, 2009, 09:17 AM
lowerymb77 lowerymb77 is offline
Junior Member
 
Join Date: Aug 2005
Location: Orlando, FL
Posts: 19
Default

I don't need this patch immediately but thank you for the quick response.
__________________
Mat Lowery
Pentaho Developer
Reply With Quote
  #5  
Old Oct 22nd, 2009, 10:49 AM
Monkiki Monkiki is offline
Junior Member
 
Join Date: Jul 2009
Posts: 7
Default

Salvatore, post the issue url so I can subscribe and be notified when changes. Cheers!
Reply With Quote
  #6  
Old Dec 14th, 2009, 11:30 AM
SalvatoreIncandela SalvatoreIncandela is offline
Junior Member
 
Join Date: May 2009
Location: Rome
Posts: 21
Default

http://jira.springframework.org/browse/SEJCR-22
Reply With Quote
  #7  
Old Mar 22nd, 2010, 03:56 PM
hipparco hipparco is offline
Junior Member
 
Join Date: Jun 2006
Posts: 26
Default Patch

Salvatore,

is this patch in the repository now ?

could you include it into maven to take a look on it?


thanx
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 02:16 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.