add https support for platform available at localhost:8443 by default when running from command line.
This commit is contained in:
+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>
|
||||
Reference in New Issue
Block a user