Package org.apache.mina.filter.ssl
Class SslFilter
java.lang.Object
org.apache.mina.core.filterchain.IoFilterAdapter
org.apache.mina.filter.ssl.SslFilter
- All Implemented Interfaces:
IoFilter
A SSL processor which performs flow control of encrypted information on the
filter-chain.
The initial handshake is automatically enabled for "client" sessions once the filter is added to the filter-chain and the session is connected.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.mina.core.filterchain.IoFilter
IoFilter.NextFilter -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanA flag used to tell the filter to start the handshake immediately (in onPostAdd method) alternatively handshake will be started after session is connected (in sessionOpened method) default value is trueprotected String[]The enabled Ciphers.protected String[]The list of enabled SSL/TLS protocols.protected static final ExecutorTask executor for processing handshakesprivate StringEndPoint identification algorithmsprotected static final org.slf4j.LoggerThe loggerprotected booleanA flag set if client authentication is requiredprivate booleanEnables the non-blocking pipelinesprotected static final AttributeKeyReturns the SSL2Handler objectstatic final AttributeKeySSLSession object when the session is secured, otherwise null.protected final SSLContextprotected booleanA flag set if client authentication is requested -
Constructor Summary
ConstructorsConstructorDescriptionSslFilter(SSLContext sslContext) Creates a new SSL filter using the specifiedSSLContext.SslFilter(SSLContext sslContext, boolean autoStart) Creates a new SSL filter using the specifiedSSLContext. -
Method Summary
Modifier and TypeMethodDescriptionprotected SSLEnginecreateEngine(IoSession session, InetSocketAddress addr) Customization handler for creating the enginevoidfilterWrite(IoFilter.NextFilter next, IoSession session, WriteRequest request) FiltersIoSession.write(Object)method invocation.String[]String[]private SslHandlergetSslHandler(IoSession session) Gets the given session's SslHandler.booleanbooleanvoidmessageReceived(IoFilter.NextFilter next, IoSession session, Object message) FiltersIoHandler.messageReceived(IoSession,Object)event.voidmessageSent(IoFilter.NextFilter next, IoSession session, WriteRequest request) FiltersIoHandler.messageSent(IoSession,Object)event.protected voidonClose(IoFilter.NextFilter next, IoSession session, boolean linger) Called when the session is going to be closed.protected voidonConnected(IoFilter.NextFilter next, IoSession session) Internal method for performing post-connect operations; this can be triggered during normal connect event or after the filter is added to the chain.voidonPostAdd(IoFilterChain parent, String name, IoFilter.NextFilter next) Invoked after this filter is added to the specifiedparent.voidonPreAdd(IoFilterChain parent, String name, IoFilter.NextFilter next) Invoked before this filter is added to the specifiedparent.voidonPreRemove(IoFilterChain parent, String name, IoFilter.NextFilter next) Invoked before this filter is removed from the specifiedparent.voidsessionClosed(IoFilter.NextFilter next, IoSession session) FiltersIoHandler.sessionClosed(IoSession)event.voidsessionOpened(IoFilter.NextFilter next, IoSession session) FiltersIoHandler.sessionOpened(IoSession)event.voidsetEnabledCipherSuites(String... enabledCipherSuites) Sets the list of cipher suites to be enabled whenSSLEngineis initialized.voidsetEnabledProtocols(String... enabledProtocols) Sets the list of protocols to be enabled whenSSLEngineis initialized.voidsetEndpointIdentificationAlgorithm(String identificationAlgorithm) Sets the endpoint identification algorithm to be used whenSSLEngineis initialized.voidsetNeedClientAuth(boolean needClientAuth) Configures the engine to require client authentication.voidsetUseNonBlockingPipeline(boolean enable) Configures the use of the Non Blocking SSL processor.voidsetWantClientAuth(boolean wantClientAuth) Configures the engine to request client authentication.Methods inherited from class org.apache.mina.core.filterchain.IoFilterAdapter
destroy, event, exceptionCaught, filterClose, init, inputClosed, onPostRemove, sessionCreated, sessionIdle, toString
-
Field Details
-
SSL_SECURED
SSLSession object when the session is secured, otherwise null. -
SSL_HANDLER
Returns the SSL2Handler object -
LOGGER
protected static final org.slf4j.Logger LOGGERThe logger -
EXECUTOR
Task executor for processing handshakes -
sslContext
-
autoStart
private final boolean autoStartA flag used to tell the filter to start the handshake immediately (in onPostAdd method) alternatively handshake will be started after session is connected (in sessionOpened method) default value is true -
nonBlockingPipeline
private boolean nonBlockingPipelineEnables the non-blocking pipelines -
needClientAuth
protected boolean needClientAuthA flag set if client authentication is required -
wantClientAuth
protected boolean wantClientAuthA flag set if client authentication is requested -
enabledCipherSuites
The enabled Ciphers. -
enabledProtocols
The list of enabled SSL/TLS protocols. Must be an array of String, containing:- SSLv2Hello
- SSLv3
- TLSv1.1 or TLSv1
- TLSv1.2
- TLSv1.3
- NONE
-
identificationAlgorithm
EndPoint identification algorithms
-
-
Constructor Details
-
SslFilter
Creates a new SSL filter using the specifiedSSLContext.- Parameters:
sslContext- The SSLContext to use
-
SslFilter
Creates a new SSL filter using the specifiedSSLContext. If theautostartflag is set totrue, the handshake will start immediately after the filter has been added to the chain.- Parameters:
sslContext- The SSLContext to useautoStart- The flag used to tell the filter to start the handshake immediately
-
-
Method Details
-
setUseNonBlockingPipeline
public void setUseNonBlockingPipeline(boolean enable) Configures the use of the Non Blocking SSL processor. This is experimental.- Parameters:
enable-trueif the non blocking SSL processor is enabled
-
isNeedClientAuth
public boolean isNeedClientAuth()- Returns:
trueif the engine will require client authentication. This option is only useful to engines in the server mode.
-
setNeedClientAuth
public void setNeedClientAuth(boolean needClientAuth) Configures the engine to require client authentication. This option is only useful for engines in the server mode.- Parameters:
needClientAuth- A flag set when client authentication is required
-
isWantClientAuth
public boolean isWantClientAuth()- Returns:
trueif the engine will request client authentication. This option is only useful to engines in the server mode.
-
setWantClientAuth
public void setWantClientAuth(boolean wantClientAuth) Configures the engine to request client authentication. This option is only useful for engines in the server mode.- Parameters:
wantClientAuth- A flag set when client authentication is requested
-
getEnabledCipherSuites
-
setEnabledCipherSuites
Sets the list of cipher suites to be enabled whenSSLEngineis initialized.- Parameters:
enabledCipherSuites- The list of enabled Cipher.nullmeans 'useSSLEngine's default.'
-
getEndpointIdentificationAlgorithm
-
setEndpointIdentificationAlgorithm
Sets the endpoint identification algorithm to be used whenSSLEngineis initialized.- Parameters:
identificationAlgorithm-nullmeans 'useSSLEngine's default.'
-
getEnabledProtocols
-
getSslHandler
Gets the given session's SslHandler.- Parameters:
session- An IoSession to query.- Returns:
- the given session's SslHandler.
-
setEnabledProtocols
Sets the list of protocols to be enabled whenSSLEngineis initialized.- Parameters:
enabledProtocols- The list of enabled SSL/TLS protocols.nullmeans 'useSSLEngine's default.'
-
onPreAdd
Invoked before this filter is added to the specifiedparent. Please note that this method can be invoked more than once if this filter is added to more than one parents. This method is not invoked beforeIoFilter.init()is invoked.- Specified by:
onPreAddin interfaceIoFilter- Overrides:
onPreAddin classIoFilterAdapter- Parameters:
parent- the parent who called this methodname- the name assigned to this filternext- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.- Throws:
Exception- If an error occurred while processing the event
-
onPostAdd
Invoked after this filter is added to the specifiedparent. Please note that this method can be invoked more than once if this filter is added to more than one parents. This method is not invoked beforeIoFilter.init()is invoked.- Specified by:
onPostAddin interfaceIoFilter- Overrides:
onPostAddin classIoFilterAdapter- Parameters:
parent- the parent who called this methodname- the name assigned to this filternext- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.- Throws:
Exception- If an error occurred while processing the event
-
onPreRemove
public void onPreRemove(IoFilterChain parent, String name, IoFilter.NextFilter next) throws Exception Invoked before this filter is removed from the specifiedparent. Please note that this method can be invoked more than once if this filter is removed from more than one parents. This method is always invoked beforeIoFilter.destroy()is invoked.- Specified by:
onPreRemovein interfaceIoFilter- Overrides:
onPreRemovein classIoFilterAdapter- Parameters:
parent- the parent who called this methodname- the name assigned to this filternext- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.- Throws:
Exception- If an error occurred while processing the event
-
onConnected
Internal method for performing post-connect operations; this can be triggered during normal connect event or after the filter is added to the chain.- Parameters:
next- The nextFilter to call in the chainsession- The session instance- Throws:
SSLException- Any exception thrown by the SslHandler closing
-
onClose
protected void onClose(IoFilter.NextFilter next, IoSession session, boolean linger) throws SSLException Called when the session is going to be closed. We must shutdown the SslHandler instance.- Parameters:
next- The nextFilter to call in the chainsession- The session instancelinger- if true, write any queued messages before closing- Throws:
SSLException- Any exception thrown by the SslHandler closing
-
createEngine
Customization handler for creating the engine- Parameters:
session- source sessionaddr- socket address used for fast reconnect- Returns:
- an SSLEngine
-
sessionOpened
FiltersIoHandler.sessionOpened(IoSession)event.- Specified by:
sessionOpenedin interfaceIoFilter- Overrides:
sessionOpenedin classIoFilterAdapter- Parameters:
next- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this event- Throws:
Exception- If an error occurred while processing the event
-
sessionClosed
FiltersIoHandler.sessionClosed(IoSession)event.- Specified by:
sessionClosedin interfaceIoFilter- Overrides:
sessionClosedin classIoFilterAdapter- Parameters:
next- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this event- Throws:
Exception- If an error occurred while processing the event
-
messageReceived
public void messageReceived(IoFilter.NextFilter next, IoSession session, Object message) throws Exception FiltersIoHandler.messageReceived(IoSession,Object)event.- Specified by:
messageReceivedin interfaceIoFilter- Overrides:
messageReceivedin classIoFilterAdapter- Parameters:
next- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this eventmessage- The received message- Throws:
Exception- If an error occurred while processing the event
-
messageSent
public void messageSent(IoFilter.NextFilter next, IoSession session, WriteRequest request) throws Exception FiltersIoHandler.messageSent(IoSession,Object)event.- Specified by:
messageSentin interfaceIoFilter- Overrides:
messageSentin classIoFilterAdapter- Parameters:
next- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this eventrequest- TheWriteRequestthat contains the sent message- Throws:
Exception- If an error occurred while processing the event
-
filterWrite
public void filterWrite(IoFilter.NextFilter next, IoSession session, WriteRequest request) throws Exception FiltersIoSession.write(Object)method invocation.- Specified by:
filterWritein interfaceIoFilter- Overrides:
filterWritein classIoFilterAdapter- Parameters:
next- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has to process this invocationrequest- TheWriteRequestto process- Throws:
Exception- If an error occurred while processing the event
-