Java Code Examples for org.wso2.carbon.apimgt.impl.utils.APIUtil#signJwt()

The following examples show how to use org.wso2.carbon.apimgt.impl.utils.APIUtil#signJwt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractAPIMgtGatewayJWTGenerator.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public byte[] signJWT(String assertion) throws APIManagementException {

        try {
            KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID);
            PrivateKey privateKey = keyStoreManager.getDefaultPrivateKey();
            return APIUtil.signJwt(assertion, privateKey, signatureAlgorithm);
        } catch (Exception e) {
            throw new APIManagementException(e);
        }
    }
 
Example 2
Source File: ApiKeyGenerator.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
private static byte[] buildSignature(String assertion) throws APIManagementException {
    PrivateKey privateKey;
    //get super tenant's key store manager
    KeyStoreManager tenantKSM = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID);
    try {
        privateKey = tenantKSM.getDefaultPrivateKey();
    } catch (Exception e) {
        throw new APIManagementException("Error while signing Api Key", e);
    }
    return APIUtil.signJwt(assertion, privateKey, "SHA256withRSA");
}
 
Example 3
Source File: AbstractJWTGenerator.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public byte[] signJWT(String assertion, String endUserName) throws APIManagementException {

        String tenantDomain = null;

        try {
            //get tenant domain
            tenantDomain = MultitenantUtils.getTenantDomain(endUserName);
            Key privateKey = CertificateMgtUtils.getInstance().getPrivateKey(tenantDomain);
            return APIUtil.signJwt(assertion, (PrivateKey) privateKey, signatureAlgorithm);
        } catch (RegistryException e) {
            String error = "Error in loading tenant registry for " + tenantDomain;
            //do not log
            throw new APIManagementException(error, e);
        }
    }