Search in sources :

Example 11 with AiravataSecurityException

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);
    }
}
Also used : TrustStoreManager(org.apache.airavata.security.util.TrustStoreManager) AiravataSecurityException(org.apache.airavata.security.AiravataSecurityException) RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException) AiravataSecurityException(org.apache.airavata.security.AiravataSecurityException) CredentialStoreException(org.apache.airavata.credential.store.exception.CredentialStoreException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 12 with AiravataSecurityException

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.");
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) AuthorizationException(org.apache.airavata.model.error.AuthorizationException) AiravataSecurityManager(org.apache.airavata.service.security.AiravataSecurityManager) AiravataSecurityException(org.apache.airavata.security.AiravataSecurityException)

Example 13 with AiravataSecurityException

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;
}
Also used : JSONObject(org.json.JSONObject) GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) JSONArray(org.json.JSONArray) AiravataSecurityException(org.apache.airavata.security.AiravataSecurityException)

Example 14 with AiravataSecurityException

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);
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) AiravataSecurityException(org.apache.airavata.security.AiravataSecurityException)

Example 15 with AiravataSecurityException

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);
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) AiravataSecurityException(org.apache.airavata.security.AiravataSecurityException)

Aggregations

AiravataSecurityException (org.apache.airavata.security.AiravataSecurityException)16 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)8 TrustStoreManager (org.apache.airavata.security.util.TrustStoreManager)5 TException (org.apache.thrift.TException)5 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)4 RemoteException (java.rmi.RemoteException)3 GatewayResourceProfile (org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile)3 AxisFault (org.apache.axis2.AxisFault)3 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 SSLContext (javax.net.ssl.SSLContext)2 CredentialStoreService (org.apache.airavata.credential.store.cpi.CredentialStoreService)2 CredentialStoreException (org.apache.airavata.credential.store.exception.CredentialStoreException)2 PasswordCredential (org.apache.airavata.model.credential.store.PasswordCredential)2 AiravataSecurityManager (org.apache.airavata.service.security.AiravataSecurityManager)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1