Search in sources :

Example 6 with EncryptionService

use of ddf.security.encryption.EncryptionService in project ddf by codice.

the class TestRegistryStore method setup.

@Before
public void setup() throws Exception {
    parser = new XmlParser();
    marshaller = new MetacardMarshaller(new XmlParser());
    context = mock(BundleContext.class);
    provider = mock(Converter.class);
    cswSourceConfiguration = new CswSourceConfiguration();
    factory = mock(SecureCxfClientFactory.class);
    transformer = mock(TransformerManager.class);
    encryptionService = mock(EncryptionService.class);
    configAdmin = mock(ConfigurationAdmin.class);
    configuration = mock(Configuration.class);
    subject = mock(Subject.class);
    queryResults = new ArrayList<>();
    registryStore = spy(new RegistryStoreImpl(context, cswSourceConfiguration, provider, factory, encryptionService) {

        @Override
        protected void validateOperation() {
        }

        @Override
        public boolean isAvailable() {
            return availability;
        }

        @Override
        protected SourceResponse query(QueryRequest queryRequest, ElementSetType elementSetName, List<QName> elementNames, Csw csw) throws UnsupportedQueryException {
            if (queryResults == null) {
                throw new UnsupportedQueryException("Test - Bad Query");
            }
            return new SourceResponseImpl(queryRequest, queryResults);
        }

        @Override
        protected CapabilitiesType getCapabilities() {
            return mock(CapabilitiesType.class);
        }

        @Override
        public void configureCswSource() {
        }

        ;

        @Override
        protected Subject getSystemSubject() {
            return subject;
        }

        @Override
        BundleContext getBundleContext() {
            return context;
        }
    });
    registryStore.setFilterBuilder(filterBuilder);
    registryStore.setFilterAdapter(filterAdapter);
    registryStore.setConfigAdmin(configAdmin);
    registryStore.setMetacardMarshaller(new MetacardMarshaller(parser));
    registryStore.setSchemaTransformerManager(transformer);
    registryStore.setAutoPush(true);
    registryStore.setRegistryUrl("http://test.url:0101/example");
    properties = new Hashtable<>();
    properties.put(RegistryStoreImpl.ID, "registryId");
    registryStore.setMetacardMarshaller(marshaller);
    when(configAdmin.getConfiguration(any())).thenReturn(configuration);
    when(configuration.getProperties()).thenReturn(properties);
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) XmlParser(org.codice.ddf.parser.xml.XmlParser) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) Configuration(org.osgi.service.cm.Configuration) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) QueryRequest(ddf.catalog.operation.QueryRequest) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Subject(ddf.security.Subject) EncryptionService(ddf.security.encryption.EncryptionService) ElementSetType(net.opengis.cat.csw.v_2_0_2.ElementSetType) Converter(com.thoughtworks.xstream.converters.Converter) List(java.util.List) ArrayList(java.util.ArrayList) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 7 with EncryptionService

use of ddf.security.encryption.EncryptionService in project ddf by codice.

the class LogoutRequestServiceTest method setup.

@Before
public void setup() throws ParserConfigurationException, SAXException, IOException {
    simpleSign = mock(SimpleSign.class);
    idpMetadata = mock(IdpMetadata.class);
    relayStates = mock(RelayStates.class);
    sessionFactory = mock(SessionFactory.class);
    request = mock(HttpServletRequest.class);
    logoutMessage = mock(LogoutMessage.class);
    encryptionService = mock(EncryptionService.class);
    session = mock(HttpSession.class);
    securityTokenHolder = mock(SecurityTokenHolder.class);
    Element issuedAssertion = readSamlAssertion().getDocumentElement();
    String assertionId = issuedAssertion.getAttributeNodeNS(null, "ID").getNodeValue();
    SecurityToken token = new SecurityToken(assertionId, issuedAssertion, null);
    when(securityTokenHolder.getSecurityToken("idp")).thenReturn(token);
    logoutRequestService = new MockLogoutRequestService(simpleSign, idpMetadata, relayStates);
    logoutRequestService.setEncryptionService(encryptionService);
    logoutRequestService.setLogOutPageTimeOut(LOGOUT_PAGE_TIMEOUT);
    logoutRequestService.setLogoutMessage(logoutMessage);
    logoutRequestService.setRequest(request);
    logoutRequestService.setSessionFactory(sessionFactory);
    logoutRequestService.init();
    when(sessionFactory.getOrCreateSession(request)).thenReturn(session);
    when(session.getAttribute(eq(SecurityConstants.SAML_ASSERTION))).thenReturn(securityTokenHolder);
    when(request.getRequestURL()).thenReturn(new StringBuffer("www.url.com/url"));
    when(idpMetadata.getSigningCertificate()).thenReturn("signingCertificate");
    when(idpMetadata.getSingleLogoutBinding()).thenReturn(SamlProtocol.REDIRECT_BINDING);
    when(idpMetadata.getSingleLogoutLocation()).thenReturn(redirectLogoutUrl);
    System.setProperty("security.audit.roles", "none");
}
Also used : SessionFactory(ddf.security.http.SessionFactory) RelayStates(ddf.security.samlp.impl.RelayStates) LogoutMessage(ddf.security.samlp.LogoutMessage) HttpSession(javax.servlet.http.HttpSession) Element(org.w3c.dom.Element) Matchers.anyString(org.mockito.Matchers.anyString) HttpServletRequest(javax.servlet.http.HttpServletRequest) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) SimpleSign(ddf.security.samlp.SimpleSign) SecurityTokenHolder(ddf.security.common.SecurityTokenHolder) EncryptionService(ddf.security.encryption.EncryptionService) Before(org.junit.Before)

