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 * @author Les Hazlewood
033 * @since 1.0
034 */
035 public class DefaultSubjectFactory implements SubjectFactory {
036
037 public DefaultSubjectFactory() {
038 }
039
040 public Subject createSubject(SubjectContext context) {
041 SecurityManager securityManager = context.resolveSecurityManager();
042 Session session = context.resolveSession();
043 PrincipalCollection principals = context.resolvePrincipals();
044 boolean authenticated = context.resolveAuthenticated();
045 String host = context.resolveHost();
046 return newSubjectInstance(principals, authenticated, host, session, securityManager);
047 }
048
049 protected Subject newSubjectInstance(PrincipalCollection principals, boolean authenticated, String host,
050 Session session, SecurityManager securityManager) {
051 return new DelegatingSubject(principals, authenticated, host, session, securityManager);
052 }
053 }