use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class APIProviderImpl method deleteSharedScope.
/**
* Delete shared scope.
*
* @param scopeName Shared scope name
* @param tenantDomain tenant domain
* @throws APIManagementException If failed to delete the scope
*/
@Override
public void deleteSharedScope(String scopeName, String tenantDomain) throws APIManagementException {
if (log.isDebugEnabled()) {
log.debug("Deleting shared scope " + scopeName);
}
Map<String, KeyManagerDto> tenantKeyManagers = KeyManagerHolder.getTenantKeyManagers(tenantDomain);
for (Map.Entry<String, KeyManagerDto> keyManagerEntry : tenantKeyManagers.entrySet()) {
KeyManager keyManager = keyManagerEntry.getValue().getKeyManager();
if (keyManager != null) {
try {
keyManager.deleteScope(scopeName);
} catch (APIManagementException e) {
log.error("Error while Deleting Shared Scope " + scopeName + " from Key Manager " + keyManagerEntry.getKey(), e);
}
}
}
apiMgtDAO.deleteSharedScope(scopeName, tenantDomain);
deleteScope(scopeName, APIUtil.getTenantIdFromTenantDomain(tenantDomain));
}
use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class APIProviderImpl method addURITemplates.
/**
* Add URI templates for the API.
*
* @param apiId API Id
* @param api API
* @param tenantId Tenant Id
* @throws APIManagementException if fails to add URI templates for the API
*/
private void addURITemplates(int apiId, API api, int tenantId) throws APIManagementException {
String tenantDomain = APIUtil.getTenantDomainFromTenantId(tenantId);
apiMgtDAO.addURITemplates(apiId, api, tenantId);
Map<String, KeyManagerDto> tenantKeyManagers = KeyManagerHolder.getTenantKeyManagers(tenantDomain);
for (Map.Entry<String, KeyManagerDto> keyManagerDtoEntry : tenantKeyManagers.entrySet()) {
KeyManager keyManager = keyManagerDtoEntry.getValue().getKeyManager();
if (keyManager != null) {
try {
keyManager.attachResourceScopes(api, api.getUriTemplates());
} catch (APIManagementException e) {
log.error("Error while Attaching Resource to scope in Key Manager " + keyManagerDtoEntry.getKey(), e);
}
}
}
}
use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class APIProviderImpl method addSharedScope.
/**
* Add Shared Scope by registering it in the KM and adding the scope as a Shared Scope in AM DB.
*
* @param scope Shared Scope
* @param tenantDomain Tenant domain
* @return UUId of the added Shared Scope object
* @throws APIManagementException if failed to add a scope
*/
@Override
public String addSharedScope(Scope scope, String tenantDomain) throws APIManagementException {
Set<Scope> scopeSet = new HashSet<>();
scopeSet.add(scope);
int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
addScopes(scopeSet, tenantId);
Map<String, KeyManagerDto> tenantKeyManagers = KeyManagerHolder.getTenantKeyManagers(tenantDomain);
for (Map.Entry<String, KeyManagerDto> keyManagerDtoEntry : tenantKeyManagers.entrySet()) {
KeyManager keyManager = keyManagerDtoEntry.getValue().getKeyManager();
if (keyManager != null) {
try {
keyManager.registerScope(scope);
} catch (APIManagementException e) {
log.error("Error occurred while registering Scope in Key Manager " + keyManagerDtoEntry.getKey(), e);
}
}
if (log.isDebugEnabled()) {
log.debug("Adding shared scope mapping: " + scope.getKey() + " to Key Manager : " + keyManagerDtoEntry.getKey());
}
}
return ApiMgtDAO.getInstance().addSharedScope(scope, tenantDomain);
}
use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class JWTValidationServiceImpl method validateJWTToken.
@Override
public JWTValidationInfo validateJWTToken(SignedJWTInfo signedJWTInfo) throws APIManagementException {
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
JWTValidationInfo jwtValidationInfo = new JWTValidationInfo();
String issuer = signedJWTInfo.getJwtClaimsSet().getIssuer();
if (StringUtils.isNotEmpty(issuer)) {
KeyManagerDto keyManagerDto = KeyManagerHolder.getKeyManagerByIssuer(tenantDomain, issuer);
if (keyManagerDto != null && keyManagerDto.getJwtValidator() != null) {
JWTValidationInfo validationInfo = keyManagerDto.getJwtValidator().validateToken(signedJWTInfo);
validationInfo.setKeyManager(keyManagerDto.getName());
return validationInfo;
}
}
jwtValidationInfo.setValid(false);
jwtValidationInfo.setValidationCode(APIConstants.KeyValidationStatus.API_AUTH_GENERAL_ERROR);
return jwtValidationInfo;
}
use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class JWTValidationServiceImpl method getKeyManagerNameIfJwtValidatorExist.
@Override
public String getKeyManagerNameIfJwtValidatorExist(SignedJWTInfo signedJWTInfo) throws APIManagementException {
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String issuer = signedJWTInfo.getJwtClaimsSet().getIssuer();
KeyManagerDto keyManagerDto = KeyManagerHolder.getKeyManagerByIssuer(tenantDomain, issuer);
if (keyManagerDto != null && keyManagerDto.getJwtValidator() != null) {
return keyManagerDto.getName();
} else {
return null;
}
}
Aggregations