Beispiel #1
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 + "'");
   }
 }
Beispiel #2
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;
 }
Beispiel #3
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);
   }
 }