001 // Copyright 2010, 2011 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry5.internal.services; 016 017 import org.apache.tapestry5.Link; 018 019 /** 020 * Identifies how a {@link Link} should handle security. 021 * 022 * @since 5.2.2 023 */ 024 public enum LinkSecurity 025 { 026 /** The request was insecure, but the targeted page was secure, so the URI should be absolute and secure. */ 027 FORCE_SECURE, 028 029 /** The request was was secure but the targeted page is not, so the URI should be absolute and insecure. */ 030 FORCE_INSECURE, 031 032 /** 033 * The request is insecure, which matches the targeted page security, so there's no explicit need for an absolute 034 * URI. 035 */ 036 INSECURE, 037 038 /** 039 * The request is secure, which matches the targeted page security, so there's no explicit need for an absolute 040 * URI. 041 */ 042 SECURE; 043 044 /** Promotes to either {@link #FORCE_SECURE} or {@link #FORCE_INSECURE}. */ 045 public LinkSecurity promote() 046 { 047 switch (this) 048 { 049 case SECURE: 050 case FORCE_SECURE: 051 return FORCE_SECURE; 052 053 default: 054 return FORCE_INSECURE; 055 } 056 } 057 058 /** Does this value indicate forcing an absolute URI (one that includes scheme and hostname)? */ 059 public boolean isAbsolute() 060 { 061 return this == FORCE_SECURE || this == FORCE_INSECURE; 062 } 063 }