001    package org.jboss.dna.jcr;
002    
003    import javax.jcr.Credentials;
004    import org.jboss.dna.common.util.CheckArg;
005    import org.jboss.dna.graph.SecurityContext;
006    
007    /**
008     * {@link Credentials} implementation that wraps a {@link SecurityContext DNA security context}.
009     * <p>
010     * This class provides a means of passing security information about an authenticated user into {@link JcrSession the DNA JCR
011     * session implementation} without using JAAS. This class effectively bypasses DNA's internal authentication mechanisms, so it is
012     * very important that this context be provided for <i>authenticated users only</i>.
013     * </p>
014     */
015    public final class SecurityContextCredentials implements Credentials {
016        private static final long serialVersionUID = 1L;
017        private final SecurityContext securityContext;
018    
019        /**
020         * Initializes the class with an existing {@link SecurityContext security context}.
021         * 
022         * @param securityContext the security context; may not be null
023         */
024        public SecurityContextCredentials( SecurityContext securityContext ) {
025            CheckArg.isNotNull(securityContext, "securityContext");
026    
027            this.securityContext = securityContext;
028        }
029    
030        /**
031         * Returns the {@link SecurityContext security context} for this instance.
032         * 
033         * @return the {@link SecurityContext security context} for this instance; never null
034         */
035        public final SecurityContext getSecurityContext() {
036            return this.securityContext;
037        }
038    }