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());
}
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);
}
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());
}
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);
}
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);
}
Aggregations