swapped exception class for existing BeanCreationException, added example flag in config file (commented out)
closes #528 closes #689pull/685/merge
parent
3e3613f471
commit
ec8f708472
|
@ -20,6 +20,7 @@ import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,11 +56,11 @@ public class ConfigurationPropertiesBean {
|
||||||
* @throws HttpsUrlRequiredException
|
* @throws HttpsUrlRequiredException
|
||||||
*/
|
*/
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void checkForHttps() throws HttpsUrlRequiredException {
|
public void checkForHttps() {
|
||||||
if (!StringUtils.startsWithIgnoreCase(issuer, "https")) {
|
if (!StringUtils.startsWithIgnoreCase(issuer, "https")) {
|
||||||
if (this.forceHttps) {
|
if (this.forceHttps) {
|
||||||
logger.warn("Configured issuer url is not using https scheme. This is not allowed!");
|
logger.error("Configured issuer url is not using https scheme. Server will be shut down!");
|
||||||
throw new HttpsUrlRequiredException(issuer);
|
throw new BeanCreationException("Issuer is not using https scheme as required: " + issuer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger.warn("Configured issuer url is not using https scheme.");
|
logger.warn("Configured issuer url is not using https scheme.");
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright 2014 The MITRE Corporation
|
|
||||||
* and the MIT Kerberos and Internet Trust Consortium
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
******************************************************************************/
|
|
||||||
package org.mitre.openid.connect.config;
|
|
||||||
|
|
||||||
public class HttpsUrlRequiredException extends RuntimeException {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1318613592371145910L;
|
|
||||||
private String error;
|
|
||||||
/**
|
|
||||||
* @param error
|
|
||||||
*/
|
|
||||||
public HttpsUrlRequiredException(String error) {
|
|
||||||
this.setError(error);
|
|
||||||
}
|
|
||||||
public String getError() {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
public void setError(String error) {
|
|
||||||
this.error = error;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "HttpsUrlRequiredException [error=" + this.error + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -22,6 +22,7 @@ package org.mitre.openid.connect.config;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jricher
|
* @author jricher
|
||||||
|
@ -62,9 +63,8 @@ public class ConfigurationPropertiesBeanTest {
|
||||||
try {
|
try {
|
||||||
bean.setIssuer("http://localhost:8080/openid-connect-server/");
|
bean.setIssuer("http://localhost:8080/openid-connect-server/");
|
||||||
bean.checkForHttps();
|
bean.checkForHttps();
|
||||||
}
|
} catch (BeanCreationException e) {
|
||||||
catch (HttpsUrlRequiredException e) {
|
fail("Unexpected BeanCreationException for http issuer with default forceHttps, message:" + e.getMessage());
|
||||||
fail("Unexpected HttpsUrlRequiredException for http issuer with default forceHttps, message:" + e.getError());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,14 +77,13 @@ public class ConfigurationPropertiesBeanTest {
|
||||||
bean.setIssuer("http://localhost:8080/openid-connect-server/");
|
bean.setIssuer("http://localhost:8080/openid-connect-server/");
|
||||||
bean.setForceHttps(false);
|
bean.setForceHttps(false);
|
||||||
bean.checkForHttps();
|
bean.checkForHttps();
|
||||||
}
|
} catch (BeanCreationException e) {
|
||||||
catch (HttpsUrlRequiredException e) {
|
fail("Unexpected BeanCreationException for http issuer with forceHttps=false, message:" + e.getMessage());
|
||||||
fail("Unexpected HttpsUrlRequiredException for http issuer with forceHttps=false, message:" + e.getError());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = HttpsUrlRequiredException.class)
|
@Test(expected = BeanCreationException.class)
|
||||||
public void testCheckForHttpsIssuerHttpTrueFlag() throws HttpsUrlRequiredException {
|
public void testCheckForHttpsIssuerHttpTrueFlag() {
|
||||||
ConfigurationPropertiesBean bean = new ConfigurationPropertiesBean();
|
ConfigurationPropertiesBean bean = new ConfigurationPropertiesBean();
|
||||||
// issuer is http
|
// issuer is http
|
||||||
// set to true
|
// set to true
|
||||||
|
@ -101,9 +100,8 @@ public class ConfigurationPropertiesBeanTest {
|
||||||
try {
|
try {
|
||||||
bean.setIssuer("https://localhost:8080/openid-connect-server/");
|
bean.setIssuer("https://localhost:8080/openid-connect-server/");
|
||||||
bean.checkForHttps();
|
bean.checkForHttps();
|
||||||
}
|
} catch (BeanCreationException e) {
|
||||||
catch (HttpsUrlRequiredException e) {
|
fail("Unexpected BeanCreationException for https issuer with default forceHttps, message:" + e.getMessage());
|
||||||
fail("Unexpected HttpsUrlRequiredException for https issuer with default forceHttps, message:" + e.getError());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,9 +114,8 @@ public class ConfigurationPropertiesBeanTest {
|
||||||
bean.setIssuer("https://localhost:8080/openid-connect-server/");
|
bean.setIssuer("https://localhost:8080/openid-connect-server/");
|
||||||
bean.setForceHttps(false);
|
bean.setForceHttps(false);
|
||||||
bean.checkForHttps();
|
bean.checkForHttps();
|
||||||
}
|
} catch (BeanCreationException e) {
|
||||||
catch (HttpsUrlRequiredException e) {
|
fail("Unexpected BeanCreationException for https issuer with forceHttps=false, message:" + e.getMessage());
|
||||||
fail("Unexpected HttpsUrlRequiredException for https issuer with forceHttps=false, message:" + e.getError());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,9 +128,8 @@ public class ConfigurationPropertiesBeanTest {
|
||||||
bean.setIssuer("https://localhost:8080/openid-connect-server/");
|
bean.setIssuer("https://localhost:8080/openid-connect-server/");
|
||||||
bean.setForceHttps(true);
|
bean.setForceHttps(true);
|
||||||
bean.checkForHttps();
|
bean.checkForHttps();
|
||||||
}
|
} catch (BeanCreationException e) {
|
||||||
catch (HttpsUrlRequiredException e) {
|
fail("Unexpected BeanCreationException for https issuer with forceHttps=true, message:" + e.getMessage());
|
||||||
fail("Unexpected HttpsUrlRequiredException for https issuer with forceHttps=true, message:" + e.getError());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
<bean id="configBean" class="org.mitre.openid.connect.config.ConfigurationPropertiesBean">
|
<bean id="configBean" class="org.mitre.openid.connect.config.ConfigurationPropertiesBean">
|
||||||
|
|
||||||
<!-- This property sets the root URL of the server, known as the issuer. -->
|
<!-- This property sets the root URL of the server, known as the issuer -->
|
||||||
<property name="issuer" value="http://localhost:8080/openid-connect-server-webapp/" />
|
<property name="issuer" value="http://localhost:8080/openid-connect-server-webapp/" />
|
||||||
|
|
||||||
<!-- This property is a URL pointing to a logo image 24px high to be used in the top bar -->
|
<!-- This property is a URL pointing to a logo image 24px high to be used in the top bar -->
|
||||||
|
@ -41,6 +41,9 @@
|
||||||
|
|
||||||
<!-- This property sets the lifetime of registration access tokens, in seconds. Leave it unset (null) for no rotation. -->
|
<!-- This property sets the lifetime of registration access tokens, in seconds. Leave it unset (null) for no rotation. -->
|
||||||
<!-- <property name="regTokenLifeTime" value="172800" /> -->
|
<!-- <property name="regTokenLifeTime" value="172800" /> -->
|
||||||
|
|
||||||
|
<!-- This property forces the issuer value to start with "https" -->
|
||||||
|
<!-- <property name="forceHttps" value="true" /> -->
|
||||||
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue