001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    package org.apache.shiro.mgt;
020    
021    import org.apache.shiro.session.Session;
022    import org.apache.shiro.subject.PrincipalCollection;
023    import org.apache.shiro.subject.Subject;
024    import org.apache.shiro.subject.SubjectContext;
025    import org.apache.shiro.subject.support.DelegatingSubject;
026    
027    
028    /**
029     * Default {@link SubjectFactory SubjectFactory} implementation that creates {@link org.apache.shiro.subject.support.DelegatingSubject DelegatingSubject}
030     * instances.
031     *
032     * @since 1.0
033     */
034    public class DefaultSubjectFactory implements SubjectFactory {
035    
036        public DefaultSubjectFactory() {
037        }
038    
039        public Subject createSubject(SubjectContext context) {
040            SecurityManager securityManager = context.resolveSecurityManager();
041            Session session = context.resolveSession();
042            boolean sessionCreationEnabled = context.isSessionCreationEnabled();
043            PrincipalCollection principals = context.resolvePrincipals();
044            boolean authenticated = context.resolveAuthenticated();
045            String host = context.resolveHost();
046    
047            return new DelegatingSubject(principals, authenticated, host, session, sessionCreationEnabled, securityManager);
048        }
049    
050        /**
051         * @deprecated since 1.2 - override {@link #createSubject(org.apache.shiro.subject.SubjectContext)} directly if you
052         *             need to instantiate a custom {@link Subject} class.
053         */
054        @Deprecated
055        protected Subject newSubjectInstance(PrincipalCollection principals, boolean authenticated, String host,
056                                             Session session, SecurityManager securityManager) {
057            return new DelegatingSubject(principals, authenticated, host, session, true, securityManager);
058        }
059    
060    }