Commit 7dd3d2be authored by Misagh Moayyed's avatar Misagh Moayyed
Browse files

working on googleapps config

parent f92f2e39
......@@ -54,6 +54,7 @@ public final class PrivateKeyFactoryBean extends AbstractFactoryBean<PrivateKey>
}
}
@Override
public Class getObjectType() {
return PrivateKey.class;
}
......
......@@ -21,6 +21,8 @@ package org.jasig.cas.web;
import org.jasig.cas.authentication.AuthenticationHandler;
import org.jasig.cas.authentication.principal.PrincipalResolver;
import org.jasig.cas.authentication.principal.Service;
import org.jasig.cas.authentication.principal.ServiceFactory;
import org.jasig.cas.services.RegisteredService;
import org.jasig.cas.services.ServicesManager;
import org.jasig.cas.util.UniqueTicketIdGenerator;
......@@ -201,6 +203,18 @@ public abstract class AbstractServletContextInitializer implements ServletContex
list.add(ext);
}
/**
* Add service factory.
*
* @param factory the factory
*/
protected void addServiceFactory(final ServiceFactory<? extends Service> factory) {
final List<ServiceFactory<? extends Service>> list =
applicationContext.getBean("serviceFactoryList", List.class);
list.add(factory);
}
/**
* Add service ticket unique id generator.
*
......
......@@ -20,6 +20,7 @@ package org.jasig.cas.web.support;
import org.jasig.cas.authentication.principal.ServiceFactory;
import org.jasig.cas.authentication.principal.WebApplicationService;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.Min;
......@@ -33,6 +34,7 @@ import java.util.List;
* @author Misagh Moayyed
* @since 4.2
*/
@Component("defaultArgumentExtractor")
public final class DefaultArgumentExtractor extends AbstractArgumentExtractor {
/**
......
......@@ -22,6 +22,7 @@ package org.jasig.cas.support.openid;
import org.jasig.cas.authentication.AuthenticationHandler;
import org.jasig.cas.authentication.principal.PrincipalResolver;
import org.jasig.cas.support.openid.authentication.principal.OpenIdService;
import org.jasig.cas.support.openid.authentication.principal.OpenIdServiceFactory;
import org.jasig.cas.util.UniqueTicketIdGenerator;
import org.jasig.cas.web.AbstractServletContextInitializer;
import org.jasig.cas.web.support.ArgumentExtractor;
......@@ -55,8 +56,8 @@ public class OpenIdServletContextListener extends AbstractServletContextInitiali
private PrincipalResolver openIdPrincipalResolver;
@Autowired
@Qualifier("openIdArgumentExtractor")
private ArgumentExtractor openIdArgumentExtractor;
@Qualifier("openIdServiceFactory")
private OpenIdServiceFactory openIdServiceFactory;
@Override
protected void initializeRootApplicationContext() {
......@@ -67,7 +68,7 @@ public class OpenIdServletContextListener extends AbstractServletContextInitiali
protected void initializeServletApplicationContext() {
addControllerToCasServletHandlerMapping(OpenIdProtocolConstants.ENDPOINT_OPENID, "openIdProviderController");
addServiceTicketUniqueIdGenerator(OpenIdService.class.getCanonicalName(), this.serviceTicketUniqueIdGenerator);
addArgumentExtractor(this.openIdArgumentExtractor);
addServiceFactory(openIdServiceFactory);
}
@Override
......
......@@ -22,6 +22,7 @@ package org.jasig.cas.support.openid.authentication.principal;
import org.jasig.cas.authentication.principal.AbstractServiceFactory;
import org.jasig.cas.support.openid.OpenIdProtocolConstants;
import org.openid4java.message.ParameterList;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletRequest;
......@@ -33,6 +34,7 @@ import javax.validation.constraints.NotNull;
* @author Misagh Moayyed
* @since 4.2
*/
@Component("openIdServiceFactory")
public class OpenIdServiceFactory extends AbstractServiceFactory<OpenIdService> {
/**
......
......@@ -34,6 +34,7 @@ import javax.validation.constraints.NotNull;
* @since 3.1
*/
@Deprecated
@Component("openIdArgumentExtractor")
public class OpenIdArgumentExtractor extends AbstractArgumentExtractor {
/**
* The prefix url for OpenID (without the trailing slash).
......
......@@ -19,7 +19,9 @@
package org.jasig.cas.support.saml;
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.UniqueTicketIdGenerator;
import org.jasig.cas.web.AbstractServletContextInitializer;
import org.jasig.cas.web.support.ArgumentExtractor;
......@@ -41,8 +43,12 @@ import javax.servlet.annotation.WebListener;
public class SamlServletContextListener extends AbstractServletContextInitializer {
@Autowired
@Qualifier("samlArgumentExtractor")
private ArgumentExtractor samlArgumentExtractor;
@Qualifier("samlServiceFactory")
private SamlServiceFactory samlServiceFactory;
@Autowired
@Qualifier("googleAccountsServiceFactory")
private GoogleAccountsServiceFactory googleAccountsServiceFactory;
@Autowired
@Qualifier("samlServiceTicketUniqueIdGenerator")
......@@ -55,7 +61,8 @@ public class SamlServletContextListener extends AbstractServletContextInitialize
@Override
protected void initializeRootApplicationContext() {
addArgumentExtractor(this.samlArgumentExtractor);
addServiceFactory(samlServiceFactory);
addServiceFactory(googleAccountsServiceFactory);
addServiceTicketUniqueIdGenerator(SamlService.class.getCanonicalName(),
this.samlServiceTicketUniqueIdGenerator);
}
......
......@@ -27,10 +27,15 @@ import org.jasig.cas.support.saml.util.AbstractSaml20ObjectBuilder;
import org.jasig.cas.support.saml.util.GoogleSaml20ObjectBuilder;
import org.jdom.Document;
import org.jdom.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.security.PrivateKey;
import java.security.PublicKey;
......@@ -39,36 +44,40 @@ import java.security.PublicKey;
* @author Misagh Moayyed
* @since 4.2
*/
@Component("googleAccountsServiceFactory")
public class GoogleAccountsServiceFactory extends AbstractServiceFactory<GoogleAccountsService> {
private static final GoogleSaml20ObjectBuilder BUILDER = new GoogleSaml20ObjectBuilder();
@NotNull
private final PublicKey publicKey;
@Nullable
@Autowired
@Qualifier("googleAppsPublicKey")
private PublicKey publicKey;
@NotNull
private final PrivateKey privateKey;
@Nullable
@Autowired
@Qualifier("googleAppsPrivateKey")
private PrivateKey privateKey;
@NotNull
private final ServicesManager servicesManager;
@Autowired
@Qualifier("servicesManager")
private ServicesManager servicesManager;
/**
* Instantiates a new Google accounts service factory.
*
* @param publicKey the public key
* @param privateKey the private key
* @param servicesManager the services manager
*/
public GoogleAccountsServiceFactory(final PublicKey publicKey, final PrivateKey privateKey,
final ServicesManager servicesManager) {
this.publicKey = publicKey;
this.privateKey = privateKey;
this.servicesManager = servicesManager;
}
public GoogleAccountsServiceFactory() {}
@Override
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",
getClass().getName());
return null;
}
final String relayState = request.getParameter(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE);
final String xmlRequest = BUILDER.decodeSamlAuthnRequest(
......
......@@ -21,6 +21,7 @@ package org.jasig.cas.support.saml.authentication.principal;
import org.jasig.cas.authentication.principal.AbstractServiceFactory;
import org.jasig.cas.support.saml.SamlProtocolConstants;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletRequest;
......@@ -32,6 +33,7 @@ import java.io.BufferedReader;
* @author Misagh Moayyed
* @since 4.2
*/
@Component("samlServiceFactory")
public class SamlServiceFactory extends AbstractServiceFactory<SamlService> {
private static final int CONST_REQUEST_ID_LENGTH = 11;
......
<!--
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="googleAppsPublicKey" class="org.jasig.cas.util.PrivateKeyFactoryBean"
p:location="${cas.saml.googleapps.publickey.file:classpath:private.p8}"
p:algorithm="${cas.saml.googleapps.publickey.alg:RSA}" />
<bean id="googleAppsPublicKey" class="org.jasig.cas.util.PublicKeyFactoryBean"
p:location="${cas.saml.googleapps.privatekey.file:classpath:public.p8}"
p:algorithm="${cas.saml.googleapps.privatekey.alg:RSA}" />
</beans>
......@@ -41,7 +41,7 @@ import static org.junit.Assert.*;
* @since 4.1
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/META-INF/spring/opensaml-config.xml"})
@ContextConfiguration({"/META-INF/spring/*-config.xml"})
@WebAppConfiguration()
public abstract class AbstractOpenSamlTests {
@Autowired
......
......@@ -19,19 +19,11 @@
package org.jasig.cas.support.saml.authentication.principal;
import org.jasig.cas.services.ServicesManager;
import org.jasig.cas.util.PrivateKeyFactoryBean;
import org.jasig.cas.util.PublicKeyFactoryBean;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mock.web.MockHttpServletRequest;
import java.security.PrivateKey;
import java.security.PublicKey;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.junit.Assert.assertNull;
/**
* Test cases for {@link GoogleAccountsServiceFactory}.
......@@ -43,26 +35,7 @@ public class GoogleAccountsServiceFactoryTests {
@Before
public void setUp() throws Exception {
final PublicKeyFactoryBean pubKeyFactoryBean = new PublicKeyFactoryBean();
final PrivateKeyFactoryBean privKeyFactoryBean = new PrivateKeyFactoryBean();
pubKeyFactoryBean.setAlgorithm("DSA");
privKeyFactoryBean.setAlgorithm("DSA");
final ClassPathResource pubKeyResource = new ClassPathResource("DSAPublicKey01.key");
final ClassPathResource privKeyResource = new ClassPathResource("DSAPrivateKey01.key");
pubKeyFactoryBean.setLocation(pubKeyResource);
privKeyFactoryBean.setLocation(privKeyResource);
assertTrue(privKeyFactoryBean.getObjectType().equals(PrivateKey.class));
assertTrue(pubKeyFactoryBean.getObjectType().equals(PublicKey.class));
pubKeyFactoryBean.afterPropertiesSet();
privKeyFactoryBean.afterPropertiesSet();
final ServicesManager servicesManager = mock(ServicesManager.class);
this.factory = new GoogleAccountsServiceFactory(pubKeyFactoryBean.getObject(),
privKeyFactoryBean.getObject(), servicesManager);
this.factory = new GoogleAccountsServiceFactory();
}
@Test
public void verifyNoService() {
......
......@@ -28,21 +28,18 @@ import org.jasig.cas.services.ServicesManager;
import org.jasig.cas.support.saml.AbstractOpenSamlTests;
import org.jasig.cas.support.saml.SamlProtocolConstants;
import org.jasig.cas.util.CompressionUtils;
import org.jasig.cas.util.PrivateKeyFactoryBean;
import org.jasig.cas.util.PublicKeyFactoryBean;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import java.io.IOException;
import java.security.interfaces.DSAPrivateKey;
import java.security.interfaces.DSAPublicKey;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
/**
* @author Scott Battaglia
......@@ -52,25 +49,12 @@ public class GoogleAccountsServiceTests extends AbstractOpenSamlTests {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private GoogleAccountsService googleAccountsService;
public static GoogleAccountsService getGoogleAccountsService() throws Exception {
final PublicKeyFactoryBean pubKeyFactoryBean = new PublicKeyFactoryBean();
pubKeyFactoryBean.setAlgorithm("DSA");
final PrivateKeyFactoryBean privKeyFactoryBean = new PrivateKeyFactoryBean();
privKeyFactoryBean.setAlgorithm("DSA");
final ClassPathResource pubKeyResource = new ClassPathResource("DSAPublicKey01.key");
final ClassPathResource privKeyResource = new ClassPathResource("DSAPrivateKey01.key");
@Autowired
private GoogleAccountsServiceFactory factory;
pubKeyFactoryBean.setLocation(pubKeyResource);
privKeyFactoryBean.setLocation(privKeyResource);
pubKeyFactoryBean.afterPropertiesSet();
privKeyFactoryBean.afterPropertiesSet();
final DSAPrivateKey privateKey = (DSAPrivateKey) privKeyFactoryBean.getObject();
final DSAPublicKey publicKey = (DSAPublicKey) pubKeyFactoryBean.getObject();
private GoogleAccountsService googleAccountsService;
public GoogleAccountsService getGoogleAccountsService() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final String samlRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
......@@ -87,7 +71,7 @@ public class GoogleAccountsServiceTests extends AbstractOpenSamlTests {
final ServicesManager servicesManager = mock(ServicesManager.class);
when(servicesManager.findServiceBy(any(Service.class))).thenReturn(regSvc);
return new GoogleAccountsServiceFactory(publicKey, privateKey, servicesManager).createService(request);
return factory.createService(request);
}
@Before
......
<!--
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"
init-method="getObject"
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"
init-method="getObject"
p:location="${cas.saml.googleapps.privatekey.file:classpath:DSAPublicKey01.key}"
p:algorithm="${cas.saml.googleapps.privatekey.alg:DSA}" />
<util:list id="serviceFactoryList" />
</beans>
......@@ -32,7 +32,7 @@
</description>
<bean id="defaultArgumentExtractor"
class="org.jasig.cas.web.support.DefaultArgumentExtractor"
class="org.jasig.cas.web.support.DefaultArgumentExtractor"
c:serviceFactoryList-ref="serviceFactoryList" />
<util:list id="serviceFactoryList">
......
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