📄 urlprincipal.java
字号:
/*
* Copyright (c) 2000-2005, University of Salford
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the University of Salford nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package issrg.pba.rbac;
import issrg.utils.ParsedURL;
/**
* This class implements a Principal interface, so it can be used as an
* identifier. It also implements an Entry interface, so it can be used
* for Domain matching as well.
*
* <p>Some of the methods do not have any description, because they simply
* redirect the calls to ParsedURL object, so refer to the description of that
* class to see the meaning of the results.
*
* @author A.Otenko
*/
public class URLPrincipal implements java.security.Principal,
issrg.utils.repository.Entry {
ParsedURL pu;
int port=-1; // no port has been specified
protected URLPrincipal(){}
/**
* This constructor builds a URLPrincipal out of a URL string, and assumes
* the defaul port is unknown (getPort() will return -1, if the URL does not
* specify the port number).
*
* <p>This is equivalent to new URLPrincipal(url, -1);
*
* @param url is the string URL
*
* @throws BadURLException if the url is not a well-formed HTTP or FILE URL
*/
public URLPrincipal(String url) throws BadURLException {
this(url, -1);
}
/**
* This constructor builds a URLPrincipal given a URL string, and a default
* port number.
*
* @param url is the string URL
* @param defaultPort is the number of the default port to assume if URL does
* not
* specify any port number
*
* @throws BadURLException if the url is not a well-formed HTTP or FILE URL
*/
public URLPrincipal(String url, int defaultPort) throws BadURLException {
Exception e=null;
pu=ParsedURL.parseURL(url);
try{
if (pu!=null)
if (pu.getPort()!=null) port=Integer.parseInt(pu.getPort()); // try to parse the port number
else port=defaultPort; // pu.getPort()==null - use default port
} catch (NumberFormatException nfe){
pu=null; // next line will throw an exception
e=nfe;
}
if (pu==null) throw new BadURLException("Malformed URL: "+url, e); // embed root cause, if any
}
/**
* This method returns a normalised URL (i.e. the path is without '.' and
* '..' elements, etc.)
*/
public String getName(){
return pu.getNormalizedURL();
}
public java.security.Principal getEntryName(){
return this;
}
public String getProtocol(){
return pu.getProtocol();
}
public String getUserName(){
return pu.getUserName();
}
public String getPassword(){
return pu.getPassword();
}
public String getHost(){
return pu.getHost();
}
/**
* This method returns a port number. Returns -1, if no port has been
* specified
* in the URL or in the constructor (use default).
*
* @return the port number, or -1, if no port has been specified in the URL
*/
public int getPort(){
return port;
}
public String [] getPath(){
return pu.getPath();
}
public String [] getOriginalPath(){
return pu.getOriginalPath();
}
public String getAnchor(){
return pu.getAnchor();
}
public String getQuery(){
return pu.getQuery();
}
/**
* This method returns the whole original URL; normalised URL can be obtained
* using getName() method.
*/
public String getURL(){
return pu.getURL();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -