Search in sources :

Example 1 with LogoutRequestBuilder

use of org.opensaml.saml.saml2.core.impl.LogoutRequestBuilder in project ddf by codice.

the class LogoutRequestServiceTest method testSendLogoutRequestGetPostRequest.

@Test
public void testSendLogoutRequestGetPostRequest() throws Exception {
    String encryptedNameIdWithTime = nameId + "\n" + time;
    when(encryptionService.decrypt(any(String.class))).thenReturn(nameId + "\n" + time);
    when(idpMetadata.getSingleLogoutBinding()).thenReturn(SamlProtocol.POST_BINDING);
    when(idpMetadata.getSingleLogoutLocation()).thenReturn(postLogoutUrl);
    LogoutRequest logoutRequest = new LogoutRequestBuilder().buildObject();
    when(logoutMessage.buildLogoutRequest(eq(nameId), anyString())).thenReturn(logoutRequest);
    Response response = logoutRequestService.sendLogoutRequest(encryptedNameIdWithTime);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertTrue("Expected logout url of " + postLogoutUrl, response.getEntity().toString().contains(postLogoutUrl));
}
Also used : LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) Response(javax.ws.rs.core.Response) LogoutRequestBuilder(org.opensaml.saml.saml2.core.impl.LogoutRequestBuilder) LogoutRequest(org.opensaml.saml.saml2.core.LogoutRequest) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with LogoutRequestBuilder

use of org.opensaml.saml.saml2.core.impl.LogoutRequestBuilder in project cloudstack by apache.

the class SAMLUtils method buildLogoutRequest.

public static LogoutRequest buildLogoutRequest(String logoutUrl, String spId, String nameIdString) {
    Issuer issuer = new IssuerBuilder().buildObject();
    issuer.setValue(spId);
    NameID nameID = new NameIDBuilder().buildObject();
    nameID.setValue(nameIdString);
    LogoutRequest logoutRequest = new LogoutRequestBuilder().buildObject();
    logoutRequest.setID(generateSecureRandomId());
    logoutRequest.setDestination(logoutUrl);
    logoutRequest.setVersion(SAMLVersion.VERSION_20);
    logoutRequest.setIssueInstant(new DateTime());
    logoutRequest.setIssuer(issuer);
    logoutRequest.setNameID(nameID);
    return logoutRequest;
}
Also used : NameIDBuilder(org.opensaml.saml2.core.impl.NameIDBuilder) LogoutRequestBuilder(org.opensaml.saml2.core.impl.LogoutRequestBuilder) Issuer(org.opensaml.saml2.core.Issuer) NameID(org.opensaml.saml2.core.NameID) LogoutRequest(org.opensaml.saml2.core.LogoutRequest) IssuerBuilder(org.opensaml.saml2.core.impl.IssuerBuilder) DateTime(org.joda.time.DateTime)

Aggregations

Response (javax.ws.rs.core.Response)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 LogoutRequest (org.opensaml.saml.saml2.core.LogoutRequest)1 LogoutResponse (org.opensaml.saml.saml2.core.LogoutResponse)1 LogoutRequestBuilder (org.opensaml.saml.saml2.core.impl.LogoutRequestBuilder)1 Issuer (org.opensaml.saml2.core.Issuer)1 LogoutRequest (org.opensaml.saml2.core.LogoutRequest)1 NameID (org.opensaml.saml2.core.NameID)1 IssuerBuilder (org.opensaml.saml2.core.impl.IssuerBuilder)1 LogoutRequestBuilder (org.opensaml.saml2.core.impl.LogoutRequestBuilder)1 NameIDBuilder (org.opensaml.saml2.core.impl.NameIDBuilder)1