use of ddf.security.samlp.impl.SimpleSign 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.SimpleSign 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.SimpleSign 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.SimpleSign 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);
}
use of ddf.security.samlp.impl.SimpleSign 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(LogoutMessageImpl.class);
UuidGenerator uuidGenerator = mock(UuidGenerator.class);
doReturn(UUID.randomUUID().toString()).when(uuidGenerator).generateUuid();
doReturn(uuidGenerator).when(logoutMessage).getUuidGenerator();
encryptionService = mock(EncryptionService.class);
Element issuedAssertion = readSamlAssertion().getDocumentElement();
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
SecurityAssertion securityAssertion = mock(SecurityAssertion.class);
principalCollection.add(securityAssertion, "default");
when(securityAssertion.getToken()).thenReturn(issuedAssertion);
PrincipalHolder principalHolder = mock(PrincipalHolder.class);
when(principalHolder.getPrincipals()).thenReturn(principalCollection);
initializeLogoutRequestService();
HttpSession session = mock(HttpSession.class);
when(sessionFactory.getOrCreateSession(request)).thenReturn(session);
when(session.getAttribute(eq(SecurityConstants.SECURITY_TOKEN_KEY))).thenReturn(principalHolder);
when(request.getRequestURL()).thenReturn(new StringBuffer("https://www.url.com/url"));
when(idpMetadata.getSigningCertificate()).thenReturn("signingCertificate");
when(idpMetadata.getSingleLogoutBinding()).thenReturn(SamlProtocol.REDIRECT_BINDING);
when(idpMetadata.getSingleLogoutLocation()).thenReturn(redirectLogoutUrl);
}
Aggregations