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.cas;
020
021import org.apache.shiro.authc.AuthenticationToken;
022import org.apache.shiro.subject.Subject;
023import org.apache.shiro.subject.SubjectContext;
024import org.apache.shiro.web.mgt.DefaultWebSubjectFactory;
025
026/**
027 * {@link org.apache.shiro.mgt.SubjectFactory Subject} implementation to be used in CAS-enabled applications.
028 *
029 * @since 1.2
030 * @see <a href="https://github.com/bujiio/buji-pac4j">buji-pac4j</a>
031 * @deprecated replaced with Shiro integration in <a href="https://github.com/bujiio/buji-pac4j">buji-pac4j</a>.
032 */
033@Deprecated
034public class CasSubjectFactory extends DefaultWebSubjectFactory {
035
036    @Override
037    public Subject createSubject(SubjectContext context) {
038
039        //the authenticated flag is only set by the SecurityManager after a successful authentication attempt.
040        boolean authenticated = context.isAuthenticated();
041
042        //although the SecurityManager 'sees' the submission as a successful authentication, in reality, the
043        //login might have been just a CAS rememberMe login.  If so, set the authenticated flag appropriately:
044        if (authenticated) {
045
046            AuthenticationToken token = context.getAuthenticationToken();
047
048            if (token != null && token instanceof CasToken) {
049                CasToken casToken = (CasToken) token;
050                // set the authenticated flag of the context to true only if the CAS subject is not in a remember me mode
051                if (casToken.isRememberMe()) {
052                    context.setAuthenticated(false);
053                }
054            }
055        }
056
057        return super.createSubject(context);
058    }
059}