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 */ 019package org.apache.shiro.mgt; 020 021import org.apache.shiro.session.Session; 022import org.apache.shiro.subject.PrincipalCollection; 023import org.apache.shiro.subject.Subject; 024import org.apache.shiro.subject.SubjectContext; 025import org.apache.shiro.subject.support.DelegatingSubject; 026 027 028/** 029 * Default {@link SubjectFactory SubjectFactory} implementation that creates 030 * {@link org.apache.shiro.subject.support.DelegatingSubject DelegatingSubject} 031 * instances. 032 * 033 * @since 1.0 034 */ 035public 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 boolean sessionCreationEnabled = context.isSessionCreationEnabled(); 044 PrincipalCollection principals = context.resolvePrincipals(); 045 boolean authenticated = context.resolveAuthenticated(); 046 String host = context.resolveHost(); 047 048 return new DelegatingSubject(principals, authenticated, host, session, sessionCreationEnabled, securityManager); 049 } 050 051 /** 052 * @deprecated since 1.2 - override {@link #createSubject(org.apache.shiro.subject.SubjectContext)} directly if you 053 * need to instantiate a custom {@link Subject} class. 054 */ 055 @Deprecated 056 protected Subject newSubjectInstance(PrincipalCollection principals, boolean authenticated, String host, 057 Session session, SecurityManager securityManager) { 058 return new DelegatingSubject(principals, authenticated, host, session, true, securityManager); 059 } 060 061}