diff --git a/mifosng-individual-lending-app/build.gradle b/mifosng-individual-lending-app/build.gradle index 28931c908..a5583cddd 100644 --- a/mifosng-individual-lending-app/build.gradle +++ b/mifosng-individual-lending-app/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath 'bmuschko:gradle-tomcat-plugin:0.9.1' + classpath 'bmuschko:gradle-tomcat-plugin:0.9.2' } } @@ -53,7 +53,7 @@ configurations { dependencies { - def tomcatVersion = '7.0.26' + def tomcatVersion = '7.0.27' tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}" tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") { @@ -97,6 +97,9 @@ dependencies { } [tomcatRun, tomcatRunWar, tomcatStop]*.with { + configFile = file('src/test/resources/META-INF/context.xml') httpPort = 8085 + httpsPort = 8444 stopPort = 8082 + enableSSL = true; } \ No newline at end of file diff --git a/mifosng-individual-lending-app/src/main/java/org/mifosng/configuration/InMemoryApplicationConfigurationService.java b/mifosng-individual-lending-app/src/main/java/org/mifosng/configuration/InMemoryApplicationConfigurationService.java index 8d3d2b060..294287a3a 100644 --- a/mifosng-individual-lending-app/src/main/java/org/mifosng/configuration/InMemoryApplicationConfigurationService.java +++ b/mifosng-individual-lending-app/src/main/java/org/mifosng/configuration/InMemoryApplicationConfigurationService.java @@ -8,7 +8,7 @@ import org.springframework.stereotype.Service; @Service public class InMemoryApplicationConfigurationService implements ApplicationConfigurationService { - private String platformApiUrl = "http://localhost:8080/mifosng-provider/api/v1/"; + private String platformApiUrl = "https://localhost:8443/mifosng-provider/api/v1/"; public InMemoryApplicationConfigurationService() { // diff --git a/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/infrastructure/ApiDelegatingAuthenticationProvider.java b/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/infrastructure/ApiDelegatingAuthenticationProvider.java index 82bab0f7b..00f0fdcab 100644 --- a/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/infrastructure/ApiDelegatingAuthenticationProvider.java +++ b/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/infrastructure/ApiDelegatingAuthenticationProvider.java @@ -20,7 +20,6 @@ import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.RestTemplate; /** * A {@link AbstractUserDetailsAuthenticationProvider} which is responsible for delegating authentication to the mifos platform API. @@ -30,11 +29,11 @@ import org.springframework.web.client.RestTemplate; */ public class ApiDelegatingAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider { - private final RestTemplate restTemplate; + private final SslRestTemplate restTemplate; private final ApplicationConfigurationService applicationConfigurationService; @Autowired - public ApiDelegatingAuthenticationProvider(final RestTemplate restTemplate, final ApplicationConfigurationService applicationConfigurationService) { + public ApiDelegatingAuthenticationProvider(final SslRestTemplate restTemplate, final ApplicationConfigurationService applicationConfigurationService) { this.restTemplate = restTemplate; this.applicationConfigurationService = applicationConfigurationService; } diff --git a/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/infrastructure/CustomClientHttpRequestFactory.java b/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/infrastructure/CustomClientHttpRequestFactory.java new file mode 100644 index 000000000..21ddd3a57 --- /dev/null +++ b/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/infrastructure/CustomClientHttpRequestFactory.java @@ -0,0 +1,71 @@ +package org.mifosng.ui.infrastructure; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.security.SecureRandom; +import java.security.cert.CertificateException; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.stereotype.Component; + +/** + * + */ +@Component +public class CustomClientHttpRequestFactory extends SimpleClientHttpRequestFactory { + + @Override + protected void prepareConnection(HttpURLConnection connection, + String httpMethod) throws IOException { + + if (connection instanceof HttpsURLConnection) { + disableCertificateValidation(); + HttpsURLConnection httpsConnection = (HttpsURLConnection) connection; + httpsConnection.setHostnameVerifier(new NullHostnameVerifier()); + } + super.prepareConnection(connection, httpMethod); + } + + private class NullHostnameVerifier implements HostnameVerifier { + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + } + + public static void disableCertificateValidation() { + + X509TrustManager trustManager = new X509TrustManager() { + @Override + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + + @Override + public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { + } + + @Override + public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { + } + }; + + TrustManager[] trustAllCerts = new TrustManager[1]; + trustAllCerts[0] = trustManager; + + try { + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + } catch (Exception e) { + } + } + +} diff --git a/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/infrastructure/SslRestTemplate.java b/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/infrastructure/SslRestTemplate.java new file mode 100644 index 000000000..71d5b73ca --- /dev/null +++ b/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/infrastructure/SslRestTemplate.java @@ -0,0 +1,17 @@ +package org.mifosng.ui.infrastructure; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +/** + * + */ +@Component +public class SslRestTemplate extends RestTemplate { + + @Autowired + public SslRestTemplate(final CustomClientHttpRequestFactory simpleClientHttpRequestFactory) { + super(simpleClientHttpRequestFactory); + } +} \ No newline at end of file diff --git a/mifosng-individual-lending-app/src/main/resources/META-INF/spring/appContext.xml b/mifosng-individual-lending-app/src/main/resources/META-INF/spring/appContext.xml index 25f2fa460..02e254e77 100644 --- a/mifosng-individual-lending-app/src/main/resources/META-INF/spring/appContext.xml +++ b/mifosng-individual-lending-app/src/main/resources/META-INF/spring/appContext.xml @@ -16,7 +16,5 @@ - - \ No newline at end of file diff --git a/mifosng-individual-lending-app/src/main/resources/META-INF/spring/securityContext.xml b/mifosng-individual-lending-app/src/main/resources/META-INF/spring/securityContext.xml index 83d40a7ec..c949fa496 100644 --- a/mifosng-individual-lending-app/src/main/resources/META-INF/spring/securityContext.xml +++ b/mifosng-individual-lending-app/src/main/resources/META-INF/spring/securityContext.xml @@ -13,7 +13,6 @@ - diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/login.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/login.jsp index f123cacf4..fa1af9e55 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/login.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/login.jsp @@ -1,73 +1,43 @@ <%@ page session="true" %> -<%@ page import="org.springframework.security.core.AuthenticationException" %> -<%@ page import="org.springframework.security.web.WebAttributes" %> +<%@ page trimDirectiveWhitespaces="true" %> +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> - - +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> + - - + + +
 
+ +
+ + + + - - - - \ No newline at end of file + \ No newline at end of file diff --git a/mifosng-individual-lending-app/src/test/resources/META-INF/context.xml b/mifosng-individual-lending-app/src/test/resources/META-INF/context.xml new file mode 100644 index 000000000..b23ef6106 --- /dev/null +++ b/mifosng-individual-lending-app/src/test/resources/META-INF/context.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/mifosng-provider/build.gradle b/mifosng-provider/build.gradle index b07eaf3b9..c618470a9 100644 --- a/mifosng-provider/build.gradle +++ b/mifosng-provider/build.gradle @@ -9,9 +9,10 @@ buildscript { } dependencies { - classpath 'bmuschko:gradle-tomcat-plugin:0.9.1' + classpath 'bmuschko:gradle-tomcat-plugin:0.9.2' } } + apply plugin: 'war' apply plugin: 'eclipse' apply plugin: 'tomcat' @@ -60,7 +61,7 @@ configurations { } dependencies { - def tomcatVersion = '7.0.26' + def tomcatVersion = '7.0.27' tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}" tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") { @@ -125,5 +126,7 @@ dependencies { [tomcatRun, tomcatRunWar, tomcatStop]*.with { configFile = file('src/test/resources/META-INF/context.xml') httpPort = 8080 + httpsPort = 8443 stopPort = 8081 + enableSSL = true } \ No newline at end of file diff --git a/mifosng-provider/src/main/resources/META-INF/spring/securityContext.xml b/mifosng-provider/src/main/resources/META-INF/spring/securityContext.xml index 43f4cfaf1..e643b64f6 100644 --- a/mifosng-provider/src/main/resources/META-INF/spring/securityContext.xml +++ b/mifosng-provider/src/main/resources/META-INF/spring/securityContext.xml @@ -7,14 +7,13 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> - - - - - - - + + + + + + diff --git a/mifosng-provider/src/main/webapp/WEB-INF/views/access_confirmation.jsp b/mifosng-provider/src/main/webapp/WEB-INF/views/access_confirmation.jsp deleted file mode 100644 index 09cc5e8ba..000000000 --- a/mifosng-provider/src/main/webapp/WEB-INF/views/access_confirmation.jsp +++ /dev/null @@ -1,44 +0,0 @@ -<%@ page import="org.springframework.security.core.AuthenticationException" %> -<%@ page import="org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter" %> -<%@ taglib prefix="authz" uri="http://www.springframework.org/security/tags" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> -<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> - - - - - - MifosNg Platform: Access Confirmation - - - - -

MifosNg

- -
- - -
-

Woops!

- -

Access could not be granted. (<%= ((AuthenticationException) session.getAttribute(AbstractAuthenticationProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY)).getMessage() %>)

-
-
- - -

Please Confirm

- -

You hereby authorize "" to access the following resource:

- -
    -
  • —
  • -
- -
" method="POST"> - " type="hidden"/> - -
-
- - \ No newline at end of file diff --git a/mifosng-provider/src/main/webapp/WEB-INF/views/index.jsp b/mifosng-provider/src/main/webapp/WEB-INF/views/index.jsp deleted file mode 100644 index 6cfb032b8..000000000 --- a/mifosng-provider/src/main/webapp/WEB-INF/views/index.jsp +++ /dev/null @@ -1,19 +0,0 @@ -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> -<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> - - - - - MifosNg Platform - - - -

Successful Authentication

- -
-

There are no UI capabilities on MifosNg Platform. You must use a suitable consumer (client) application to use our platform services.

-
- - - \ No newline at end of file diff --git a/mifosng-provider/src/main/webapp/WEB-INF/views/login.jsp b/mifosng-provider/src/main/webapp/WEB-INF/views/login.jsp deleted file mode 100644 index f123cacf4..000000000 --- a/mifosng-provider/src/main/webapp/WEB-INF/views/login.jsp +++ /dev/null @@ -1,73 +0,0 @@ -<%@ page session="true" %> -<%@ page import="org.springframework.security.core.AuthenticationException" %> -<%@ page import="org.springframework.security.web.WebAttributes" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> - - - - - - - - - - -
-
-
 
-
-
- - - - - \ No newline at end of file