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.web.tags;
020
021 import javax.servlet.jsp.JspException;
022
023 import org.slf4j.Logger;
024 import org.slf4j.LoggerFactory;
025
026
027 /**
028 * JSP tag that renders the tag body if the current user known to the system, either from a successful login attempt
029 * (not necessarily during the current session) or from 'RememberMe' services.
030 *
031 * <p><b>Note:</b> This is <em>less</em> restrictive than the <code>AuthenticatedTag</code> since it only assumes
032 * the user is who they say they are, either via a current session login <em>or</em> via Remember Me services, which
033 * makes no guarantee the user is who they say they are. The <code>AuthenticatedTag</code> however
034 * guarantees that the current user has logged in <em>during their current session</em>, proving they really are
035 * who they say they are.
036 *
037 * <p>The logically opposite tag of this one is the {@link org.apache.shiro.web.tags.GuestTag}.
038 *
039 * @since 0.9
040 */
041 public class UserTag extends SecureTag {
042
043 //TODO - complete JavaDoc
044
045 private static final Logger log = LoggerFactory.getLogger(UserTag.class);
046
047 public int onDoStartTag() throws JspException {
048 if (getSubject() != null && getSubject().getPrincipal() != null) {
049 if (log.isTraceEnabled()) {
050 log.trace("Subject has known identity (aka 'principal'). " +
051 "Tag body will be evaluated.");
052 }
053 return EVAL_BODY_INCLUDE;
054 } else {
055 if (log.isTraceEnabled()) {
056 log.trace("Subject does not exist or have a known identity (aka 'principal'). " +
057 "Tag body will not be evaluated.");
058 }
059 return SKIP_BODY;
060 }
061 }
062
063 }