Search in sources :

Example 1 with SystemCrypto

use of ddf.security.samlp.impl.SystemCrypto in project ddf by codice.

the class AssertionConsumerServiceTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    systemCrypto = new SystemCrypto("encryption.properties", "signature.properties", encryptionService);
    simpleSign = new SimpleSign(systemCrypto);
    idpMetadata = new IdpMetadata();
    idpMetadata.setMetadata(metadata);
    // stubs
    when(relayStates.encode(REQUEST_URL)).thenReturn(RELAY_STATE_VAL);
    when(relayStates.decode(RELAY_STATE_VAL)).thenReturn(LOCATION);
    when(principal.getName()).thenReturn(SUBJECT_NAME);
    when(securityToken.getPrincipal()).thenReturn(principal);
    when(principalHolder.getPrincipals()).thenReturn(null);
    when(session.getAttribute(SAML_PROPERTY_KEY)).thenReturn(principalHolder);
    when(session.getId()).thenReturn(SESSION_ID);
    when(sessionFactory.getOrCreateSession(any(HttpServletRequest.class))).thenReturn(session);
    when(httpRequest.getServerName()).thenReturn(HOST);
    when(httpRequest.getRequestURL()).thenReturn(new StringBuffer(REQUEST_URL));
    when(httpRequest.isSecure()).thenReturn(true);
    when(securityAssertion.getToken()).thenReturn(securityToken);
    List<Object> principalList = Arrays.asList(securityAssertion);
    when(principalCollection.asList()).thenReturn(principalList);
    when(subject.getPrincipals()).thenReturn(principalCollection);
    assertionConsumerService = new AssertionConsumerService(simpleSign, idpMetadata, systemCrypto, relayStates);
    assertionConsumerService.setRequest(httpRequest);
    assertionConsumerService.setLoginFilter(loginFilter);
    assertionConsumerService.setSessionFactory(sessionFactory);
    assertionConsumerService.setContextPolicyManager(contextPolicyManager);
    assertionConsumerService.setSamlSecurity(new SamlSecurity());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SimpleSign(ddf.security.samlp.impl.SimpleSign) SystemCrypto(ddf.security.samlp.impl.SystemCrypto) SamlSecurity(org.codice.ddf.security.jaxrs.impl.SamlSecurity) Before(org.junit.Before)

Example 2 with SystemCrypto

use of ddf.security.samlp.impl.SystemCrypto in project ddf by codice.

the class AttributeQueryClientTest method setUp.

@Before
public void setUp() throws IOException {
    dispatch = mock(Dispatch.class);
    encryptionService = mock(EncryptionService.class);
    systemCrypto = new SystemCrypto("encryption.properties", "signature.properties", encryptionService);
    SimpleSign simpleSign = new SimpleSign(systemCrypto);
    spySimpleSign = spy(simpleSign);
    attributeQueryClient = new AttributeQueryClient(dispatch, spySimpleSign, EXTERNAL_ATTRIBUTE_STORE, ISSUER, DESTINATION);
    attributeQueryClient.setDispatch(dispatch);
    attributeQueryClient.setSimpleSign(spySimpleSign);
    attributeQueryClient.setExternalAttributeStoreUrl(EXTERNAL_ATTRIBUTE_STORE);
    attributeQueryClient.setIssuer(ISSUER);
    attributeQueryClient.setDestination(DESTINATION);
    cannedResponse = Resources.toString(Resources.getResource(getClass(), "/SAMLResponse.xml"), Charsets.UTF_8);
}
Also used : SimpleSign(ddf.security.samlp.impl.SimpleSign) SystemCrypto(ddf.security.samlp.impl.SystemCrypto) EncryptionService(ddf.security.encryption.EncryptionService) Dispatch(javax.xml.ws.Dispatch) Before(org.junit.Before)

Example 3 with SystemCrypto

use of ddf.security.samlp.impl.SystemCrypto in project ddf by codice.

the class SamlAssertionValidatorImplTest method setUp.

@Before
public void setUp() throws Exception {
    File signatureFile = temporaryFolder.newFile("signature.properties");
    File encryptionFile = temporaryFolder.newFile("encryption.properties");
    File jksFile = temporaryFolder.newFile("serverKeystore.jks");
    try (FileOutputStream outputStream = new FileOutputStream(signatureFile);
        InputStream inputStream = getClass().getResourceAsStream("/signature.properties")) {
        IOUtils.copy(inputStream, outputStream);
    }
    try (FileOutputStream outputStream = new FileOutputStream(encryptionFile);
        InputStream inputStream = getClass().getResourceAsStream("/encryption.properties")) {
        IOUtils.copy(inputStream, outputStream);
    }
    try (FileOutputStream outputStream = new FileOutputStream(jksFile);
        InputStream inputStream = getClass().getResourceAsStream("/serverKeystore.jks")) {
        IOUtils.copy(inputStream, outputStream);
    }
    System.setProperty("javax.net.ssl.keyStore", jksFile.getAbsolutePath());
    System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
    System.setProperty("org.codice.ddf.system.hostname", "localhost");
    EncryptionService encryptionService = mock(EncryptionService.class);
    when(encryptionService.decrypt(anyString())).thenReturn("changeit");
    when(encryptionService.encrypt(anyString())).thenReturn("changeit");
    SystemCrypto crypto = new SystemCrypto(signatureFile.getAbsolutePath(), encryptionFile.getAbsolutePath(), encryptionService);
    CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
    cryptoType.setAlias(crypto.getSignatureAlias());
    certificate = crypto.getSignatureCrypto().getX509Certificates(cryptoType)[0];
    privateKey = crypto.getSignatureCrypto().getPrivateKey(crypto.getSignatureAlias(), crypto.getSignaturePassword());
    samlAssertionValidator = new SamlAssertionValidatorImpl();
    samlAssertionValidator.setSignatureProperties(signatureFile.getAbsolutePath());
}
Also used : SystemCrypto(ddf.security.samlp.impl.SystemCrypto) InputStream(java.io.InputStream) EncryptionService(ddf.security.encryption.EncryptionService) FileOutputStream(java.io.FileOutputStream) CryptoType(org.apache.wss4j.common.crypto.CryptoType) File(java.io.File) Before(org.junit.Before)

