java.lang.Object
|
+--stec.iws.HttpServlet
|
+--stec.iws.Realm
public abstract class Realm extends HttpServlet
Defines methods used by security realms.
Methods
|
Method
|
Description
|
|
run
|
Called by iServer for each client request to check security privileges.
|
run
Called by iServer for each client request to check security privileges.
Syntax
public abstract Object run(HttpServletRequest request,
HttpServletResponse reponse)
throws Exception
Parameters
|
request
|
the client's request.
|
|
response
|
the client's response.
|
Returns
|
Object
|
any access rights, null if unauthorized.
|
Throws
|
Exception
|
any exception thrown.
|
Example
public void run(HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
String rights = null;
String authorization = request.getHeader("Authorization");
if(authorization != null)
{
String scheme = DString.extract(authorization, " ", 0);
if(scheme.equals(Constants.DEFAULT_SCHEME))
{
int offset = authorization.indexOf(' ');
String sValue = authorization.substring(offset + 1);
sValue = Codecs.base64Decode(sValue);
String username = DString.extract(sValue, ":", 0);
String password = DString.extract(sValue, ":", 1);
if(password == null)
{
password = "";
}
if(username.equals("admin") && password.equals("admin"))
{
rights = "*";
}
}
}
if(rights == null)
{
response.setHeader("WWW-Authenticate",
"Basic realm=\"default\"");
response.sendError(response.SC_UNAUTHORIZED);
}
return rights;
}
|