org.wso2.carbon.CarbonException Java Examples
The following examples show how to use
org.wso2.carbon.CarbonException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OutboundProvisioningManager.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * @param provisioningEntity * @param provisionByRoleList * @param tenantDomain * @return * @throws CarbonException * @throws UserStoreException */ protected boolean canUserBeProvisioned(ProvisioningEntity provisioningEntity, String[] provisionByRoleList, String tenantDomain) throws UserStoreException, CarbonException { if (provisioningEntity.getEntityType() != ProvisioningEntityType.USER || provisionByRoleList == null || provisionByRoleList.length == 0) { // we apply restrictions only for users. // if service provider's out-bound provisioning configuration does not define any roles // to be provisioned then we apply no restrictions. return true; } String userName = getUserName(provisioningEntity.getAttributes()); List<String> roleListOfUser = getUserRoles(userName, tenantDomain); for (String provisionByRole : provisionByRoleList) { if (roleListOfUser.contains(provisionByRole)) { return true; } } return false; }
Example #2
Source File: IdentityTenantUtil.java From carbon-identity with Apache License 2.0 | 6 votes |
public static Registry getRegistry(String domainName, String username) throws IdentityException { HttpSession httpSess = getHttpSession(); if (httpSess != null) { if (httpSess.getAttribute(ServerConstants.USER_LOGGED_IN) != null) { try { return AdminServicesUtil.getSystemRegistry(); } catch (CarbonException e) { log.error("Error obtaining a registry instance", e); throw IdentityException.error( "Error obtaining a registry instance", e); } } } return getRegistryForAnonymousSession(domainName, username); }
Example #3
Source File: UIBundleDeployer.java From attic-stratos with Apache License 2.0 | 6 votes |
private void processFileUploadExecutorDefinitions(Component component , String action) throws CarbonException{ if (component.getFileUploadExecutorConfigs() != null && component.getFileUploadExecutorConfigs().length > 0) { FileUploadExecutorManager executorManager = (FileUploadExecutorManager) fileUploadExecManagerTracker.getService(); if (executorManager == null) { log.error("FileUploadExecutorManager service is not available"); return; } FileUploadExecutorConfig[] executorConfigs = component.getFileUploadExecutorConfigs(); for (FileUploadExecutorConfig executorConfig : executorConfigs) { String[] mappingActions = executorConfig.getMappingActionList(); for (String mappingAction : mappingActions) { if (CarbonConstants.ADD_UI_COMPONENT.equals(action)) { executorManager.addExecutor(mappingAction, executorConfig.getFUploadExecClass()); } else if (CarbonConstants.REMOVE_UI_COMPONENT.equals(action)) { executorManager.removeExecutor(mappingAction); } } } } }
Example #4
Source File: IdentityTenantUtil.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
public static Registry getRegistry(String domainName, String username) throws IdentityException { HttpSession httpSess = getHttpSession(); if (httpSess != null) { if (httpSess.getAttribute(ServerConstants.USER_LOGGED_IN) != null) { try { return AdminServicesUtil.getSystemRegistry(); } catch (CarbonException e) { log.error("Error obtaining a registry instance", e); throw IdentityException.error( "Error obtaining a registry instance", e); } } } return getRegistryForAnonymousSession(domainName, username); }
Example #5
Source File: XMPPConfigurationService.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Get the IM Address of an user to populate the IM field of XMPP Configuration page. * * @param userId * @return * @throws IdentityProviderException */ public String getUserIM(String userId) throws IdentityProviderException { String message = "Invalid parameters provided to hasXMPPSettings"; validateInputParameters(new String[] { userId }, message); checkUserAuthorization(userId, "hasXMPPSettings"); Map<String, String> claimValues = null; try { UserStoreManager userStore = AdminServicesUtil.getUserRealm().getUserStoreManager(); String[] imClaim = { UserCoreConstants.ClaimTypeURIs.IM }; claimValues = userStore.getUserClaimValues(userId, imClaim, UserCoreConstants.DEFAULT_PROFILE); } catch (UserStoreException | CarbonException e) { throw new IdentityProviderException("Failed to get claims for user " + userId); } if (claimValues.containsKey(UserCoreConstants.ClaimTypeURIs.IM)) { return claimValues.get(UserCoreConstants.ClaimTypeURIs.IM); } else { return null; } }
Example #6
Source File: IdentityTenantUtil.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private static Registry getRegistryForAnonymousSession(String domainName, String username) throws IdentityException { try { if (domainName == null && username == null) { domainName = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; } if (username == null) { return AnonymousSessionUtil.getSystemRegistryByDomainName(registryService, realmService, domainName); } else { return AnonymousSessionUtil.getSystemRegistryByUserName(registryService, realmService, username); } } catch (CarbonException e) { log.error("Error obtaining a registry instance", e); throw IdentityException.error("Error obtaining a registry instance", e); } }
Example #7
Source File: IdentityTenantUtil.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private static UserRealm getRealmForAnonymousSession(String domainName, String username) throws IdentityException { try { if (username != null) { return AnonymousSessionUtil.getRealmByUserName(registryService, realmService, username); } if (domainName == null) { domainName = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; } return AnonymousSessionUtil.getRealmByTenantDomain(registryService, realmService, domainName); } catch (CarbonException e) { throw IdentityException.error("Error Obtaining a realm for user name: " + username + " and " + "domain:" + domainName, e); } }
Example #8
Source File: ComponentBuilder.java From attic-stratos with Apache License 2.0 | 6 votes |
public static Component build(InputStream componentIn, String componentName, String componentVersion, BundleContext bundleContext) throws CarbonException, XMLStreamException { XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(componentIn); StAXOMBuilder builder = new StAXOMBuilder(streamReader); OMElement document = builder.getDocumentElement(); Component component = new Component(); component.setName(componentName); component.setVersion(componentVersion); processMenus(componentName, document, component); processServlets(document, component); processFileUploadConfigs(document, component); processCustomUIs(document, component); processOSGiServices(document, bundleContext); processFrameworkConfiguration(document, component); processContextConfiguration(componentName, document, component); return component; }
Example #9
Source File: UserProfileUIUtil.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Check whether the account is attached with account lock bypassable role. * * @param userName user name whos roles needs to be listed * @return true or false based on user roles * @throws CarbonException, UserStoreException */ public static boolean isAccountLockable(String userName) throws CarbonException, UserStoreException { boolean isLockable = true; String[] roleList = AdminServicesUtil.getUserRealm().getUserStoreManager().getRoleListOfUser(userName); if (roleList != null) { for (String roleName : roleList) { if (roleName.equals(bypassRoleName)) { isLockable = false; break; } } } return isLockable; }
Example #10
Source File: IdentityTenantUtil.java From carbon-identity with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private static Registry getRegistryForAnonymousSession(String domainName, String username) throws IdentityException { try { if (domainName == null && username == null) { domainName = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; } if (username == null) { return AnonymousSessionUtil.getSystemRegistryByDomainName(registryService, realmService, domainName); } else { return AnonymousSessionUtil.getSystemRegistryByUserName(registryService, realmService, username); } } catch (CarbonException e) { log.error("Error obtaining a registry instance", e); throw IdentityException.error("Error obtaining a registry instance", e); } }
Example #11
Source File: IdentityTenantUtil.java From carbon-identity with Apache License 2.0 | 6 votes |
private static UserRealm getRealmForAnonymousSession(String domainName, String username) throws IdentityException { try { if (domainName == null && username == null) { domainName = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; } if (username == null) { return AnonymousSessionUtil.getRealmByTenantDomain(registryService, realmService, domainName); } else if (username != null) { return AnonymousSessionUtil.getRealmByUserName(registryService, realmService, username); } } catch (CarbonException e) { log.error("Error obtaining the realm", e); throw IdentityException.error("Error Obtaining a realm", e); } return null; }
Example #12
Source File: Util.java From carbon-commons with Apache License 2.0 | 5 votes |
/** * Get generic location to write a file with the given suffix. * * @param suffix should be given with dot; ex: .xml, .wsdl * @return */ public static FileInfo getOutputFileLocation(String suffix) throws CarbonException { String uuid = String.valueOf(System.currentTimeMillis() + Math.random()); String extraFileLocation = MessageContext. getCurrentMessageContext(). getConfigurationContext().getProperty("WORK_DIR") + File.separator + "extra" + File.separator + uuid + File.separator; File dirs = new File(extraFileLocation); if (!dirs.exists() && !dirs.mkdirs()) { throw new CarbonException("Unable to create directory " + dirs.getName()); } File outFile = new File(extraFileLocation, uuid + suffix); return new FileInfo(uuid, outFile); }
Example #13
Source File: OutboundProvisioningManager.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * @param userName * @param tenantDomain * @return * @throws CarbonException * @throws UserStoreException */ private Map<String, String> getUserClaims(String userName, String tenantDomain) throws CarbonException, UserStoreException { Map<String, String> inboundAttributes = new HashMap<>(); RegistryService registryService = IdentityProvisionServiceComponent.getRegistryService(); RealmService realmService = IdentityProvisionServiceComponent.getRealmService(); UserRealm realm = AnonymousSessionUtil.getRealmByTenantDomain(registryService, realmService, tenantDomain); UserStoreManager userstore = null; userstore = realm.getUserStoreManager(); Claim[] claimArray = null; try { claimArray = userstore.getUserClaimValues(userName, null); } catch (UserStoreException e) { if (e.getMessage().contains("UserNotFound")) { if (log.isDebugEnabled()) { log.debug("User " + userName + " not found in user store"); } } else { throw e; } } if (claimArray != null) { for (Claim claim : claimArray) { inboundAttributes.put(claim.getClaimUri(), claim.getValue()); } } return inboundAttributes; }
Example #14
Source File: PostAuthnMissingClaimHandler.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
private UserRealm getUserRealm(String tenantDomain) throws PostAuthenticationFailedException { UserRealm realm; try { realm = AnonymousSessionUtil.getRealmByTenantDomain( FrameworkServiceComponent.getRegistryService(), FrameworkServiceComponent.getRealmService(), tenantDomain); } catch (CarbonException e) { throw new PostAuthenticationFailedException("Error while handling missing mandatory claims", "Error occurred while retrieving the Realm for " + tenantDomain + " to handle local claims", e); } return realm; }
Example #15
Source File: XmlConfiguration.java From carbon-identity with Apache License 2.0 | 5 votes |
public XmlConfiguration(InputStream xmlFile, String serverNamespace) throws CarbonException { if (serverNamespace != null) { this.serverNamespace = serverNamespace; } try { builder = new StAXOMBuilder(xmlFile); builder.getDocumentElement().build(); } catch (Exception e) { String msg = "Error occurred while trying to instantiate StAXOMBuilder for XML file " + xmlFile; log.error(msg, e); throw new CarbonException(msg, e); } }
Example #16
Source File: IdentityTenantUtil.java From carbon-identity with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") public static Registry getRegistry() throws IdentityException { try { return AdminServicesUtil.getSystemRegistry(); } catch (CarbonException e) { log.error("Error obtaining a registry instance", e); throw IdentityException.error("Error obtaining a registry instance", e); } }
Example #17
Source File: UserProfileAdmin.java From carbon-identity with Apache License 2.0 | 5 votes |
private boolean isAuthorized(String targetUser) throws UserStoreException, CarbonException { boolean isAuthrized = false; MessageContext msgContext = MessageContext.getCurrentMessageContext(); HttpServletRequest request = (HttpServletRequest) msgContext .getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); HttpSession httpSession = request.getSession(false); if (httpSession != null) { String userName = (String) httpSession.getAttribute(ServerConstants.USER_LOGGED_IN); isAuthrized = UserProfileUtil.isUserAuthorizedToConfigureProfile(getUserRealm(), userName, targetUser); } return isAuthrized; }
Example #18
Source File: BasicAuthenticationInterceptor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * This method authenticates the request using Basic authentication and validate the roles of user based on * roles of scope. * * @param inMessage cxf Message * @param username username in basic auth header * @param password password in basic auth header * @return true if user is successfully authenticated and authorized. false otherwise. */ private boolean authenticate(Message inMessage, String username, String password) { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class, null); RegistryService registryService = (RegistryService) carbonContext.getOSGiService(RegistryService.class, null); String tenantDomain = MultitenantUtils.getTenantDomain(username); int tenantId; UserRealm userRealm; try { tenantId = realmService.getTenantManager().getTenantId(tenantDomain); userRealm = AnonymousSessionUtil.getRealmByTenantDomain(registryService, realmService, tenantDomain); if (userRealm == null) { log.error("Authentication failed: invalid domain or unactivated tenant login"); return false; } //if authenticated if (userRealm.getUserStoreManager() .authenticate(MultitenantUtils.getTenantAwareUsername(username), password)) { //set the correct tenant info for downstream code. carbonContext.setTenantDomain(tenantDomain); carbonContext.setTenantId(tenantId); carbonContext.setUsername(username); if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { APIUtil.loadTenantConfigBlockingMode(tenantDomain); } return validateRoles(inMessage, userRealm, tenantDomain, username); } else { log.error("Authentication failed: Invalid credentials"); } } catch (UserStoreException | CarbonException e) { log.error("Error occurred while authenticating user: " + username, e); } return false; }
Example #19
Source File: XmlConfiguration.java From carbon-identity with Apache License 2.0 | 5 votes |
public XmlConfiguration(String xmlFile, String serverNamespace) throws CarbonException { if (serverNamespace != null) { this.serverNamespace = serverNamespace; } try { builder = new StAXOMBuilder(xmlFile); builder.getDocumentElement().build(); } catch (Exception e) { String msg = "Error occurred while trying to instantiate StAXOMBuilder for XML file " + xmlFile; log.error(msg, e); throw new CarbonException(msg, e); } }
Example #20
Source File: UIBundleDeployer.java From attic-stratos with Apache License 2.0 | 5 votes |
/** * 1)Search for the UIBundle header * 2)Check for UI bundle fragments - for backward compatibility * * @param bundle * @param action * @throws CarbonException */ private void processUIBundle(Bundle bundle, String action) throws CarbonException { Dictionary headers = bundle.getHeaders(); String value = (String) headers.get("Carbon-Component"); if (value != null && "UIBundle".equals(value)) { //this is a UI Bundle if (CarbonConstants.ADD_UI_COMPONENT.equals(action)) { if(log.isDebugEnabled()){ log.debug("UI component add action received in UIBundleDeployer : "+action); } if(log.isDebugEnabled()){ log.debug("Adding bundle resource paths : "+ bundle ); } bundleBasedUIResourceProvider.addBundleResourcePaths(bundle); if(log.isDebugEnabled()){ log.debug("processComponentXML in : "+ bundle +" "+action); } processComponentXML(bundle, action); } else if (CarbonConstants.REMOVE_UI_COMPONENT.equals(action)){ if(log.isDebugEnabled()){ log.debug("UI component add action received in UIBundleDeployer : "+action); } if(log.isDebugEnabled()){ log.debug("Removing bundle resource paths : "+ bundle ); } bundleBasedUIResourceProvider.removeBundleResourcePaths(bundle); if(log.isDebugEnabled()){ log.debug("processComponentXML in : "+ bundle +" "+action); } processComponentXML(bundle, action); } } }
Example #21
Source File: FileUploadServlet.java From attic-stratos with Apache License 2.0 | 5 votes |
public void init(ServletConfig servletConfig) throws ServletException { this.servletConfig = servletConfig; try { fileUploadExecutorManager = new FileUploadExecutorManager(bundleContext, configContext, webContext); //Registering FileUploadExecutor Manager as an OSGi service bundleContext.registerService(FileUploadExecutorManager.class.getName(), fileUploadExecutorManager, null); } catch (CarbonException e) { log.error("Exception occurred while trying to initialize FileUploadServlet", e); throw new ServletException(e); } }
Example #22
Source File: FileDownloadServlet.java From attic-stratos with Apache License 2.0 | 5 votes |
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { try { fileDownloadUtil.acquireResource(configContextService, req, res); } catch (CarbonException e) { String msg = "Cannot download file"; log.error(msg, e); throw new ServletException(e); } }
Example #23
Source File: AnyFileUploadExecutor.java From attic-stratos with Apache License 2.0 | 5 votes |
public boolean execute(HttpServletRequest request, HttpServletResponse response) throws CarbonException, IOException { try { return super.executeCommon(request, response); } catch (FileUploadException e) { e.printStackTrace(); //Todo: change body of catch statement use File | Settings | File Templates. } return false; }
Example #24
Source File: FileUploadExecutorManager.java From attic-stratos with Apache License 2.0 | 5 votes |
public FileUploadExecutorManager(BundleContext bundleContext, ConfigurationContext configCtx, String webContext) throws CarbonException { this.bundleContext = bundleContext; this.configContext = configCtx; this.webContext = webContext; this.loadExecutorMap(); }
Example #25
Source File: Utils.java From attic-stratos with Apache License 2.0 | 5 votes |
/** * For a given Zip file, process each entry. * * @param zipFileLocation zipFileLocation * @param targetLocation targetLocation * @throws org.wso2.carbon.core.CarbonException * CarbonException */ public static void deployZipFile(File zipFileLocation, File targetLocation) throws CarbonException { try { SortedSet<String> dirsMade = new TreeSet<String>(); JarFile jarFile = new JarFile(zipFileLocation); Enumeration all = jarFile.entries(); while (all.hasMoreElements()) { getFile((ZipEntry) all.nextElement(), jarFile, targetLocation, dirsMade); } } catch (IOException e) { log.error("Error while copying component", e); throw new CarbonException(e); } }
Example #26
Source File: OutboundProvisioningManager.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * @param provisioningEntity * @param provisionByRoleList * @param tenantDomain * @return * @throws CarbonException * @throws UserStoreException */ protected boolean canUserBeProvisioned(ProvisioningEntity provisioningEntity, String[] provisionByRoleList, String tenantDomain) throws UserStoreException, CarbonException { if (provisioningEntity.getEntityType() != ProvisioningEntityType.USER || provisionByRoleList == null || provisionByRoleList.length == 0) { // we apply restrictions only for users. // if service provider's out-bound provisioning configuration does not define any roles // to be provisioned then we apply no restrictions. return true; } if (provisioningEntity.getAttributes() != null) { String userName = getUserName(provisioningEntity.getAttributes()); List<String> provisioningRoleList = Arrays.asList(provisionByRoleList); List<String> roleListOfUser = getUserRoles(userName, tenantDomain); if (userHasProvisioningRoles(roleListOfUser, provisioningRoleList, userName)) { return true; } List<String> newRoleListOfUser = provisioningEntity.getAttributes().get(ClaimMapping.build (IdentityProvisioningConstants.GROUP_CLAIM_URI, null, null, false)); if (userHasProvisioningRoles(newRoleListOfUser, provisioningRoleList, userName)) { return true; } } return false; }
Example #27
Source File: IdentityTenantUtil.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") public static Registry getRegistry() throws IdentityException { try { return AdminServicesUtil.getSystemRegistry(); } catch (CarbonException e) { log.error("Error obtaining a registry instance", e); throw IdentityException.error("Error obtaining a registry instance", e); } }
Example #28
Source File: DatabaseBasedUserStoreDAOImpl.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
private OMElement getRealmElement(InputStream inputStream) throws XMLStreamException, org.wso2.carbon.user.core.UserStoreException { try { inputStream = CarbonUtils.replaceSystemVariablesInXml(inputStream); StAXOMBuilder builder = new StAXOMBuilder(inputStream); OMElement documentElement = builder.getDocumentElement(); setSecretResolver(documentElement); return documentElement; } catch (CarbonException e) { throw new org.wso2.carbon.user.core.UserStoreException(e.getMessage(), e); } }
Example #29
Source File: OutboundProvisioningManager.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * @param userName * @param tenantDomain * @return * @throws CarbonException * @throws UserStoreException */ private Map<String, String> getUserClaims(String userName, String tenantDomain) throws CarbonException, UserStoreException { Map<String, String> inboundAttributes = new HashMap<>(); RegistryService registryService = IdentityProvisionServiceComponent.getRegistryService(); RealmService realmService = IdentityProvisionServiceComponent.getRealmService(); UserRealm realm = AnonymousSessionUtil.getRealmByTenantDomain(registryService, realmService, tenantDomain); UserStoreManager userstore = null; userstore = realm.getUserStoreManager(); Claim[] claimArray = null; try { claimArray = userstore.getUserClaimValues(userName, null); } catch (UserStoreException e) { if (e.getMessage().contains("UserNotFound")) { if (log.isDebugEnabled()) { log.debug("User " + userName + " not found in user store"); } } else { throw e; } } if (claimArray != null) { for (Claim claim : claimArray) { inboundAttributes.put(claim.getClaimUri(), claim.getValue()); } } return inboundAttributes; }
Example #30
Source File: OutboundProvisioningManager.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * @param userName * @param tenantDomain * @return * @throws CarbonException * @throws UserStoreException */ private List<String> getUserRoles(String userName, String tenantDomain) throws CarbonException, UserStoreException { RegistryService registryService = IdentityProvisionServiceComponent.getRegistryService(); RealmService realmService = IdentityProvisionServiceComponent.getRealmService(); UserRealm realm = AnonymousSessionUtil.getRealmByTenantDomain(registryService, realmService, tenantDomain); UserStoreManager userstore = null; userstore = realm.getUserStoreManager(); String[] newRoles = userstore.getRoleListOfUser(userName); return Arrays.asList(newRoles); }