%JAVA_HOME%/bin
and launch keytool from there. For MS Windows, the command will look something like this: keytool -genkey -alias ContactManager -keyalg RSA -keystore c:/contactmanager.keystore
alias
- unique key identifierkeyalg
- generation algorithm. Possible RSA, DSA, DES valueskeystore
- file path%CATALINA_HOME%/conf/server.xml
and find the commented out piece <!-- Define a SSL HTTP/1.1 Connector on port 8443 This connector uses the JSSE configuration, when using APR, the connector should be using the OpenSSL style configuration described in the APR documentation --> <!-- <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" /> -->
<Connector port="8443" SSLEnabled="true" protocol="HTTP/1.1" maxThreads="150" scheme="https" secure="true" keystoreFile="c:\contactmanager.keystore" keystorePass="password" sslProtocol="TLS" />
keystorePass
- the password that we entered when generating the key. Yes, it is stored in clear form. There are ways to solve this problem, but for now let's leave it that way. Actually everything can be run. Oops ... INFO: Initializing ProtocolHandler ["http-apr-8080"] 28, 2013 11:43:04 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-apr-8443"] 28, 2013 11:43:04 AM org.apache.coyote.AbstractProtocol init SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-apr-8443"] java.lang.Exception: Connector attribute SSLCertificateFile must be defined when using SSL with APR at org.apache.tomcat.util.net.AprEndpoint.bind(AprEndpoint.java:507) ...
protocol="HTTP/1.1"
needs to be replaced with protocol="org.apache.coyote.http11.Http11Protocol"
. We start, now everything is in order. ... 28, 2013 11:56:41 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-apr-8080"] 28, 2013 11:56:41 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-bio-8443"] 28, 2013 11:56:41 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["ajp-apr-8009"] 28, 2013 11:56:41 AM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 1909 ms ...
requires-channel="https"
must be added to each of the critical URLs of the web service. It will look like this: <intercept-url pattern="/ws/index*" access="hasAnyRole('ROLE_USER','ROLE_ANONYMOUS')" requires-channel="https"/> <intercept-url pattern="/ws/add*" access="hasRole('ROLE_USER')" requires-channel="https"/> <intercept-url pattern="/ws/delete/*" access="hasRole('ROLE_ADMIN') " requires-channel="https"/>
/ws/index
for HTTPS
, so we index_user1()
try the index_user1()
test. Error, which, however, is expected. The question is what kind of error and how to fix it. JUnit swears at the response curve com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input at [Source: java.io.StringReader@1841d1d3; line: 1, column: 1]
... MockHttpServletResponse: Status = 302 Error message = null Headers = {Location=[https://localhost/ws/index]} Content type = null Body = Forwarded URL = null Redirected URL = https://localhost/ws/index Cookies = []
/** * Set the secure property of the {@link ServletRequest} indicating use of a * secure channel, such as HTTPS. * * @param secure whether the request is using a secure channel */ public MockHttpServletRequestBuilder secure(boolean secure){ this.secure = secure; return this; }
def result = mockMvc.perform(MockMvcRequestBuilders.get("/ws/index") .secure(true) // <--------- HTTPS .with(SecurityRequestPostProcessors.userDetailsService(USER1))) .andDo(MockMvcResultHandlers.print()) .andReturn()
Source: https://habr.com/ru/post/174513/
All Articles