private OAuth2Service getOauth2Service() { return (OAuth2Service) PrivilegedCarbonContext .getThreadLocalCarbonContext().getOSGiService(OAuth2Service.class, null); } }
private static OAuth2Service getOauth2Service() { return (OAuth2Service) PrivilegedCarbonContext .getThreadLocalCarbonContext().getOSGiService(OAuth2Service.class, null); }
public static TenantConfigurationManagementService getTenantConfigurationManagementService() { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); TenantConfigurationManagementService tenantConfigurationManagementService = (TenantConfigurationManagementService) ctx.getOSGiService(TenantConfigurationManagementService.class, null); if (tenantConfigurationManagementService == null) { String msg = "Tenant configuration Management service not initialized."; log.error(msg); throw new IllegalStateException(msg); } return tenantConfigurationManagementService; }
public static NotificationManagementService getNotificationManagementService() { NotificationManagementService notificationManagementService; PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); notificationManagementService = (NotificationManagementService) ctx.getOSGiService( NotificationManagementService.class, null); if (notificationManagementService == null) { String msg = "Notification Management service not initialized."; log.error(msg); throw new IllegalStateException(msg); } return notificationManagementService; }
public static DeviceManagementProviderService getDeviceManagementService(int tenantId) { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); ctx.setTenantId(tenantId, true); DeviceManagementProviderService deviceManagementProviderService = (DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null); if (deviceManagementProviderService == null) { String msg = "Device Management provider service has not initialized."; log.error(msg); throw new IllegalStateException(msg); } return deviceManagementProviderService; }
public static ApplicationManagementProviderService getAppManagementService(int tenantId) { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); ctx.setTenantId(tenantId, true); ApplicationManagementProviderService applicationManagementProviderService = (ApplicationManagementProviderService) ctx.getOSGiService(ApplicationManagementProviderService.class, null); if (applicationManagementProviderService == null) { String msg = "Application management service has not initialized."; log.error(msg); throw new IllegalStateException(msg); } return applicationManagementProviderService; }
public static PolicyManagerService getPolicyManagementService(int tenantId) { PolicyManagerService policyManagementService; PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); ctx.setTenantId(tenantId, true); policyManagementService = (PolicyManagerService) ctx.getOSGiService(PolicyManagerService.class, null); if (policyManagementService == null) { String msg = "Policy Management service not initialized."; log.error(msg); throw new IllegalStateException(msg); } return policyManagementService; }
private void setUserDetails(String username) throws org.wso2.carbon.user.api.UserStoreException { String tenantDomain = MultitenantUtils.getTenantDomain(username); PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class, null); if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { if (username.endsWith(SUPER_TENANT_SUFFIX)) { username = username.substring(0, username.length() - SUPER_TENANT_SUFFIX.length()); } } int tenantId = realmService.getTenantManager().getTenantId(tenantDomain); carbonContext.setTenantDomain(tenantDomain); carbonContext.setTenantId(tenantId); carbonContext.setUsername(username); }
private boolean authenticate(String username, String password, RealmService realmService) { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); RegistryService registryService = (RegistryService) carbonContext.getOSGiService(RegistryService.class, null); String tenantDomain = MultitenantUtils.getTenantDomain(username); try { UserRealm userRealm = AnonymousSessionUtil.getRealmByTenantDomain(registryService, realmService, tenantDomain); if (userRealm == null) { log.error(String.format("Can't get the user realm for the tenant domain %s. Invalid domain or unactivated tenant login.", tenantDomain)); return false; } String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username); return userRealm.getUserStoreManager().authenticate(tenantAwareUsername, password); } catch (CarbonException e) { log.error(String.format("Can't get the user realm for the tenant domain %s.", tenantDomain), e); return false; } catch (UserStoreException e) { log.error("Error while authenticating the user against the user store manager", e); return false; } }
public static AuthorizationManager getAuthorizationManager(int tenantId) throws MDMException { RealmService realmService; AuthorizationManager authorizationManager; try { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); ctx.setTenantId(tenantId, true); realmService = (RealmService) ctx.getOSGiService(RealmService.class, null); if (realmService == null) { String msg = "Realm service has not initialized."; log.error(msg); throw new IllegalStateException(msg); } authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager(); } catch (UserStoreException e) { String msg = "Error occurred while retrieving current Authorization manager."; log.error(msg, e); throw new MDMException(msg, e); } return authorizationManager; }
public static UserStoreManager getUserStoreManager(int tenantId) throws MDMException { RealmService realmService; UserStoreManager userStoreManager; try { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); ctx.setTenantId(tenantId, true); realmService = (RealmService) ctx.getOSGiService(RealmService.class, null); if (realmService == null) { String msg = "Realm service has not initialized."; log.error(msg); throw new IllegalStateException(msg); } userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager(); } catch (UserStoreException e) { String msg = "Error occurred while retrieving current user store manager"; log.error(msg, e); throw new MDMException(msg, e); } return userStoreManager; }
private void setRating(App app) throws AppManagementException { try { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); SocialActivityService socialActivityService = (SocialActivityService) carbonContext.getOSGiService(org.wso2.carbon.social.core.service.SocialActivityService.class, null); JsonObject rating = socialActivityService.getRating(app.getType() + ":" + app.getUUID()); if(rating != null && rating.get("rating") != null){ app.setRating(rating.get("rating").getAsFloat()); } } catch (SocialActivityException e) { String errorMessage = String.format("Can't get the rating for the app '%s:%s'", app.getType(), app.getUUID()); log.error(errorMessage, e); throw new AppManagementException(errorMessage, e); } }
public static int getTenantId(String tenantDomain) throws MDMException { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null); try { return realmService.getTenantManager().getTenantId(tenantDomain); } catch (UserStoreException e) { throw new MDMException( "Error obtaining tenant id from tenant domain " + tenantDomain); } }
/** * This is to send clusterMessage to inform other nodes about subscription added to the system, so that everyone can add new one. * @param topicName * @param subsciptionID * @param tenantID * @param tenantName * @throws ClusteringFault */ public static void sendAddSubscriptionClusterMessage(String topicName,String subsciptionID, int tenantID, String tenantName) throws ClusteringFault{ ConfigurationContextService configContextService = (ConfigurationContextService) PrivilegedCarbonContext .getThreadLocalCarbonContext().getOSGiService(ConfigurationContextService.class); ConfigurationContext configContext = configContextService.getServerConfigContext(); ClusteringAgent agent = configContext.getAxisConfiguration().getClusteringAgent(); agent.sendMessage(new SubscriptionClusterMessage(topicName,subsciptionID,tenantID, tenantName), false); }
public static boolean isExistingRole(String roleName) { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class, null); try { String tenantDomainName = RestApiUtil.getLoggedInUserTenantDomain(); int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId( tenantDomainName); UserRealm realm = realmService.getTenantUserRealm(tenantId); UserStoreManager manager = realm.getUserStoreManager(); return manager.isExistingRole(roleName); } catch (UserStoreException e) { log.error(e); return false; } }
public static boolean isExistingUser(String username) { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class, null); try { String tenantDomainName = RestApiUtil.getLoggedInUserTenantDomain(); int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId( tenantDomainName); UserRealm realm = realmService.getTenantUserRealm(tenantId); UserStoreManager manager = realm.getUserStoreManager(); return manager.isExistingUser(username); } catch (UserStoreException e) { log.error(e); return false; } }
ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
/** * @param context context with user data * @return * @throws org.wso2.carbon.registry.core.exceptions.RegistryException */ private Registry acquireGregRepository(CallContext context, String tenantDomain, String uName) throws RegistryException, AxisFault { UserRegistry userRegistry = null; try{ PrivilegedCarbonContext.getThreadLocalCarbonContext().startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); RegistryService registryService = (RegistryService) PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(RegistryService.class); //userRegistry = registryService.getRegistry(username, password); userRegistry = registryService.getRegistry(uName, context.getPassword(), PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); } catch (RegistryException e) { log.error("unable to create registry instance for the respective enduser", e); } finally { PrivilegedCarbonContext.getThreadLocalCarbonContext().endTenantFlow(); } return userRegistry; }
RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class, null);
if (eventSinkService == null) { Object serviceObject = PrivilegedCarbonContext .getThreadLocalCarbonContext().getOSGiService(EventSinkService.class); if (serviceObject instanceof EventSinkService) { eventSinkService = (EventSinkService) serviceObject;