use of org.apache.airavata.security.AiravataSecurityException in project airavata by apache.
the class KeyCloakSecurityManager method initializeSecurityInfra.
/**
* Implement this method in your SecurityManager to perform necessary initializations at the server startup.
*
* @throws AiravataSecurityException
*/
@Override
public void initializeSecurityInfra() throws AiravataSecurityException {
try {
// initialize SSL context with the trust store that contains the public cert of WSO2 Identity Server.
TrustStoreManager trustStoreManager = new TrustStoreManager();
trustStoreManager.initializeTrustStoreManager(ServerSettings.getTrustStorePath(), ServerSettings.getTrustStorePassword());
} catch (Exception e) {
throw new AiravataSecurityException(e.getMessage(), e);
}
}
use of org.apache.airavata.security.AiravataSecurityException in project airavata by apache.
the class SecurityInterceptor method authorize.
private void authorize(AuthzToken authzToken, Map<String, String> metaData) throws AuthorizationException {
try {
boolean isAPISecured = ServerSettings.isAPISecured();
if (isAPISecured) {
AiravataSecurityManager securityManager = SecurityManagerFactory.getSecurityManager();
boolean isAuthz = securityManager.isUserAuthorized(authzToken, metaData);
if (!isAuthz) {
throw new AuthorizationException("User is not authenticated or authorized.");
}
}
} catch (AiravataSecurityException e) {
logger.error(e.getMessage(), e);
throw new AuthorizationException("Error in authenticating or authorizing user.");
} catch (ApplicationSettingsException e) {
logger.error(e.getMessage(), e);
throw new AuthorizationException("Internal error in authenticating or authorizing user.");
}
}
use of org.apache.airavata.security.AiravataSecurityException in project airavata by apache.
the class KeyCloakSecurityManager method getUserRolesFromOAuthToken.
private String[] getUserRolesFromOAuthToken(String username, String token, String gatewayId) throws Exception {
GatewayResourceProfile gwrp = getRegistryServiceClient().getGatewayResourceProfile(gatewayId);
String identityServerRealm = gwrp.getIdentityServerTenant();
String openIdConnectUrl = getOpenIDConfigurationUrl(identityServerRealm);
JSONObject openIdConnectConfig = new JSONObject(getFromUrl(openIdConnectUrl, token));
String userInfoEndPoint = openIdConnectConfig.getString("userinfo_endpoint");
JSONObject userInfo = new JSONObject(getFromUrl(userInfoEndPoint, token));
if (!username.equals(userInfo.get("preferred_username"))) {
throw new AiravataSecurityException("Subject name and username for the token doesn't match");
}
String userId = userInfo.getString("sub");
String userRoleMappingUrl = ServerSettings.getRemoteIDPServiceUrl() + "/admin/realms/" + identityServerRealm + "/users/" + userId + "/role-mappings/realm";
JSONArray roleMappings = new JSONArray(getFromUrl(userRoleMappingUrl, getAdminAccessToken(gatewayId)));
String[] roles = new String[roleMappings.length()];
for (int i = 0; i < roleMappings.length(); i++) {
roles[i] = (new JSONObject(roleMappings.get(i).toString())).get("name").toString();
}
return roles;
}
use of org.apache.airavata.security.AiravataSecurityException in project airavata by apache.
the class SecurityManagerFactory method getSecurityManager.
public static AiravataSecurityManager getSecurityManager() throws AiravataSecurityException {
try {
Class secManagerImpl = Class.forName(ServerSettings.getSecurityManagerClassName());
AiravataSecurityManager securityManager = (AiravataSecurityManager) secManagerImpl.newInstance();
return securityManager;
} catch (ClassNotFoundException e) {
String error = "Security Manager class could not be found.";
logger.error(e.getMessage(), e);
throw new AiravataSecurityException(error);
} catch (ApplicationSettingsException e) {
String error = "Error in reading the configuration related to Security Manager class.";
logger.error(e.getMessage(), e);
throw new AiravataSecurityException(error);
} catch (InstantiationException e) {
String error = "Error in instantiating the Security Manager class.";
logger.error(e.getMessage(), e);
throw new AiravataSecurityException(error);
} catch (IllegalAccessException e) {
String error = "Error in instantiating the Security Manager class.";
logger.error(e.getMessage(), e);
throw new AiravataSecurityException(error);
}
}
use of org.apache.airavata.security.AiravataSecurityException in project airavata by apache.
the class AuthzCacheManagerFactory method getAuthzCacheManager.
public static AuthzCacheManager getAuthzCacheManager() throws AiravataSecurityException {
try {
Class authzCacheManagerImpl = Class.forName(ServerSettings.getAuthzCacheManagerClassName());
AuthzCacheManager authzCacheManager = (AuthzCacheManager) authzCacheManagerImpl.newInstance();
return authzCacheManager;
} catch (ClassNotFoundException e) {
String error = "Authorization Cache Manager class could not be found.";
logger.error(e.getMessage(), e);
throw new AiravataSecurityException(error);
} catch (ApplicationSettingsException e) {
String error = "Error in reading the configuration related to Authorization Cache Manager class.";
logger.error(e.getMessage(), e);
throw new AiravataSecurityException(error);
} catch (InstantiationException e) {
String error = "Error in instantiating the Authorization Cache Manager class.";
logger.error(e.getMessage(), e);
throw new AiravataSecurityException(error);
} catch (IllegalAccessException e) {
String error = "Error in instantiating the Authorization Cache Manager class.";
logger.error(e.getMessage(), e);
throw new AiravataSecurityException(error);
}
}
Aggregations