001// Copyright 2010-2013 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
015package org.apache.tapestry5.http;
016
017/**
018 * Identifies how a {@link Link} should handle security.
019 * 
020 * @since 5.2.2
021 */
022public enum LinkSecurity
023{
024    /** The request was insecure, but the targeted page was secure, so the URI should be absolute and secure. */
025    FORCE_SECURE,
026
027    /** The request was was secure but the targeted page is not, so the URI should be absolute and insecure. */
028    FORCE_INSECURE,
029
030    /**
031     * The request is insecure, which matches the targeted page security, so there's no explicit need for an absolute
032     * URI.
033     */
034    INSECURE,
035
036    /**
037     * The request is secure, which matches the targeted page security, so there's no explicit need for an absolute
038     * URI.
039     */
040    SECURE;
041
042    /** Promotes to either {@link #FORCE_SECURE} or {@link #FORCE_INSECURE}. */
043    public LinkSecurity promote()
044    {
045        switch (this)
046        {
047            case SECURE:
048            case FORCE_SECURE:
049                return FORCE_SECURE;
050
051            default:
052                return FORCE_INSECURE;
053        }
054    }
055
056    /** Does this value indicate forcing an absolute URI (one that includes scheme and hostname)? */
057    public boolean isAbsolute()
058    {
059        return this == FORCE_SECURE || this == FORCE_INSECURE;
060    }
061}