View Javadoc

1   package org.modeshape.jcr;
2   
3   import javax.jcr.Credentials;
4   import org.modeshape.common.util.CheckArg;
5   import org.modeshape.graph.SecurityContext;
6   
7   /**
8    * {@link Credentials} implementation that wraps a {@link SecurityContext ModeShape security context}.
9    * <p>
10   * This class provides a means of passing security information about an authenticated user into {@link JcrSession the ModeShape JCR
11   * session implementation} without using JAAS. This class effectively bypasses ModeShape's internal authentication mechanisms, so it is
12   * very important that this context be provided for <i>authenticated users only</i>.
13   * </p>
14   */
15  public final class SecurityContextCredentials implements Credentials {
16      private static final long serialVersionUID = 1L;
17      private final SecurityContext securityContext;
18  
19      /**
20       * Initializes the class with an existing {@link SecurityContext security context}.
21       * 
22       * @param securityContext the security context; may not be null
23       */
24      public SecurityContextCredentials( SecurityContext securityContext ) {
25          CheckArg.isNotNull(securityContext, "securityContext");
26  
27          this.securityContext = securityContext;
28      }
29  
30      /**
31       * Returns the {@link SecurityContext security context} for this instance.
32       * 
33       * @return the {@link SecurityContext security context} for this instance; never null
34       */
35      public final SecurityContext getSecurityContext() {
36          return this.securityContext;
37      }
38  }