Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
 
 package org.apache.wookie.beans;
 
 import java.net.URI;
IAccessRequest - access request control for a particular widget.

Author(s):
Paul Sharples
Randy Watler
Version:
$Id$
 
 public interface IAccessRequest extends IBean
 {
    
Get widget access granted flag.

Returns:
access granted flag
 
     boolean isGranted();
    
    
Set widget access granted flag.

Parameters:
granted access granted flag
 
     void setGranted(boolean granted);
    
    
Get widget access origin.

Returns:
access origin
 
     String getOrigin();
    
    
Set widget access origin.

Parameters:
origin access origin
 
     void setOrigin(String origin);
    
    
Get widget access subdomains flag.

Returns:
access subdomains flag
 
     boolean isSubdomains();
    
    
Set widget access subdomains flag.

Parameters:
subdomains access subdomains flag
 
     void setSubdomains(boolean subdomains);

    
Get default widget instance.

Returns:
widget instance
 
     IWidget getWidget();

    
Set default widget instance.

Parameters:
widget widget instance
 
     void setWidget(IWidget widget);
    
    
Implementation of the W3C WARP algorithm for a single access request.

Parameters:
requestedUri the URI requested
Returns:
true if this access request grants access, otherwise false
 
     boolean isAllowed(URI requestedUri);
    
    
Shared implementation utilities.
 
     public static class Utilities
     {
        
Implementation of the W3C WARP algorithm for a single access request.

Parameters:
requestedUri the URI requested
Returns:
true if this access request grants access, otherwise false
        public static boolean isAllowed(IAccessRequest accessRequestURI requestedUri)
        {
            // check origin wildcard
            String origin = accessRequest.getOrigin();
            if (origin.equals("*"))
            {
                return true;
            }
            // origins other than "*" MUST be valid URIs
            URI accessUri = null;
            try
            {
                accessUri = new URI(origin);
            }
            catch (URISyntaxException e)
            {
                return false;
            }
            // schemes must match
            if (!accessUri.getScheme().equalsIgnoreCase(requestedUri.getScheme()))
            {
                return false;                
            }
            // check host/subdomain
            boolean subdomains = accessRequest.isSubdomains();
            if (subdomains)
            {
                // host must match or match with subdomains
                if (!accessUri.getHost().equalsIgnoreCase(requestedUri.getHost()) &&
                    !requestedUri.getHost().endsWith("."+accessUri.getHost()))
                {
                    return false;
                }
            }
            else
            {
                // hosts must match
                if (!accessUri.getHost().equalsIgnoreCase(requestedUri.getHost()))
                {
                    return false;
                }
            }
            // ports must match
            if (accessUri.getPort()==requestedUri.getPort() || requestedUri.getPort() == -1 && accessUri.getPort() == 80)
            {
                return true;
            }
            // no match
            return false;
        }
    }
New to GrepCode? Check out our FAQ X