Class PrincipalParser
- All Implemented Interfaces:
Principal
base64
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
the Basic
authorization scheme. The format of the basic
scheme can be found in RFC 2617 and is of the form
Basic SP base64-encoding.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
Keeps thebytes
used for decoding base64.private ParseBuffer
Keeps the characters consumed for the password token.private int
Tracks the read offset for the buffer.private int
Tracks the ready offset for the four buffer.private ParseBuffer
Keeps the characters consumed for the user name token.private int
Tracks the write offset for the buffer. -
Constructor Summary
ConstructorsConstructorDescriptionCreates aParser
for the basic authorization scheme.PrincipalParser
(String header) Creates aParser
for the basic authorization scheme. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
decode()
This is used to remove decode thebase64
encoding of the user name and password.private char
first
(byte[] four) This is used to extract thebyte
from the set of fourbytes
given.getName()
Gets the users name from the Authorization header value.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
.private void
pack()
This is used to remove all whitespace characters from theString
excluding the whitespace within literals.protected void
parse()
Used to parse the actual header data.private void
password()
Extracts the password from the buffer.private char
second
(byte[] four) This is used to extract thebyte
from the set of fourbytes
given.private boolean
text
(char c) This is used to determine wheather or not a character is aTEXT
character according to the HTTP specification, that is RFC 2616 specifies aTEXT
character as one that is any octet except those less than 32 and not 127.private char
third
(byte[] four) This is used to extract thebyte
from the set of fourbytes
given.private int
translate
(int octet) This uses a basic translation from thebyte
character to thebyte
number.private void
userid()
Extracts the user name from the buffer.private void
userpass()
Extracts the name and password of the user from thename : password
pair that was given.
-
Field Details
-
password
Keeps the characters consumed for the password token. -
user
Keeps the characters consumed for the user name token. -
four
private byte[] fourKeeps thebytes
used for decoding base64. -
write
private int writeTracks the write offset for the buffer. -
ready
private int readyTracks the ready offset for the four buffer. -
read
private int readTracks the read offset for the buffer.
-
-
Constructor Details
-
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
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 Details
-
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
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. -
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. -
pack
private void pack()This is used to remove all whitespace characters from theString
excluding the whitespace within literals. The definition of a literal can be found in RFC 2616.The definition of a literal for RFC 2616 is anything between 2 quotes but excuding quotes that are prefixed with the backward slash character.
-
userpass
private void userpass()Extracts the name and password of the user from thename : password
pair that was given. This will take all data up to the first occurence of a ':' character as the users name and all data after the colon as the users password. -
userid
private void userid()Extracts the user name from the buffer. This will read up to the first occurence of a colon, ':', character as the user name. For the BNF syntax of this see RFC 2617. -
password
private void password()Extracts the password from the buffer. This will all characters from the current offset to the first non text character as the password. For the BNF syntax of this see RFC 2617. -
decode
private void decode()This is used to remove decode thebase64
encoding of the user name and password. This uses a standartbase64
decoding scheme.For information on the decoding scheme used for
base64
see the RFC 2045 on MIME, Multipurpose Internet Mail Extensions. -
translate
private int translate(int octet) This uses a basic translation from thebyte
character to thebyte
number.The table for translation the data can be found in RFC 2045 on MIME, Multipurpose Internet Mail Extensions.
- Parameters:
octet
- this is the octet ttat is to be translated- Returns:
- this returns the translated octet
-
first
private char first(byte[] four) This is used to extract thebyte
from the set of fourbytes
given. This method is used to isolate the correct bits that corrospond to an actual character withing thebase64
data.- Parameters:
four
- this is the fourbytes
that the character is to be extracted from- Returns:
- this returns the character extracted
-
second
private char second(byte[] four) This is used to extract thebyte
from the set of fourbytes
given. This method is used to isolate the correct bits that corrospond to an actual character withing thebase64
data.- Parameters:
four
- this is the fourbytes
that the character is to be extracted from- Returns:
- this returns the character extracted
-
third
private char third(byte[] four) This is used to extract thebyte
from the set of fourbytes
given. This method is used to isolate the correct bits that corrospond to an actual character withing thebase64
data.- Parameters:
four
- this is the fourbytes
that the character is to be extracted from- Returns:
- this returns the character extracted
-
text
private boolean text(char c) This is used to determine wheather or not a character is aTEXT
character according to the HTTP specification, that is RFC 2616 specifies aTEXT
character as one that is any octet except those less than 32 and not 127.- Parameters:
c
- this is the character that is to be determined- Returns:
- this returns true if the character is a
TEXT
-