Package org.simpleframework.http.parse
Class PrincipalParser
- java.lang.Object
-
- org.simpleframework.common.parse.Parser
-
- org.simpleframework.http.parse.PrincipalParser
-
- All Implemented Interfaces:
Principal
public class PrincipalParser extends org.simpleframework.common.parse.Parser implements Principal
PrincipalParser is a parser class for the HTTP basic authorization header. It decodes thebase64
encoding of the user and password pair.This follows the parsing tree of RFC 2617. The goal of this parser is to decode the
base64
encoding of the user name and password. After the string has been decoded then the user name and password are extracted. This will only parse headers that are from theBasic
authorization scheme. The format of the basic scheme can be found in RFC 2617 and is of the formBasic SP base64-encoding.
- Author:
- Niall Gallagher
-
-
Constructor Summary
Constructors Constructor Description PrincipalParser()
Creates aParser
for the basic authorization scheme.PrincipalParser(java.lang.String header)
Creates aParser
for the basic authorization scheme.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getName()
Gets the users name from the Authorization header value.java.lang.String
getPassword()
Gets the users password parsed from the Authorization header value.protected void
init()
This will initialize theParser
when it is ready to parse a newString
.protected void
parse()
Used to parse the actual header data.
-
-
-
Constructor Detail
-
PrincipalParser
public PrincipalParser()
Creates aParser
for the basic authorization scheme. This allows headers that are of this scheme to be broken into its component parts i.e. user name and password.
-
PrincipalParser
public PrincipalParser(java.lang.String header)
Creates aParser
for the basic authorization scheme. This allows headers that are of this scheme to be broken into its component parts i.e. user name and password. This constructor will parse theString
given as the header.- Parameters:
header
- this is a header value from the basic scheme
-
-
Method Detail
-
getPassword
public java.lang.String getPassword()
Gets the users password parsed from the Authorization header value. If there was not password parsed from the base64 value of the header this returnsnull
- Specified by:
getPassword
in interfacePrincipal
- Returns:
- the password for the user or
null
-
getName
public java.lang.String getName()
Gets the users name from the Authorization header value. This will returnnull
if there is no user name extracted from the base64 header value.
-
parse
protected void parse()
Used to parse the actual header data. This will attempt to read the "Basic" token from the set of characters given, if this is successful then the username and password is extracted.- Specified by:
parse
in classorg.simpleframework.common.parse.Parser
-
init
protected void init()
This will initialize theParser
when it is ready to parse a newString
. This will reset theParser
to a ready state. Theinit
method is invoked by theParser
when theparse
method is invoked.- Specified by:
init
in classorg.simpleframework.common.parse.Parser
-
-