Package com.gmt2001.httpwsserver.auth
Class HttpBasicAuthenticationHandler
java.lang.Object
com.gmt2001.httpwsserver.auth.HttpBasicAuthenticationHandler
- All Implemented Interfaces:
HttpAuthenticationHandler
Provides a
HttpAuthenticationHandler
that implements HTTP Basic authentication, as well as allowing the same format to be provided in a
cookie- Author:
- gmt2001
-
Constructor Summary
ConstructorsConstructorDescriptionHttpBasicAuthenticationHandler
(String realm, String user, String pass, String loginUri) ConstructorHttpBasicAuthenticationHandler
(String realm, String user, String pass, String loginUri, boolean allowPaneluser) Constructor -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if the givenFullHttpRequest
has the correct header with valid credentialsboolean
static String
getAuthorizationString
(HttpHeaders headers) int
hashCode()
void
Invalidates the authentication of the specifiedChannelHandlerContext
, if supported by the authentication handlerboolean
isAuthorized
(ChannelHandlerContext ctx, FullHttpRequest req) Checks if the givenFullHttpRequest
is a valid authentication request, or if the underlyingChannel
has already been authenticated When returningfalse
, this method MUST NOT send a response to the clientboolean
isAuthorized
(ChannelHandlerContext ctx, HttpHeaders headers) Checks if the givenHttpHeaders
contain a valid authorization, or if the underlyingChannel
has already been authenticated When returningfalse
, this method MUST NOT send a response to the clientboolean
isAuthorized
(String user, String pass) Checks if the given username and password is a valid When returningfalse
, this method MUST NOT send a response to the client
-
Constructor Details
-
HttpBasicAuthenticationHandler
Constructor- Parameters:
realm
- The realm to present to the useruser
- The username required for valid authenticationpass
- The password required for valid authenticationloginUri
- The login page URI- Throws:
IllegalArgumentException
- Ifrealm
contains any double quotes oruser
contains any colons
-
HttpBasicAuthenticationHandler
public HttpBasicAuthenticationHandler(String realm, String user, String pass, String loginUri, boolean allowPaneluser) Constructor- Parameters:
realm
- The realm to present to the useruser
- The username required for valid authenticationpass
- The password required for valid authenticationloginUri
- The login page URIallowPanelUser
- Whether this instance is allow to authenticate headers againstPanelUser
- Throws:
IllegalArgumentException
- Ifrealm
contains any double quotes oruser
contains any colons
-
-
Method Details
-
checkAuthorization
Checks if the givenFullHttpRequest
has the correct header with valid credentials- Specified by:
checkAuthorization
in interfaceHttpAuthenticationHandler
- Parameters:
ctx
- TheChannelHandlerContext
of the sessionreq
- TheFullHttpRequest
to check- Returns:
- , this method will also reply with
401 Unauthorized
and then close the channel
-
invalidateAuthorization
Description copied from interface:HttpAuthenticationHandler
Invalidates the authentication of the specifiedChannelHandlerContext
, if supported by the authentication handler- Specified by:
invalidateAuthorization
in interfaceHttpAuthenticationHandler
- Parameters:
ctx
- TheChannelHandlerContext
of the sessionreq
- TheFullHttpRequest
-
isAuthorized
Description copied from interface:HttpAuthenticationHandler
Checks if the givenFullHttpRequest
is a valid authentication request, or if the underlyingChannel
has already been authenticated When returningfalse
, this method MUST NOT send a response to the client- Specified by:
isAuthorized
in interfaceHttpAuthenticationHandler
- Parameters:
ctx
- TheChannelHandlerContext
of the sessionreq
- TheFullHttpRequest
to check- Returns:
- otherwise
-
isAuthorized
Description copied from interface:HttpAuthenticationHandler
Checks if the given username and password is a valid When returningfalse
, this method MUST NOT send a response to the client- Specified by:
isAuthorized
in interfaceHttpAuthenticationHandler
- Parameters:
user
- The usernamepass
- The password- Returns:
- otherwise
-
isAuthorized
Description copied from interface:HttpAuthenticationHandler
Checks if the givenHttpHeaders
contain a valid authorization, or if the underlyingChannel
has already been authenticated When returningfalse
, this method MUST NOT send a response to the client- Specified by:
isAuthorized
in interfaceHttpAuthenticationHandler
- Parameters:
ctx
- TheChannelHandlerContext
of the sessionheaders
- TheHttpHeaders
to check- Returns:
- otherwise
-
getAuthorizationString
- Parameters:
headers
- TheHttpHeaders
to check- Returns:
- The authorization string, still encoded with Base64, giving preference to
Authorization Basic
;null
if neither is found
-
hashCode
public int hashCode() -
equals
-