Package org.zeromq
Class ZAuth
- java.lang.Object
-
- org.zeromq.ZAuth
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class ZAuth extends java.lang.Object implements java.io.Closeable
A ZAuth actor takes over authentication for all incoming connections in its context. You can whitelist or blacklist peers based on IP address, and define policies for securing PLAIN, CURVE, and GSSAPI connections.
Note that libzmq provides four levels of security: default NULL (which ZAuth does not see), and authenticated NULL, PLAIN, and CURVE, which ZAuth can see.
Based on zauth.c in czmq
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ZAuth.Auth
private static class
ZAuth.AuthActor
AuthActor is the backend actor which we talk to over a pipe.static class
ZAuth.SimpleCurveAuth
static class
ZAuth.SimpleNullAuth
static class
ZAuth.SimplePlainAuth
static class
ZAuth.ZapReply
static class
ZAuth.ZapRequest
A small class for working with ZAP requests and replies.
-
Field Summary
Fields Modifier and Type Field Description private ZAgent
agent
private static java.lang.String
ALLOW
static java.lang.String
CURVE_ALLOW_ANY
private static java.lang.String
DENY
private ZStar.Exit
exit
private ZAgent
replies
private static java.lang.String
REPLIES
private boolean
repliesEnabled
private static java.lang.String
TERMINATE
private static java.lang.String
VERBOSE
private static java.lang.String
ZAP_VERSION
-
Constructor Summary
Constructors Constructor Description ZAuth(ZContext ctx)
Install authentication for the specified context.ZAuth(ZContext ctx, java.lang.String actorName)
ZAuth(ZContext ctx, java.lang.String actorName, java.util.Map<java.lang.String,ZAuth.Auth> auths)
ZAuth(ZContext ctx, ZCertStore.Fingerprinter fingerprinter)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ZAuth
allow(java.lang.String address)
Allow (whitelist) a single IP address.void
close()
Destructor.ZAuth
configureCurve(java.lang.String location)
Configure CURVE authenticationZAuth
configurePlain(java.lang.String domain, java.lang.String filename)
Configure PLAIN authentication for a given domain.private static java.util.Map<java.lang.String,ZAuth.Auth>
curveVariant(ZCertStore.Fingerprinter fingerprinter)
ZAuth
deny(java.lang.String address)
Deny (blacklist) a single IP address.void
destroy()
Destructor.private static java.util.Map<java.lang.String,ZAuth.Auth>
makeSimpleAuths()
ZAuth.ZapReply
nextReply()
Retrieves the next ZAP reply.ZAuth.ZapReply
nextReply(boolean wait)
Retrieves the next ZAP reply.ZAuth.ZapReply
nextReply(int timeout)
Retrieves the next ZAP reply.ZAuth
replies(boolean enable)
protected ZAuth
send(java.lang.String command, java.lang.String... datas)
ZAuth
setVerbose(boolean verbose)
Enable verbose tracing of commands and activityZAuth
verbose(boolean verbose)
-
-
-
Field Detail
-
ZAP_VERSION
private static final java.lang.String ZAP_VERSION
- See Also:
- Constant Field Values
-
CURVE_ALLOW_ANY
public static final java.lang.String CURVE_ALLOW_ANY
- See Also:
- Constant Field Values
-
VERBOSE
private static final java.lang.String VERBOSE
- See Also:
- Constant Field Values
-
REPLIES
private static final java.lang.String REPLIES
- See Also:
- Constant Field Values
-
ALLOW
private static final java.lang.String ALLOW
- See Also:
- Constant Field Values
-
DENY
private static final java.lang.String DENY
- See Also:
- Constant Field Values
-
TERMINATE
private static final java.lang.String TERMINATE
- See Also:
- Constant Field Values
-
agent
private final ZAgent agent
-
exit
private final ZStar.Exit exit
-
replies
private final ZAgent replies
-
repliesEnabled
private boolean repliesEnabled
-
-
Constructor Detail
-
ZAuth
public ZAuth(ZContext ctx)
Install authentication for the specified context. Note that until you add policies, all incoming NULL connections are allowed (classic ZeroMQ behavior), and all PLAIN and CURVE connections are denied.- Parameters:
ctx
-
-
ZAuth
public ZAuth(ZContext ctx, ZCertStore.Fingerprinter fingerprinter)
-
ZAuth
public ZAuth(ZContext ctx, java.lang.String actorName)
-
ZAuth
public ZAuth(ZContext ctx, java.lang.String actorName, java.util.Map<java.lang.String,ZAuth.Auth> auths)
-
-
Method Detail
-
makeSimpleAuths
private static java.util.Map<java.lang.String,ZAuth.Auth> makeSimpleAuths()
-
curveVariant
private static java.util.Map<java.lang.String,ZAuth.Auth> curveVariant(ZCertStore.Fingerprinter fingerprinter)
-
setVerbose
public ZAuth setVerbose(boolean verbose)
Enable verbose tracing of commands and activity- Parameters:
verbose
-
-
verbose
public ZAuth verbose(boolean verbose)
-
allow
public ZAuth allow(java.lang.String address)
Allow (whitelist) a single IP address. For NULL, all clients from this address will be accepted. For PLAIN and CURVE, they will be allowed to continue with authentication. You can call this method multiple times to whitelist multiple IP addresses. If you whitelist a single address, any non-whitelisted addresses are treated as blacklisted.- Parameters:
address
-
-
deny
public ZAuth deny(java.lang.String address)
Deny (blacklist) a single IP address. For all security mechanisms, this rejects the connection without any further authentication. Use either a whitelist, or a blacklist, not not both. If you define both a whitelist and a blacklist, only the whitelist takes effect.- Parameters:
address
-
-
configurePlain
public ZAuth configurePlain(java.lang.String domain, java.lang.String filename)
Configure PLAIN authentication for a given domain. PLAIN authentication uses a plain-text password file. To cover all domains, use "*". You can modify the password file at any time; it is reloaded automatically.- Parameters:
domain
-filename
-
-
configureCurve
public ZAuth configureCurve(java.lang.String location)
Configure CURVE authentication- Parameters:
location
- Can be ZAuth.CURVE_ALLOW_ANY or a directory with public-keys that will be accepted
-
replies
public ZAuth replies(boolean enable)
-
nextReply
public ZAuth.ZapReply nextReply()
Retrieves the next ZAP reply.- Returns:
- the next reply or null if the actor is closed.
-
nextReply
public ZAuth.ZapReply nextReply(boolean wait)
Retrieves the next ZAP reply.- Parameters:
wait
- true to wait for the next reply, false to immediately return if there is no next reply.- Returns:
- the next reply or null if the actor is closed or if there is no next reply yet.
-
nextReply
public ZAuth.ZapReply nextReply(int timeout)
Retrieves the next ZAP reply.- Parameters:
timeout
- the timeout in milliseconds to wait for a reply before giving up and returning null.- Returns:
- the next reply or null if the actor is closed or if there is no next reply after the elapsed timeout.
-
close
public void close() throws java.io.IOException
Destructor.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
destroy
public void destroy()
Destructor.
-
send
protected ZAuth send(java.lang.String command, java.lang.String... datas)
-
-