Example 8 with EncryptionService

use of ddf.security.encryption.EncryptionService in project ddf by codice.

the class IdpHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    encryptionService = mock(EncryptionService.class);
    systemCrypto = new SystemCrypto("encryption.properties", "signature.properties", encryptionService);
    simpleSign = new SimpleSign(systemCrypto);
    idpMetadata = new IdpMetadata();
    relayStates = (RelayStates<String>) mock(RelayStates.class);
    when(relayStates.encode(anyString())).thenReturn(RELAY_STATE_VAL);
    when(relayStates.decode(RELAY_STATE_VAL)).thenReturn(LOCATION);
    httpRequest = mock(HttpServletRequest.class);
    when(httpRequest.getRequestURL()).thenReturn(new StringBuffer("https://localhost:8993"));
    when(httpRequest.getMethod()).thenReturn("GET");
    httpResponse = mock(HttpServletResponse.class);
    idpHandler = new IdpHandler(simpleSign, idpMetadata, relayStates);
    StringWriter writer = new StringWriter();
    InputStream inputStream = this.getClass().getResourceAsStream("/IDPmetadata.xml");
    IOUtils.copy(inputStream, writer, "UTF-8");
    metadata = writer.toString();
    idpMetadata.setMetadata(metadata);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SimpleSign(ddf.security.samlp.SimpleSign) SystemCrypto(ddf.security.samlp.SystemCrypto) StringWriter(java.io.StringWriter) EncryptionService(ddf.security.encryption.EncryptionService) InputStream(java.io.InputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) Matchers.anyString(org.mockito.Matchers.anyString) Before(org.junit.Before)

Example 9 with EncryptionService

use of ddf.security.encryption.EncryptionService in project ddf by codice.

the class AssertionConsumerServiceTest method setUp.

@Before
public void setUp() throws Exception {
    encryptionService = mock(EncryptionService.class);
    systemCrypto = new SystemCrypto("encryption.properties", "signature.properties", encryptionService);
    simpleSign = new SimpleSign(systemCrypto);
    relayStates = (RelayStates<String>) mock(RelayStates.class);
    when(relayStates.encode("fubar")).thenReturn(RELAY_STATE_VAL);
    when(relayStates.decode(RELAY_STATE_VAL)).thenReturn(LOCATION);
    loginFilter = mock(javax.servlet.Filter.class);
    sessionFactory = mock(SessionFactory.class);
    httpRequest = mock(HttpServletRequest.class);
    when(httpRequest.getRequestURL()).thenReturn(new StringBuffer("fubar"));
    when(httpRequest.isSecure()).thenReturn(true);
    idpMetadata = new IdpMetadata();
    assertionConsumerService = new AssertionConsumerService(simpleSign, idpMetadata, systemCrypto, relayStates);
    assertionConsumerService.setRequest(httpRequest);
    assertionConsumerService.setLoginFilter(loginFilter);
    assertionConsumerService.setSessionFactory(sessionFactory);
    cannedResponse = Resources.toString(Resources.getResource(getClass(), "/SAMLResponse.xml"), Charsets.UTF_8);
    String metadata = Resources.toString(Resources.getResource(getClass(), "/IDPmetadata.xml"), Charsets.UTF_8);
    deflatedSamlResponse = Resources.toString(Resources.getResource(getClass(), "/DeflatedSAMLResponse.txt"), Charsets.UTF_8);
    idpMetadata.setMetadata(metadata);
}
Also used : SessionFactory(ddf.security.http.SessionFactory) HttpServletRequest(javax.servlet.http.HttpServletRequest) SimpleSign(ddf.security.samlp.SimpleSign) SystemCrypto(ddf.security.samlp.SystemCrypto) Filter(javax.servlet.Filter) EncryptionService(ddf.security.encryption.EncryptionService) Before(org.junit.Before)

Aggregations

EncryptionService (ddf.security.encryption.EncryptionService)9 Before (org.junit.Before)8 SimpleSign (ddf.security.samlp.SimpleSign)5 SystemCrypto (ddf.security.samlp.SystemCrypto)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Subject (ddf.security.Subject)2 SessionFactory (ddf.security.http.SessionFactory)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)2 SecureCxfClientFactory (org.codice.ddf.cxf.SecureCxfClientFactory)2 BundleContext (org.osgi.framework.BundleContext)2 Converter (com.thoughtworks.xstream.converters.Converter)1 MetacardType (ddf.catalog.data.MetacardType)1 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)1 ResourceReader (ddf.catalog.resource.ResourceReader)1