Commit 3992627d authored by Misagh Moayyed's avatar Misagh Moayyed
Browse files

updated config for googleapps

parent 24ff156d
......@@ -19,18 +19,31 @@
package org.jasig.cas.support.saml;
import org.apache.commons.lang3.StringUtils;
import org.jasig.cas.support.saml.authentication.principal.GoogleAccountsServiceFactory;
import org.jasig.cas.support.saml.authentication.principal.SamlService;
import org.jasig.cas.support.saml.authentication.principal.SamlServiceFactory;
import org.jasig.cas.util.PrivateKeyFactoryBean;
import org.jasig.cas.util.PublicKeyFactoryBean;
import org.jasig.cas.util.UniqueTicketIdGenerator;
import org.jasig.cas.web.AbstractServletContextInitializer;
import org.jasig.cas.web.support.ArgumentExtractor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.stereotype.Component;
import javax.servlet.ServletContextEvent;
import javax.servlet.annotation.WebListener;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.List;
/**
* Initializes the CAS root servlet context to make sure
......@@ -72,4 +85,64 @@ public class SamlServletContextListener extends AbstractServletContextInitialize
addControllerToCasServletHandlerMapping(SamlProtocolConstants.ENDPOINT_SAML_VALIDATE,
"samlValidateController");
}
@Component
@Configuration
private static class GoogleAppsConfigurationInitializer {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Value("${cas.saml.googleapps.publickey.file:}")
private String publicKeyLocation;
@Value("${cas.saml.googleapps.privatekey.file:}")
private String privateKeyLocation;
@Value("${cas.saml.googleapps.key.alg:}")
private String keyAlgorithm;
protected GoogleAppsConfigurationInitializer() {}
@Bean(name="googleAppsPrivateKey", autowire = Autowire.BY_NAME)
public PrivateKey getGoogleAppsPrivateKey() throws Exception {
if (!isValidConfiguration()) {
logger.debug("Google Apps private key bean will not be created, because it's not configured");
return null;
}
final PrivateKeyFactoryBean bean = new PrivateKeyFactoryBean();
bean.setLocation(new FileSystemResource(this.publicKeyLocation));
bean.setAlgorithm(this.keyAlgorithm);
logger.debug("Creating Google Apps private key instance via {}", this.publicKeyLocation);
return bean.getObject();
}
@Bean(name="googleAppsPublicKey", autowire = Autowire.BY_NAME)
public PublicKey getGoogleAppsPublicKey() throws Exception {
if (!isValidConfiguration()) {
logger.debug("Google Apps public key bean will not be created, because it's not configured");
return null;
}
final PublicKeyFactoryBean bean = new PublicKeyFactoryBean();
bean.setLocation(new FileSystemResource(this.publicKeyLocation));
bean.setAlgorithm(this.keyAlgorithm);
logger.debug("Creating Google Apps public key instance via {}", this.publicKeyLocation);
return bean.getObject();
}
@Bean(name="serviceFactoryList")
public List getServiceFactoryList() {
return new ArrayList();
}
private boolean isValidConfiguration() {
return StringUtils.isNotBlank(this.privateKeyLocation)
|| StringUtils.isNotBlank(this.publicKeyLocation)
|| StringUtils.isNotBlank(this.keyAlgorithm);
}
}
}
......@@ -73,7 +73,7 @@ public class GoogleAccountsServiceFactory extends AbstractServiceFactory<GoogleA
public GoogleAccountsService createService(final HttpServletRequest request) {
if (this.publicKey == null || this.privateKey == null) {
logger.debug("{} is will not turn on because private/public keys are not configured",
logger.debug("{} will not turn on because private/public keys are not configured",
getClass().getName());
return null;
}
......
<!--
Licensed to Apereo under one or more contributor license
agreements. See the NOTICE file distributed with this work
for additional information regarding copyright ownership.
Apereo licenses this file to you 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 the following location:
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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<description>
This file is loaded by the Spring configuration automatically, and serves as a placeholder
for various view definitions and beans. This helps with construction of views that require
references to other beans and whose changes can be configured externally.
</description>
<bean id="googleAppsPrivateKey" class="org.jasig.cas.util.PrivateKeyFactoryBean"
p:location="${cas.saml.googleapps.publickey.file:classpath:DSAPrivateKey01.key}"
p:algorithm="${cas.saml.googleapps.publickey.alg:DSA}" />
<bean id="googleAppsPublicKey" class="org.jasig.cas.util.PublicKeyFactoryBean"
p:location="${cas.saml.googleapps.privatekey.file:classpath:DSAPublicKey01.key}"
p:algorithm="${cas.saml.googleapps.privatekey.alg:DSA}" />
</beans>
......@@ -20,7 +20,6 @@
package org.jasig.cas.support.saml.authentication.principal;
import org.jasig.cas.support.saml.AbstractOpenSamlTests;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
......@@ -36,14 +35,8 @@ public class GoogleAccountsServiceFactoryTests extends AbstractOpenSamlTests {
@Autowired
private GoogleAccountsServiceFactory factory;
@Before
public void setUp() throws Exception {
this.factory = new GoogleAccountsServiceFactory();
}
@Test
public void verifyNoService() {
assertNull(factory.createService(new MockHttpServletRequest()));
}
}
<!--
Licensed to Apereo under one or more contributor license
agreements. See the NOTICE file distributed with this work
for additional information regarding copyright ownership.
Apereo licenses this file to you 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 the following location:
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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<description>
This file is loaded by the Spring configuration automatically, and serves as a placeholder
for various view definitions and beans. This helps with construction of views that require
references to other beans and whose changes can be configured externally.
</description>
<bean id="googleAppsPrivateKey" class="org.jasig.cas.util.PrivateKeyFactoryBean"
p:location="${cas.saml.googleapps.publickey.file:classpath:DSAPrivateKey01.key}"
p:algorithm="${cas.saml.googleapps.publickey.alg:DSA}" />
<bean id="googleAppsPublicKey" class="org.jasig.cas.util.PublicKeyFactoryBean"
p:location="${cas.saml.googleapps.privatekey.file:classpath:DSAPublicKey01.key}"
p:algorithm="${cas.saml.googleapps.privatekey.alg:DSA}" />
<util:list id="serviceFactoryList" />
</beans>
......@@ -31,3 +31,10 @@ cas.saml.response.skewAllowance=0
#
# Indicates whether SAML ticket id generation should be saml2-compliant.
cas.saml.ticketid.saml2=false
##
# Google Apps public/private key
#
cas.saml.googleapps.publickey.file=classpath:DSAPrivateKey01.key
cas.saml.googleapps.privatekey.file=classpath:DSAPrivateKey01.key
cas.saml.googleapps.key.alg=DSA
......@@ -248,6 +248,13 @@ tgc.signing.key=szxK-5_eJjs-aUj-64MpUZ-GPPzGLhYPLGl0wrYjYNVAGva2P0lLe6UGKGM7k8dW
# Indicates whether SAML ticket id generation should be saml2-compliant.
# cas.saml.ticketid.saml2=false
##
# Google Apps public/private key
#
# cas.saml.googleapps.publickey.file=classpath:DSAPrivateKey01.key
# cas.saml.googleapps.privatekey.file=classpath:DSAPrivateKey01.key
# cas.saml.googleapps.key.alg=DSA
##
# WS-FED
#
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment