Search in sources :

Example 1 with SimpleSign

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

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);
}
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 SimpleSign

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);
}
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 4 with SimpleSign

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

Example 5 with SimpleSign

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);
}
Also used : SessionFactory(ddf.security.http.SessionFactory) RelayStates(ddf.security.samlp.impl.RelayStates) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) HttpSession(javax.servlet.http.HttpSession) LogoutMessageImpl(ddf.security.samlp.impl.LogoutMessageImpl) Element(org.w3c.dom.Element) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SecurityAssertion(ddf.security.assertion.SecurityAssertion) HttpServletRequest(javax.servlet.http.HttpServletRequest) SimpleSign(ddf.security.samlp.impl.SimpleSign) EncryptionService(ddf.security.encryption.EncryptionService) PrincipalHolder(ddf.security.common.PrincipalHolder) Before(org.junit.Before)

Aggregations

SimpleSign (ddf.security.samlp.impl.SimpleSign)5 Before (org.junit.Before)5 EncryptionService (ddf.security.encryption.EncryptionService)4 SystemCrypto (ddf.security.samlp.impl.SystemCrypto)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 SamlSecurity (org.codice.ddf.security.jaxrs.impl.SamlSecurity)2 SecurityAssertion (ddf.security.assertion.SecurityAssertion)1 SecurityLogger (ddf.security.audit.SecurityLogger)1 PrincipalHolder (ddf.security.common.PrincipalHolder)1 SessionFactory (ddf.security.http.SessionFactory)1 LogoutMessageImpl (ddf.security.samlp.impl.LogoutMessageImpl)1 RelayStates (ddf.security.samlp.impl.RelayStates)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 Properties (java.util.Properties)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Dispatch (javax.xml.ws.Dispatch)1 Service (javax.xml.ws.Service)1