Java Code Examples for org.wso2.carbon.identity.base.IdentityException#error()
The following examples show how to use
org.wso2.carbon.identity.base.IdentityException#error() .
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: JDBCUserRecoveryDataStore.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Override public void invalidate(String code) throws IdentityException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; try { prepStmt = connection.prepareStatement(SQLQuery.INVALIDATE_METADATA_FROM_CODE); prepStmt.setString(1, code.toLowerCase()); prepStmt.execute(); IdentityDatabaseUtil.commitTransaction(connection); } catch (SQLException e) { IdentityDatabaseUtil.rollbackTransaction(connection); throw IdentityException.error("Error while invalidating user identity data for code: " + code, e); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); IdentityDatabaseUtil.closeConnection(connection); } }
Example 2
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 3
Source File: JDBCUserRecoveryDataStore.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * @param userId * @param tenant * @throws IdentityException */ @Override public void invalidate(String userId, int tenant) throws IdentityException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; try { prepStmt = connection.prepareStatement(SQLQuery.INVALIDATE_METADATA); prepStmt.setString(1, userId); prepStmt.setInt(2, tenant); connection.commit(); } catch (SQLException e) { throw IdentityException.error("Error while invalidating user identity data", e); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); IdentityDatabaseUtil.closeConnection(connection); } }
Example 4
Source File: RecoveryProcessor.java From carbon-identity with Apache License 2.0 | 6 votes |
public VerificationBean updateConfirmationCode(int sequence, String username, int tenantId) throws IdentityException { String confirmationKey = generateUserCode(sequence, username); String secretKey = UUIDGenerator.generateUUID(); UserRecoveryDataDO recoveryDataDO = new UserRecoveryDataDO(username, tenantId, confirmationKey, secretKey); if (sequence != 3 && sequence != 30) { dataStore.invalidate(username, tenantId); } dataStore.store(recoveryDataDO); String externalCode = null; try { externalCode = getUserExternalCodeStr(confirmationKey); } catch (Exception e) { throw IdentityException.error("Error occurred while getting external code for user : " + username, e); } return new VerificationBean(username, externalCode); }
Example 5
Source File: IdPInitSSOAuthnRequestProcessor.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Returns the configured service provider configurations. The * configurations are taken from the user registry or from the * sso-idp-config.xml configuration file. In Stratos deployment the * configurations are read from the sso-idp-config.xml file. * * @param authnReqDTO * @return * @throws IdentityException */ private SAMLSSOServiceProviderDO getServiceProviderConfig(SAMLSSOAuthnReqDTO authnReqDTO) throws IdentityException { try { SSOServiceProviderConfigManager stratosIdpConfigManager = SSOServiceProviderConfigManager .getInstance(); SAMLSSOServiceProviderDO ssoIdpConfigs = stratosIdpConfigManager .getServiceProvider(authnReqDTO.getIssuer()); if (ssoIdpConfigs == null) { IdentityPersistenceManager persistenceManager = IdentityPersistenceManager .getPersistanceManager(); Registry registry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_CONFIGURATION); ssoIdpConfigs = persistenceManager.getServiceProvider(registry, authnReqDTO.getIssuer()); authnReqDTO.setStratosDeployment(false); // not stratos } else { authnReqDTO.setStratosDeployment(true); // stratos deployment } return ssoIdpConfigs; } catch (Exception e) { throw IdentityException.error("Error while reading Service Provider configurations", e); } }
Example 6
Source File: ParameterDAO.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * @param parameterDO * @throws IdentityException */ public void removeParameter(ParameterDO parameterDO) throws IdentityException { String path = null; Resource resource = null; if (log.isDebugEnabled()) { log.debug("Removing parameter"); } try { path = IdentityRegistryResources.CARD_ISSUER; if (registry.resourceExists(path)) { resource = registry.get(path); if (resource != null) { resource.removeProperty(parameterDO.getName()); registry.put(path, resource); } } } catch (RegistryException e) { log.error("Error while removing parameter", e); throw IdentityException.error("Error while removing parameter", e); } }
Example 7
Source File: UserIdentityManagementUtil.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Remove primary security questions * * @param tenantId * @throws IdentityException */ public static void removePrimaryQuestions(String[] primarySecurityQuestion, int tenantId) throws IdentityException { UserRecoveryDataDO[] metadata = new UserRecoveryDataDO[primarySecurityQuestion.length]; int i = 0; for (String secQuestion : primarySecurityQuestion) { if (!secQuestion.contains(UserCoreConstants.ClaimTypeURIs.CHALLENGE_QUESTION_URI)) { throw IdentityException.error("One or more security questions does not contain the namespace " + UserCoreConstants.ClaimTypeURIs.CHALLENGE_QUESTION_URI); } metadata[i++] = new UserRecoveryDataDO("TENANT", tenantId, UserRecoveryDataDO.METADATA_PRIMARAY_SECURITY_QUESTION, secQuestion); } }
Example 8
Source File: JDBCUserRecoveryDataStore.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Stores identity data. * * @throws IdentityException */ @Override public void store(UserRecoveryDataDO recoveryDataDO) throws IdentityException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; try { prepStmt = connection.prepareStatement(SQLQuery.STORE_META_DATA); prepStmt.setString(1, recoveryDataDO.getUserName().toLowerCase()); prepStmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); prepStmt.setString(3, recoveryDataDO.getCode().toLowerCase()); prepStmt.setString(4, recoveryDataDO.getSecret()); prepStmt.setString(5, recoveryDataDO.getExpireTime()); prepStmt.execute(); IdentityDatabaseUtil.commitTransaction(connection); } catch (SQLException e) { IdentityDatabaseUtil.rollbackTransaction(connection); throw IdentityException.error("Error while storing user identity data", e); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); IdentityDatabaseUtil.closeConnection(connection); } }
Example 9
Source File: UserIdentityManagementAdminService.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * User updates/add account recovery data such as the email address or the * phone number etc. * * @param userIdentityClaims * @throws IdentityMgtServiceException */ public void updateUserIdentityClaims(UserIdentityClaimDTO[] userIdentityClaims) throws IdentityMgtServiceException { String userName = CarbonContext.getThreadLocalCarbonContext().getUsername(); try { UserStoreManager userStoreManager = IdentityMgtServiceComponent.getRealmService() .getTenantUserRealm(CarbonContext.getThreadLocalCarbonContext().getTenantId()) .getUserStoreManager(); Map<String, String> claims = new HashMap<String, String>(); for (UserIdentityClaimDTO dto : userIdentityClaims) { if (dto.getClaimUri().contains(UserCoreConstants.ClaimTypeURIs.IDENTITY_CLAIM_URI)) { log.warn("WARNING! User " + userName + " tried to alter " + dto.getClaimUri()); throw IdentityException.error("Updates to the claim " + dto.getClaimUri() + " are not allowed"); } claims.put(dto.getClaimUri(), dto.getClaimValue()); } userStoreManager.setUserClaimValues(userName, claims, null); } catch (UserStoreException|IdentityException e) { String errorMessage = "Error while updating identity recovery data for : " + userName; log.error(errorMessage, e); throw new IdentityMgtServiceException(errorMessage, e); } }
Example 10
Source File: ThriftAuthenticatorServiceImpl.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
private void onSuccessLogin(ThriftSession authSession) throws IdentityException { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); try { carbonContext.setUsername((String) (authSession.getAttribute(ServerConstants.AUTHENTICATION_SERVICE_USERNAME))); carbonContext.setTenantDomain((String) (authSession.getAttribute(MultitenantConstants.TENANT_DOMAIN))); carbonContext.setTenantId((Integer) (authSession.getAttribute(MultitenantConstants.TENANT_ID))); } catch (Exception e) { String authErrorMsg = "Error populating current carbon context from thrift auth session: " + e.getMessage(); throw IdentityException.error(authErrorMsg); } }
Example 11
Source File: IdentityUtil.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
public static int getRandomInteger() throws IdentityException { try { SecureRandom prng = SecureRandom.getInstance("SHA1PRNG"); int number = prng.nextInt(); while (number < 0) { number = prng.nextInt(); } return number; } catch (NoSuchAlgorithmException e) { log.error("Error when generating a random number.", e); throw IdentityException.error("Error when generating a random number.", e); } }
Example 12
Source File: SAMLSSOServiceProviderDAO.java From carbon-identity with Apache License 2.0 | 5 votes |
public boolean isServiceProviderExists(String issuer) throws IdentityException { String path = IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS + encodePath(issuer); try { return registry.resourceExists(path); } catch (RegistryException e) { throw IdentityException.error("Error occurred while checking if resource path \'" + path + "\' exists in " + "registry"); } }
Example 13
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 14
Source File: UserIdentityMetadataStore.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * This method should return only one result. An exception will be thrown if * duplicate entries found. * This can be used to check if the given metada exist in the database or to * check the validity. * * @param userName * @param tenantId * @param metadataType * @param metadata * @return * @throws IdentityException */ public IdentityMetadataDO loadMetadata(String userName, int tenantId, String metadataType, String metadata) throws IdentityException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; ResultSet results = null; try { prepStmt = connection.prepareStatement(SQLQuery.LOAD_META_DATA); prepStmt.setString(1, userName); prepStmt.setInt(2, tenantId); prepStmt.setString(3, metadataType); prepStmt.setString(4, metadata); results = prepStmt.executeQuery(); connection.commit(); if (results.next()) { return new IdentityMetadataDO(results.getString(1), results.getInt(2), results.getString(3), results.getString(4), Boolean.parseBoolean(results.getString(5))); } if (results.next()) { throw IdentityException.error("Duplicate entry found for " + metadataType); } return null; } catch (SQLException e) { throw IdentityException.error("Error while reading user identity data", e); } finally { IdentityDatabaseUtil.closeResultSet(results); IdentityDatabaseUtil.closeStatement(prepStmt); IdentityDatabaseUtil.closeConnection(connection); } }
Example 15
Source File: JDBCIdentityDataStore.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@Override public void remove(String userName, UserStoreManager userStoreManager) throws IdentityException { super.remove(userName, userStoreManager); String domainName = ((org.wso2.carbon.user.core.UserStoreManager) userStoreManager). getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME); userName = UserCoreUtil.addDomainToName(userName, domainName); Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; try { int tenantId = userStoreManager.getTenantId(); boolean isUsernameCaseSensitive = IdentityUtil.isUserStoreInUsernameCaseSensitive(userName, tenantId); String query; if (isUsernameCaseSensitive) { query = SQLQuery.DELETE_USER_DATA; } else { query = SQLQuery.DELETE_USER_DATA_CASE_INSENSITIVE; } prepStmt = connection.prepareStatement(query); prepStmt.setInt(1, tenantId); prepStmt.setString(2, userName); prepStmt.execute(); IdentityDatabaseUtil.commitTransaction(connection); } catch (SQLException | UserStoreException e) { IdentityDatabaseUtil.rollbackTransaction(connection); throw IdentityException.error("Error while reading user identity data", e); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); IdentityDatabaseUtil.closeConnection(connection); } }
Example 16
Source File: IdentityUtil.java From carbon-identity with Apache License 2.0 | 5 votes |
public static int getRandomInteger() throws IdentityException { try { SecureRandom prng = SecureRandom.getInstance("SHA1PRNG"); int number = prng.nextInt(); while (number < 0) { number = prng.nextInt(); } return number; } catch (NoSuchAlgorithmException e) { log.error("Error when generating a random number.", e); throw IdentityException.error("Error when generating a random number.", e); } }
Example 17
Source File: Utils.java From carbon-identity with Apache License 2.0 | 5 votes |
public static void validateTenant(UserDTO user) throws IdentityException { if (user.getTenantDomain() != null && !user.getTenantDomain().isEmpty()) { if (!user.getTenantDomain().equals( PrivilegedCarbonContext.getThreadLocalCarbonContext() .getTenantDomain())) { throw IdentityException.error( "Failed access to unauthorized tenant domain"); } user.setTenantId(getTenantId(user.getTenantDomain())); } }
Example 18
Source File: AbstractDAO.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
/** * Returns all the objects in a given registry path with a given property values. * * @param path registry path * @param propName name of the property to be matched * @param value value of the property to be matched * @return list of all objects matching the given property value in the given registry path * @throws IdentityException if an error occurs while reading the registry */ public List<T> getAllObjectsWithPropertyValue(String path, String propName, String value) throws IdentityException { Resource query = null; List<T> retList = null; Map<String, String> params = null; Resource result = null; String[] paths = null; Resource resource = null; if (log.isErrorEnabled()) { log.debug("Retrieving all objects from the registry path with property values " + path); } try { retList = new ArrayList<T>(); if (registry.resourceExists(CUSTOM_QUERY_GET_ALL_BY_PROP)) { //query = registry.get(CUSTOM_QUERY_GET_ALL_BY_PROP); } else { query = registry.newResource(); query.setContent(SQL_GET_ALL_BY_PROP); query.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE); query.addProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.RESOURCES_RESULT_TYPE); registry.put(CUSTOM_QUERY_GET_ALL_BY_PROP, query); } params = new HashMap<String, String>(); params.put("1", propName); params.put("2", value); result = registry.executeQuery(CUSTOM_QUERY_GET_ALL_BY_PROP, params); paths = (String[]) result.getContent(); for (String prop : paths) { resource = registry.get(prop); retList.add(resourceToObject(resource)); } } catch (RegistryException e) { String message = "Error while retrieving all objects from the registry path with property values"; log.error(message, e); throw IdentityException.error(message, e); } return retList; }
Example 19
Source File: XMPPSettingsDAO.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * Update XMPP Settings of a user * * @param userId * @param xmppServer * @param xmppUserName * @param xmppUserCode * @throws IdentityException */ public void updateXmppSettings(String userId, String xmppServer, String xmppUserName, String xmppUserCode, boolean enabled, boolean pinEnabled) throws IdentityException { String path = null; Resource resource = null; String xmppEnabled = "false"; String isPINEnabled = "false"; if (enabled) { xmppEnabled = "true"; } if (pinEnabled) { isPINEnabled = "true"; } try { if (userId != null) { path = IdentityRegistryResources.XMPP_SETTINGS_ROOT + userId; } if (!registry.resourceExists(path)) { if (log.isInfoEnabled()) { log.info("XMPP Settings does not exist for the user " + userId); } return; } resource = registry.get(path); resource.setProperty(IdentityRegistryResources.XMPP_SERVER, xmppServer); resource.setProperty(IdentityRegistryResources.XMPP_USERNAME, xmppUserName); resource.setProperty(IdentityRegistryResources.XMPP_USERCODE, xmppUserCode); resource.setProperty(IdentityRegistryResources.XMPP_ENABLED, xmppEnabled); resource.setProperty(IdentityRegistryResources.XMPP_PIN_ENABLED, isPINEnabled); registry.put(path, resource); if (log.isInfoEnabled()) { log.info("XMPP Settings are updated for the user " + userId); } } catch (RegistryException e) { log.error("Error occured while updating the XMPP Settings.", e); throw IdentityException.error("Error occured while updating the XMPP Settings.", e); } }
Example 20
Source File: IdentityClaimManager.java From carbon-identity-framework with Apache License 2.0 | 2 votes |
/** * Creates an IdentityException instance wrapping the given error message and * * @param message Error message * @param e Exception * @throws IdentityException constructed exception based on input parameters */ private void getException(String message, Exception e) throws IdentityException { log.error(message, e); throw IdentityException.error(message, e); }