Esempio n. 1
0
 public static synchronized String loadFromSecureVault(String alias) {
   if (secretResolver == null) {
     secretResolver = SecretResolverFactory.create((OMElement) null, false);
     secretResolver.init(
         DataServicesDSComponent.getSecretCallbackHandlerService().getSecretCallbackHandler());
   }
   return secretResolver.resolve(alias);
 }
Esempio n. 2
0
 public static String getTenantDomainFromId(int tid) {
   try {
     return DataServicesDSComponent.getRealmService()
         .getTenantManager()
         .getTenant(tid)
         .getDomain();
   } catch (UserStoreException e) {
     throw new RuntimeException(e);
   }
 }
Esempio n. 3
0
 /**
  * Creates and returns an InputStream from the file path / http location given.
  *
  * @throws DataServiceFault
  * @see InputStream
  */
 public static InputStream getInputStreamFromPath(String path)
     throws IOException, DataServiceFault {
   InputStream ins;
   if (path.startsWith("http://")) {
     /* This is a url file path */
     URL url = new URL(path);
     ins = url.openStream();
   } else if (isRegistryPath(path)) {
     try {
       RegistryService registryService = DataServicesDSComponent.getRegistryService();
       if (registryService == null) {
         throw new DataServiceFault(
             "DBUtils.getInputStreamFromPath(): Registry service is not available");
       }
       Registry registry;
       if (path.startsWith(DBConstants.CONF_REGISTRY_PATH_PREFIX)) {
         if (path.length() > DBConstants.CONF_REGISTRY_PATH_PREFIX.length()) {
           path = path.substring(DBConstants.CONF_REGISTRY_PATH_PREFIX.length());
           registry = registryService.getConfigSystemRegistry(getCurrentTenantId());
         } else {
           throw new DataServiceFault("Empty configuration registry path given");
         }
       } else {
         if (path.length() > DBConstants.GOV_REGISTRY_PATH_PREFIX.length()) {
           path = path.substring(DBConstants.GOV_REGISTRY_PATH_PREFIX.length());
           registry = registryService.getGovernanceSystemRegistry(getCurrentTenantId());
         } else {
           throw new DataServiceFault("Empty governance registry path given");
         }
       }
       if (registry.resourceExists(path)) {
         Resource serviceResource = registry.get(path);
         ins = serviceResource.getContentStream();
       } else {
         throw new DataServiceFault(
             "The given XSLT resource path at '" + path + "' does not exist");
       }
     } catch (RegistryException e) {
       String msg = "Error in retrieving the resource: " + path;
       log.error(msg, e);
       throw new DataServiceFault(e, msg);
     }
   } else {
     File csvFile = new File(path);
     if (path.startsWith("." + File.separator) || path.startsWith(".." + File.separator)) {
       /* this is a relative path */
       path = csvFile.getAbsolutePath();
     }
     /* local file */
     ins = new FileInputStream(path);
   }
   return ins;
 }
Esempio n. 4
0
 public static boolean authenticate(String username, String password) throws DataServiceFault {
   try {
     RegistryService registryService = DataServicesDSComponent.getRegistryService();
     UserRealm realm =
         registryService.getUserRealm(
             PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
     username = MultitenantUtils.getTenantAwareUsername(username);
     return realm.getUserStoreManager().authenticate(username, password);
   } catch (Exception e) {
     throw new DataServiceFault(e, "Error in authenticating user '" + username + "'");
   }
 }
Esempio n. 5
0
 /**
  * Retrieves the current user's roles given the username.
  *
  * @param username The username
  * @return The user roles
  * @throws DataServiceFault
  */
 public static String[] getUserRoles(String username) throws DataServiceFault {
   RealmService realmService = DataServicesDSComponent.getRealmService();
   RegistryService registryService = DataServicesDSComponent.getRegistryService();
   username = MultitenantUtils.getTenantAwareUsername(username);
   String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
   int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
   username = MultitenantUtils.getTenantAwareUsername(username);
   try {
     if (tenantId < MultitenantConstants.SUPER_TENANT_ID) {
       tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
     }
     if (tenantId < MultitenantConstants.SUPER_TENANT_ID) {
       /* the tenant doesn't exist. */
       log.error("The tenant doesn't exist. Tenant domain:" + tenantDomain);
       throw new DataServiceFault("Access Denied. You are not authorized.");
     }
     if (!realmService.getTenantManager().isTenantActive(tenantId)) {
       /* the tenant is not active. */
       log.error("The tenant is not active. Tenant domain:" + tenantDomain);
       throw new DataServiceFault("The tenant is not active. Tenant domain:" + tenantDomain);
     }
     UserRealm realm = registryService.getUserRealm(tenantId);
     String roles[] = realm.getUserStoreManager().getRoleListOfUser(username);
     return roles;
   } catch (Exception e) {
     String msg =
         "Error in retrieving the realm for the tenant id: "
             + tenantId
             + ", username: "******". "
             + e.getMessage();
     log.error(msg);
     throw new DataServiceFault(msg);
   }
 }
Esempio n. 6
0
 private static Connection createConnection(String dataSourceId)
     throws SQLException, DataServiceFault {
   DataSourceService dataSourceService = DataServicesDSComponent.getDataSourceService();
   CarbonDataSource cds;
   try {
     cds = dataSourceService.getDataSource(dataSourceId);
   } catch (DataSourceException e) {
     throw new DataServiceFault(e, "Error in retrieving data source: " + e.getMessage());
   }
   if (cds == null) {
     throw new DataServiceFault("DataSource '" + dataSourceId + "' is not available.");
   }
   Object ds = cds.getDSObject();
   if (!(ds instanceof DataSource)) {
     throw new DataServiceFault("DataSource '" + dataSourceId + "' is not an RDBMS data source.");
   }
   return ((DataSource) ds).getConnection();
 }