Class AuthBasic
- java.lang.Object
-
- com.github.fmjsjx.libnetty.http.server.middleware.AuthBasic
-
- All Implemented Interfaces:
Middleware,java.util.function.BiFunction<HttpRequestContext,MiddlewareChain,java.util.concurrent.CompletionStage<HttpResult>>
public class AuthBasic extends java.lang.Object implements Middleware
AMiddlewareallows limiting access to resources by validating the user name and password using the "HTTP Basic Authentication" protocol.- Since:
- 1.1
- See Also:
Middleware
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAuthBasic.BasicUserAHttpServer.Userholding the username parsed from the "HTTP Basic Authentication" protocol.
-
Constructor Summary
Constructors Constructor Description AuthBasic(java.util.function.BiPredicate<java.lang.String,java.lang.String> validator, java.lang.String realm)Constructs a newAuthBasicwith the specified validator and realm.AuthBasic(java.util.Map<java.lang.String,java.lang.String> users, java.lang.String realm)Constructs a newAuthBasicwith the specified users and realm.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletionStage<HttpResult>apply(HttpRequestContext ctx, MiddlewareChain next)Apply thisMiddlewareto the givenHttpRequestContext.java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.fmjsjx.libnetty.http.server.middleware.Middleware
close, onServerClosed
-
-
-
-
Constructor Detail
-
AuthBasic
public AuthBasic(java.util.Map<java.lang.String,java.lang.String> users, java.lang.String realm)Constructs a newAuthBasicwith the specified users and realm.- Parameters:
users- a map contains the users' name and their passwordrealm- the realm attribute
-
AuthBasic
public AuthBasic(java.util.function.BiPredicate<java.lang.String,java.lang.String> validator, java.lang.String realm)Constructs a newAuthBasicwith the specified validator and realm.- Parameters:
validator- function to validating the user name and passwordrealm- the realm attribute
-
-
Method Detail
-
apply
public java.util.concurrent.CompletionStage<HttpResult> apply(HttpRequestContext ctx, MiddlewareChain next)
Description copied from interface:MiddlewareApply thisMiddlewareto the givenHttpRequestContext.- Specified by:
applyin interfacejava.util.function.BiFunction<HttpRequestContext,MiddlewareChain,java.util.concurrent.CompletionStage<HttpResult>>- Specified by:
applyin interfaceMiddleware- Parameters:
ctx- theHttpRequestContextobject of the current HTTP requestnext- theMiddlewareChainfor invoking the nextMiddleware- Returns:
- a
CompletionStage<HttpResult>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-