Search in sources :

Example 1 with GetServiceProviderMetaDataCmd

use of org.apache.cloudstack.api.command.GetServiceProviderMetaDataCmd in project cloudstack by apache.

the class GetServiceProviderMetaDataCmdTest method testAuthenticate.

@Test
public void testAuthenticate() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, CertificateParsingException, CertificateEncodingException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException, UnknownHostException {
    GetServiceProviderMetaDataCmd cmd = new GetServiceProviderMetaDataCmd();
    Field apiServerField = GetServiceProviderMetaDataCmd.class.getDeclaredField("_apiServer");
    apiServerField.setAccessible(true);
    apiServerField.set(cmd, apiServer);
    Field managerField = GetServiceProviderMetaDataCmd.class.getDeclaredField("_samlAuthManager");
    managerField.setAccessible(true);
    managerField.set(cmd, samlAuthManager);
    String spId = "someSPID";
    String url = "someUrl";
    KeyPair kp = SAMLUtils.generateRandomKeyPair();
    X509Certificate cert = SAMLUtils.generateRandomX509Certificate(kp);
    SAMLProviderMetadata providerMetadata = new SAMLProviderMetadata();
    providerMetadata.setEntityId("random");
    providerMetadata.setSigningCertificate(cert);
    providerMetadata.setEncryptionCertificate(cert);
    providerMetadata.setKeyPair(kp);
    providerMetadata.setSsoUrl("http://test.local");
    providerMetadata.setSloUrl("http://test.local");
    Mockito.when(samlAuthManager.getSPMetadata()).thenReturn(providerMetadata);
    String result = cmd.authenticate("command", null, session, InetAddress.getByName("127.0.0.1"), HttpUtils.RESPONSE_TYPE_JSON, new StringBuilder(), req, resp);
    Assert.assertTrue(result.contains("md:EntityDescriptor"));
}
Also used : Field(java.lang.reflect.Field) KeyPair(java.security.KeyPair) SAMLProviderMetadata(org.apache.cloudstack.saml.SAMLProviderMetadata) GetServiceProviderMetaDataCmd(org.apache.cloudstack.api.command.GetServiceProviderMetaDataCmd) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Aggregations

Field (java.lang.reflect.Field)1 KeyPair (java.security.KeyPair)1 X509Certificate (java.security.cert.X509Certificate)1 GetServiceProviderMetaDataCmd (org.apache.cloudstack.api.command.GetServiceProviderMetaDataCmd)1 SAMLProviderMetadata (org.apache.cloudstack.saml.SAMLProviderMetadata)1 Test (org.junit.Test)1