add https support for platform available at localhost:8443 by default when running from command line.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
+1
-1
@@ -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() {
|
||||
//
|
||||
|
||||
+2
-3
@@ -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;
|
||||
}
|
||||
|
||||
+71
@@ -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) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+17
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,5 @@
|
||||
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" />
|
||||
</context:component-scan>
|
||||
|
||||
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate" />
|
||||
|
||||
<import resource="securityContext.xml" />
|
||||
</beans>
|
||||
@@ -13,7 +13,6 @@
|
||||
<http use-expressions="true" pattern="/**" create-session="always">
|
||||
<intercept-url pattern="/**" access="isFullyAuthenticated()" />
|
||||
|
||||
<!-- login-page="/login" -->
|
||||
<form-login />
|
||||
<logout invalidate-session="true" logout-url="/signout" logout-success-url="/logout" />
|
||||
</http>
|
||||
|
||||
@@ -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" %>
|
||||
<c:set var="applicationName" scope="session" value="Mifos - Individual Lending: " />
|
||||
<c:set var="pageTitle" scope="session" value="Login"/>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<c:set var="pageTitle" scope="request"><spring:message code="page.home.title"/></c:set>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<jsp:include page="common-head.jsp" />
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#login').button();
|
||||
});
|
||||
</script>
|
||||
<jsp:include page="common-head.jsp" />
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="container">
|
||||
<div id="content">
|
||||
<div id="spacer" style="line-height: 25px;"> </div>
|
||||
|
||||
<div id="loginformholder"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script id="formLoginTemplate" type="text/x-jquery-tmpl">
|
||||
<form id="entityform">
|
||||
<div id="formerrors"></div>
|
||||
|
||||
<label for="username">Username:</label>
|
||||
<input size="75" type="text" name="j_username" id="username" title="Username for authentication." />
|
||||
|
||||
<label for="password">Password:</label>
|
||||
<input size="75" type="password" name="j_password" id="password" title="Password for authentication."/>
|
||||
</form>
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
<!--
|
||||
<h1>Mifos - Individual Lending: Login</h1>
|
||||
<div id="formcontainer">
|
||||
|
||||
<c:if test="${!empty sessionScope.SPRING_SECURITY_LAST_EXCEPTION}">
|
||||
<div class="ui-widget">
|
||||
<div class="ui-state-error ui-corner-all">
|
||||
<span class="ui-icon ui-icon-alert" style="float: left; margin-right: 5px;" ></span>
|
||||
<span>You have the following errors:</span>
|
||||
<div style="margin-left: 5px;">
|
||||
<p>Your login attempt was not successful. (<%= ((AuthenticationException) session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION)).getMessage() %>)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</c:if>
|
||||
<c:remove scope="session" var="SPRING_SECURITY_LAST_EXCEPTION"/>
|
||||
|
||||
<c:url value="/j_spring_security_check" var="loginFilterUrl" />
|
||||
<c:url value="${successUrl}" var="authSuccessUrl" />
|
||||
|
||||
<form method="post" action="${loginFilterUrl}">
|
||||
<fieldset>
|
||||
<legend>Login</legend>
|
||||
<label for="username">Username:</label>
|
||||
<input type="hidden" name="successUrl" value="${successUrl}" />
|
||||
|
||||
<c:choose>
|
||||
<c:when test="${param.oauth_token == null}">
|
||||
<input id="testone" type="hidden" name="oauth_token" value="${requestScope.oauth_token}" />
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<input id="testtwo" type="hidden" name="oauth_token" value="${param.oauth_token}" />
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
|
||||
|
||||
<input size="75" type="text" name="j_username" id="username" title="Username for authentication." />
|
||||
<label for="password">Password:</label>
|
||||
<input size="75" type="password" name="j_password" id="password" title="Password for authentication."/>
|
||||
<div id="formbuttons">
|
||||
<button type="submit" id="login" name="login" title="Log in to application.">Login</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
-->
|
||||
</html>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Context>
|
||||
</Context>
|
||||
@@ -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
|
||||
}
|
||||
@@ -7,14 +7,13 @@
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||
|
||||
<http security="none" pattern="/api/*/authentication" />
|
||||
|
||||
<http create-session="stateless" use-expressions="true" pattern="/api/**">
|
||||
<intercept-url pattern="/api/**" access="isFullyAuthenticated()" method="GET"/>
|
||||
<intercept-url pattern="/api/**" access="isFullyAuthenticated()" method="POST"/>
|
||||
<intercept-url pattern="/api/**" access="isFullyAuthenticated()" method="PUT"/>
|
||||
<intercept-url pattern="/api/**" access="isFullyAuthenticated()" method="DELETE"/>
|
||||
<intercept-url pattern="/api/**" access="isFullyAuthenticated()" method="HEAD"/>
|
||||
<intercept-url pattern="/api/*/authentication" access="permitAll" method="POST" requires-channel="https" />
|
||||
<intercept-url pattern="/api/**" access="isFullyAuthenticated()" method="GET" requires-channel="https" />
|
||||
<intercept-url pattern="/api/**" access="isFullyAuthenticated()" method="POST" requires-channel="https"/>
|
||||
<intercept-url pattern="/api/**" access="isFullyAuthenticated()" method="PUT" requires-channel="https"/>
|
||||
<intercept-url pattern="/api/**" access="isFullyAuthenticated()" method="DELETE" requires-channel="https"/>
|
||||
<intercept-url pattern="/api/**" access="isFullyAuthenticated()" method="HEAD" requires-channel="https"/>
|
||||
<http-basic />
|
||||
</http>
|
||||
|
||||
|
||||
@@ -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" %>
|
||||
|
||||
<!DOCTYPE>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
|
||||
<title>MifosNg Platform: Access Confirmation</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>MifosNg</h1>
|
||||
|
||||
<div id="content">
|
||||
|
||||
<c:if test="${!empty sessionScope.SPRING_SECURITY_LAST_EXCEPTION}">
|
||||
<div class="error">
|
||||
<h2>Woops!</h2>
|
||||
|
||||
<p>Access could not be granted. (<%= ((AuthenticationException) session.getAttribute(AbstractAuthenticationProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY)).getMessage() %>)</p>
|
||||
</div>
|
||||
</c:if>
|
||||
<c:remove scope="session" var="SPRING_SECURITY_LAST_EXCEPTION"/>
|
||||
|
||||
<h2>Please Confirm</h2>
|
||||
|
||||
<p>You hereby authorize "<c:out value="${consumer.consumerName}"/>" to access the following resource:</p>
|
||||
|
||||
<ul>
|
||||
<li><c:out value="${consumer.resourceName}"/> — <c:out value="${consumer.resourceDescription}"/></li>
|
||||
</ul>
|
||||
|
||||
<form action="<c:url value="/oauth/authorize"/>" method="POST">
|
||||
<input name="requestToken" value="<c:out value="${oauth_token}"/>" type="hidden"/>
|
||||
<label><input name="authorize" value="Authorize" type="submit"></label>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -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" %>
|
||||
<!DOCTYPE>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
|
||||
<title>MifosNg Platform</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Successful Authentication</h1>
|
||||
|
||||
<div id="content">
|
||||
<p>There are no UI capabilities on MifosNg Platform. You must use a suitable consumer (client) application to use our platform services.</p>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -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" %>
|
||||
<c:set var="applicationName" scope="session" value="Mifos - Individual Lending: " />
|
||||
<c:set var="pageTitle" scope="session" value="Login"/>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<jsp:include page="common-head.jsp" />
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#login').button();
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="container">
|
||||
<div id="content">
|
||||
<div id="spacer" style="line-height: 25px;"> </div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
<!--
|
||||
<h1>Mifos - Individual Lending: Login</h1>
|
||||
<div id="formcontainer">
|
||||
|
||||
<c:if test="${!empty sessionScope.SPRING_SECURITY_LAST_EXCEPTION}">
|
||||
<div class="ui-widget">
|
||||
<div class="ui-state-error ui-corner-all">
|
||||
<span class="ui-icon ui-icon-alert" style="float: left; margin-right: 5px;" ></span>
|
||||
<span>You have the following errors:</span>
|
||||
<div style="margin-left: 5px;">
|
||||
<p>Your login attempt was not successful. (<%= ((AuthenticationException) session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION)).getMessage() %>)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</c:if>
|
||||
<c:remove scope="session" var="SPRING_SECURITY_LAST_EXCEPTION"/>
|
||||
|
||||
<c:url value="/j_spring_security_check" var="loginFilterUrl" />
|
||||
<c:url value="${successUrl}" var="authSuccessUrl" />
|
||||
|
||||
<form method="post" action="${loginFilterUrl}">
|
||||
<fieldset>
|
||||
<legend>Login</legend>
|
||||
<label for="username">Username:</label>
|
||||
<input type="hidden" name="successUrl" value="${successUrl}" />
|
||||
|
||||
<c:choose>
|
||||
<c:when test="${param.oauth_token == null}">
|
||||
<input id="testone" type="hidden" name="oauth_token" value="${requestScope.oauth_token}" />
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<input id="testtwo" type="hidden" name="oauth_token" value="${param.oauth_token}" />
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
|
||||
|
||||
<input size="75" type="text" name="j_username" id="username" title="Username for authentication." />
|
||||
<label for="password">Password:</label>
|
||||
<input size="75" type="password" name="j_password" id="password" title="Password for authentication."/>
|
||||
<div id="formbuttons">
|
||||
<button type="submit" id="login" name="login" title="Log in to application.">Login</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
-->
|
||||
Reference in New Issue
Block a user