Example 4 with SystemCrypto

use of ddf.security.samlp.impl.SystemCrypto in project ddf by codice.

the class AttributeQueryClaimsHandlerTest method setUp.

@Before
public void setUp() throws IOException {
    signatureProperties = mock(Properties.class);
    encryptionProperties = mock(Properties.class);
    service = mock(Service.class);
    dispatch = (Dispatch<StreamSource>) mock(Dispatch.class);
    encryptionService = mock(EncryptionService.class);
    systemCrypto = new SystemCrypto("encryption.properties", "signature.properties", encryptionService);
    simpleSign = new SimpleSign(systemCrypto);
    supportedClaims = new ArrayList<>();
    supportedClaims.add("Role");
    supportedClaims.add("NameIdentifier");
    supportedClaims.add("Email");
    AttributeQueryTestClaimsHandler attributeQueryClaimsHandler = new AttributeQueryTestClaimsHandler();
    spyAttributeQueryClaimsHandler = spy(attributeQueryClaimsHandler);
    spyAttributeQueryClaimsHandler.setWsdlLocation("wsdlLocation");
    spyAttributeQueryClaimsHandler.setServiceName("serviceName");
    spyAttributeQueryClaimsHandler.setPortName("portName");
    spyAttributeQueryClaimsHandler.setSimpleSign(simpleSign);
    spyAttributeQueryClaimsHandler.setSupportedClaims(supportedClaims);
    spyAttributeQueryClaimsHandler.setExternalAttributeStoreUrl(EXTERNAL_ATTRIBUTE_STORE);
    spyAttributeQueryClaimsHandler.setIssuer(ISSUER);
    spyAttributeQueryClaimsHandler.setDestination(DESTINATION);
    spyAttributeQueryClaimsHandler.setAttributeMapLocation(getClass().getClassLoader().getResource("attributeMap.properties").getPath());
    spyAttributeQueryClaimsHandler.setSignatureProperties(signatureProperties);
    spyAttributeQueryClaimsHandler.setEncryptionProperties(encryptionProperties);
    doReturn(service).when(spyAttributeQueryClaimsHandler).createService();
    doReturn(dispatch).when(spyAttributeQueryClaimsHandler).createDispatcher(service);
    cannedResponse = Resources.toString(Resources.getResource(getClass(), "/SAMLResponse.xml"), Charsets.UTF_8);
}
Also used : SimpleSign(ddf.security.samlp.impl.SimpleSign) SystemCrypto(ddf.security.samlp.impl.SystemCrypto) EncryptionService(ddf.security.encryption.EncryptionService) StreamSource(javax.xml.transform.stream.StreamSource) Service(javax.xml.ws.Service) EncryptionService(ddf.security.encryption.EncryptionService) Properties(java.util.Properties) Before(org.junit.Before)

Example 5 with SystemCrypto

use of ddf.security.samlp.impl.SystemCrypto 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);
    idpHandler.setSamlSecurity(new SamlSecurity());
    idpHandler.setAuthContextClasses(Arrays.asList("urn:oasis:names:tc:SAML:2.0:ac:classes:Password", "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport", "urn:oasis:names:tc:SAML:2.0:ac:classes:X509", "urn:oasis:names:tc:SAML:2.0:ac:classes:TLSClient"));
    idpHandler.setSecurityLogger(mock(SecurityLogger.class));
    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 : InputStream(java.io.InputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HttpServletRequest(javax.servlet.http.HttpServletRequest) SimpleSign(ddf.security.samlp.impl.SimpleSign) SystemCrypto(ddf.security.samlp.impl.SystemCrypto) StringWriter(java.io.StringWriter) EncryptionService(ddf.security.encryption.EncryptionService) SamlSecurity(org.codice.ddf.security.jaxrs.impl.SamlSecurity) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Aggregations

SystemCrypto (ddf.security.samlp.impl.SystemCrypto)5 Before (org.junit.Before)5 EncryptionService (ddf.security.encryption.EncryptionService)4 SimpleSign (ddf.security.samlp.impl.SimpleSign)4 InputStream (java.io.InputStream)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 SamlSecurity (org.codice.ddf.security.jaxrs.impl.SamlSecurity)2 SecurityLogger (ddf.security.audit.SecurityLogger)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 StringWriter (java.io.StringWriter)1 Properties (java.util.Properties)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Dispatch (javax.xml.ws.Dispatch)1 Service (javax.xml.ws.Service)1 CryptoType (org.apache.wss4j.common.crypto.CryptoType)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1