use of org.wso2.carbon.core.util.KeyStoreManager in project carbon-apimgt by wso2.
the class UtilTest method testShouldThrowEceptionWhenRetrievingCertificateFails.
@Test(expected = Exception.class)
public void testShouldThrowEceptionWhenRetrievingCertificateFails() throws Exception {
PowerMockito.mockStatic(KeyStoreManager.class);
KeyStoreManager keyStoreManager = Mockito.mock(KeyStoreManager.class);
PowerMockito.when(KeyStoreManager.getInstance(Mockito.anyInt())).thenReturn(keyStoreManager);
Mockito.when(keyStoreManager.getDefaultPrimaryCertificate()).thenThrow(Exception.class);
Mockito.when(keyStoreManager.getDefaultPrivateKey()).thenReturn(privateKey);
Util.getAuthHeader("admin");
}
use of org.wso2.carbon.core.util.KeyStoreManager in project carbon-apimgt by wso2.
the class UtilTest method testShouldSetAuthHeaders.
@Test
public void testShouldSetAuthHeaders() throws Exception {
Options options = new Options();
PowerMockito.mockStatic(KeyStoreManager.class);
KeyStoreManager keyStoreManager = Mockito.mock(KeyStoreManager.class);
ServiceClient serviceClient = Mockito.mock(ServiceClient.class);
PowerMockito.when(KeyStoreManager.getInstance(Mockito.anyInt())).thenReturn(keyStoreManager);
Mockito.when(serviceClient.getOptions()).thenReturn(options);
Mockito.when(keyStoreManager.getDefaultPrimaryCertificate()).thenReturn(null);
Mockito.when(keyStoreManager.getDefaultPrivateKey()).thenReturn(privateKey);
Util.setAuthHeaders(serviceClient, "admin");
}
use of org.wso2.carbon.core.util.KeyStoreManager in project carbon-apimgt by wso2.
the class ServiceReferenceHolder method setPrivateKey.
public void setPrivateKey() {
try {
KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID);
this.privateKey = keyStoreManager.getDefaultPrivateKey();
} catch (Exception e) {
String error = "Error in obtaining keystore";
log.debug(error, e);
}
}
use of org.wso2.carbon.core.util.KeyStoreManager in project carbon-apimgt by wso2.
the class InternalAPIKeyGenerator method buildSignature.
protected void buildSignature(SignedJWT assertion) throws APIManagementException {
// get super tenant's key store manager
KeyStoreManager tenantKSM = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID);
try {
PrivateKey privateKey = tenantKSM.getDefaultPrivateKey();
JWSSigner jwsSigner = new RSASSASigner(privateKey);
assertion.sign(jwsSigner);
} catch (Exception e) {
throw new APIManagementException("Error while signing Api Key", e);
}
}
use of org.wso2.carbon.core.util.KeyStoreManager in project carbon-apimgt by wso2.
the class DefaultApiKeyGenerator method buildHeader.
protected String buildHeader() throws APIManagementException {
Certificate publicCert;
JSONObject headerWithKid;
try {
KeyStoreManager tenantKSM = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID);
publicCert = tenantKSM.getDefaultPrimaryCertificate();
String headerWithoutKid = APIUtil.generateHeader(publicCert, APIConstants.SIGNATURE_ALGORITHM_SHA256_WITH_RSA);
headerWithKid = new JSONObject(headerWithoutKid);
headerWithKid.put("kid", APIUtil.getApiKeyAlias());
} catch (Exception e) {
throw new APIManagementException("Error while building Api key header", e);
}
return headerWithKid.toString();
}
Aggregations