1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.shiro.web.tags; 20 21 import javax.servlet.jsp.JspException; 22 23 import org.slf4j.Logger; 24 import org.slf4j.LoggerFactory; 25 26 27 /** 28 * JSP tag that renders the tag body if the current user known to the system, either from a successful login attempt 29 * (not necessarily during the current session) or from 'RememberMe' services. 30 * 31 * <p><b>Note:</b> This is <em>less</em> restrictive than the <code>AuthenticatedTag</code> since it only assumes 32 * the user is who they say they are, either via a current session login <em>or</em> via Remember Me services, which 33 * makes no guarantee the user is who they say they are. The <code>AuthenticatedTag</code> however 34 * guarantees that the current user has logged in <em>during their current session</em>, proving they really are 35 * who they say they are. 36 * 37 * <p>The logically opposite tag of this one is the {@link org.apache.shiro.web.tags.GuestTag}. 38 * 39 * @since 0.9 40 */ 41 public class UserTag extends SecureTag { 42 43 //TODO - complete JavaDoc 44 45 private static final Logger log = LoggerFactory.getLogger(UserTag.class); 46 47 public int onDoStartTag() throws JspException { 48 if (getSubject() != null && getSubject().getPrincipal() != null) { 49 if (log.isTraceEnabled()) { 50 log.trace("Subject has known identity (aka 'principal'). " + 51 "Tag body will be evaluated."); 52 } 53 return EVAL_BODY_INCLUDE; 54 } else { 55 if (log.isTraceEnabled()) { 56 log.trace("Subject does not exist or have a known identity (aka 'principal'). " + 57 "Tag body will not be evaluated."); 58 } 59 return SKIP_BODY; 60 } 61 } 62 63 }