org.wso2.carbon.registry.core.exceptions.RegistryException Java Examples

The following examples show how to use org.wso2.carbon.registry.core.exceptions.RegistryException. 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: ParameterDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * @param paramName
 * @return
 * @throws IdentityException
 */
public ParameterDO getParameter(String paramName) throws IdentityException {
    ParameterDO param = null;
    String path = null;
    Resource resource = null;

    if (log.isDebugEnabled()) {
        log.debug("Retrieving parameter " + paramName);
    }

    try {
        path = IdentityRegistryResources.CARD_ISSUER;
        param = new ParameterDO();
        if (registry.resourceExists(path)) {
            resource = registry.get(path);
            if (resource != null) {
                param.setName(paramName);
                param.setValue(resource.getProperty(paramName));
            }
        }
    } catch (RegistryException e) {
        log.error("Error while retrieving parameter " + paramName, e);
        throw IdentityException.error("Error while retrieving parameter " + paramName, e);
    }
    return param;
}
 
Example #2
Source File: RegistryTaskDeletionClient.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Default constructor
 */
public RegistryTaskDeletionClient() {
    String adminUserName = MigrationClientConfig.getInstance()
                                                .getMigrationConfiguration()
                                                .getProperty(MigrationConstants.ADMIN_USERNAME);

    if (adminUserName.isEmpty()) {
        throw new MigrationClientException("Invalid admin username");
    }

    try {
        this.userRegistry = EIMigrationServiceDataHolder.getRegistryService().getRegistry(adminUserName);
        this.userRegistryResource = userRegistry.get(MigrationConstants.ESB_TASK_PATH);
    } catch (RegistryException e) {
        throw new MigrationClientException("Error occurred while retrieving registry resources", e);
    }
}
 
Example #3
Source File: SAMLSSOServiceProviderDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * This helps to find resources in a recursive manner.
 *
 * @param parentResource      parent resource Name.
 * @param serviceProviderList child resource list.
 * @throws RegistryException
 */
private void getChildResources(String parentResource, List<SAMLSSOServiceProviderDO>
        serviceProviderList) throws RegistryException {

    if (registry.resourceExists(parentResource)) {
        Resource resource = registry.get(parentResource);
        if (resource instanceof Collection) {
            Collection collection = (Collection) resource;
            String[] resources = collection.getChildren();
            for (String res : resources) {
                getChildResources(res, serviceProviderList);
            }
        } else {
            serviceProviderList.add(resourceToObject(resource));
        }
    }
}
 
Example #4
Source File: CarbonEntitlementDataFinder.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * This helps to find resources un a recursive manner
 *
 * @param node           attribute value node
 * @param parentResource parent resource Name
 * @return child resource set
 * @throws RegistryException throws
 */
private EntitlementTreeNodeDTO getChildResources(EntitlementTreeNodeDTO node,
                                                 String parentResource) throws RegistryException {

    if (registry.resourceExists(parentResource)) {
        String[] resourcePath = parentResource.split("/");
        EntitlementTreeNodeDTO childNode =
                new EntitlementTreeNodeDTO(resourcePath[resourcePath.length - 1]);
        node.addChildNode(childNode);
        Resource root = registry.get(parentResource);
        if (root instanceof Collection) {
            Collection collection = (Collection) root;
            String[] resources = collection.getChildren();
            for (String resource : resources) {
                getChildResources(childNode, resource);
            }
        }
    }
    return node;
}
 
Example #5
Source File: RegistryDataManager.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Encrypt the registry properties by new algorithm and update
 *
 * @param registry
 * @param resource
 * @param properties
 * @throws RegistryException
 * @throws CryptoException
 */
private void updateRegistryProperties(Registry registry, String resource, List<String> properties)
        throws RegistryException, CryptoException {
    if (registry == null || StringUtils.isEmpty(resource) || CollectionUtils.isEmpty(properties)) {
        return;
    }
    if (registry.resourceExists(resource)) {
        try {
            registry.beginTransaction();
            Resource resourceObj = registry.get(resource);
            for (String encryptedPropertyName : properties) {
                String oldValue = resourceObj.getProperty(encryptedPropertyName);
                String newValue = Utility.getNewEncryptedValue(oldValue);
                if (StringUtils.isNotEmpty(newValue)) {
                    resourceObj.setProperty(encryptedPropertyName, newValue);
                }
            }
            registry.put(resource, resourceObj);
            registry.commitTransaction();
        } catch (RegistryException e) {
            registry.rollbackTransaction();
            log.error("Unable to update the registry resource", e);
            throw e;
        }
    }
}
 
Example #6
Source File: OAuthConsumerDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Returns oAuth consumer secret for a give consumer key.
 *
 * @param consumerKey consumer key
 * @return oAuth consumer secret
 * @throws IdentityException if error occurs while obtaining the consumer secret
 */
public String getOAuthConsumerSecret(String consumerKey) throws IdentityException {
    String path = null;
    Resource resource = null;

    if (log.isDebugEnabled()) {
        log.debug("Retreiving user for OAuth consumer key  " + consumerKey);
    }

    try {
        path = RegistryConstants.PROFILES_PATH + consumerKey;
        if (registry.resourceExists(path)) {
            resource = registry.get(path);
            return resource.getProperty(IdentityRegistryResources.OAUTH_CONSUMER_PATH);
        } else {
            return null;
        }
    } catch (RegistryException e) {
        log.error("Error while retreiving user for OAuth consumer key  " + consumerKey, e);
        throw IdentityException.error("Error while retreiving user for OAuth consumer key  "
                + consumerKey, e);
    }
}
 
Example #7
Source File: OpenIDUserDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public String getUserIdForAssociation(String openId) {

        try {
            if (registry
                    .resourceExists(IdentityRegistryResources.OPENID_SIGN_UP
                            + getOpenIdModified(openId))) {
                return resourceToObject(
                        registry.get(IdentityRegistryResources.OPENID_SIGN_UP
                                + getOpenIdModified(openId))).getUserName();
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Unable to find an Sign-Up for " + openId);
                }
            }
        } catch (RegistryException e) {
            log.error("Error retrieving a resource from Registry", e);
        }

        return null;
    }
 
Example #8
Source File: XMPPSettingsDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * retrieve XMPP Settings of a user by providing the userId
 *
 * @param userId
 * @return
 */
public XMPPSettingsDO getXmppSettings(String userId) {

    XMPPSettingsDO xmppSettings = null;

    try {
        if (registry.resourceExists(IdentityRegistryResources.XMPP_SETTINGS_ROOT + userId)) {
            xmppSettings = resourceToObject(registry
                    .get(IdentityRegistryResources.XMPP_SETTINGS_ROOT + userId));
        }

    } catch (RegistryException e) {
        log.error("Cannot retrieve the XMPP Settings for the user " + userId, e);
    }
    return xmppSettings;
}
 
Example #9
Source File: RegistryDataManager.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Method to migrate encrypted password of SYSLOG_PROPERTIES registry resource
 *
 * @param migrateActiveTenantsOnly
 * @throws UserStoreException user store exception
 */
public void migrateSysLogPropertyPassword(boolean migrateActiveTenantsOnly)
        throws UserStoreException, RegistryException, CryptoException {
    try {
        //migrating super tenant configurations
        migrateSysLogPropertyPasswordForTenant(SUPER_TENANT_ID);
        log.info("Sys log property password migrated for tenant : " + SUPER_TENANT_DOMAIN_NAME);
    } catch (Exception e) {
        log.error("Error while migrating Sys log property password for tenant : " + SUPER_TENANT_DOMAIN_NAME, e);
    }
    Tenant[] tenants = MigrationServiceDataHolder.getRealmService().getTenantManager().getAllTenants();
    for (Tenant tenant : tenants) {
        if (migrateActiveTenantsOnly && !tenant.isActive()) {
            log.info("Tenant " + tenant.getDomain() + " is inactive. Skipping SYSLOG_PROPERTIES file migration. ");
            continue;
        }
        try {
            migrateSysLogPropertyPasswordForTenant(tenant.getId());
        } finally {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
}
 
Example #10
Source File: PAPPolicyStore.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * This returns given policy as Registry resource
 *
 * @param policyId   policy id
 * @param collection
 * @return policy as Registry resource
 * @throws EntitlementException throws, if fails
 */
public Resource getPolicy(String policyId, String collection) throws EntitlementException {
    String path = null;

    if (log.isDebugEnabled()) {
        log.debug("Retrieving entitlement policy");
    }

    try {
        path = collection + policyId;

        if (!registry.resourceExists(path)) {
            if (log.isDebugEnabled()) {
                log.debug("Trying to access an entitlement policy which does not exist");
            }
            return null;
        }
        return registry.get(path);
    } catch (RegistryException e) {
        log.error("Error while retrieving entitlement policy " + policyId + " PAP policy store", e);
        throw new EntitlementException("Error while retrieving entitlement policy " + policyId
                                       + " PAP policy store");
    }
}
 
Example #11
Source File: PAPPolicyStore.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * @param policyId
 * @throws EntitlementException
 */
public void removePolicy(String policyId) throws EntitlementException {
    String path = null;

    if (log.isDebugEnabled()) {
        log.debug("Removing entitlement policy");
    }

    try {
        path = PDPConstants.ENTITLEMENT_POLICY_PAP + policyId;
        if (!registry.resourceExists(path)) {
            if (log.isDebugEnabled()) {
                log.debug("Trying to access an entitlement policy which does not exist");
            }
            return;
        }
        registry.delete(path);
    } catch (RegistryException e) {
        log.error("Error while removing entitlement policy " + policyId + " from PAP policy store", e);
        throw new EntitlementException("Error while removing policy " + policyId + " from PAP policy store");
    }
}
 
Example #12
Source File: XMPPSettingsDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the given user has enabled XMPP based multifactor auth.
 *
 * @param userId
 * @return
 */
public boolean isXmppSettingsEnabled(String userId) {

    boolean isEnabled = false;
    XMPPSettingsDO xmppSettings;
    try {
        if (registry.resourceExists(IdentityRegistryResources.XMPP_SETTINGS_ROOT + userId)) {
            xmppSettings = resourceToObject(registry
                    .get(IdentityRegistryResources.XMPP_SETTINGS_ROOT + userId));
            isEnabled = xmppSettings.isXmppEnabled();
        }
    } catch (RegistryException e) {
        log.error("Error when checking the availability of the user " + userId, e);
    }

    return isEnabled;
}
 
Example #13
Source File: PolicyPublisher.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public void deleteSubscriber(String subscriberId) throws EntitlementException {

        String subscriberPath;

        if (subscriberId == null) {
            log.error("Subscriber Id can not be null");
            throw new EntitlementException("Subscriber Id can not be null");
        }

        if (EntitlementConstants.PDP_SUBSCRIBER_ID.equals(subscriberId.trim())) {
            log.error("Can not delete PDP publisher");
            throw new EntitlementException("Can not delete PDP publisher");
        }

        try {
            subscriberPath = PDPConstants.ENTITLEMENT_POLICY_PUBLISHER +
                    RegistryConstants.PATH_SEPARATOR + subscriberId;

            if (registry.resourceExists(subscriberPath)) {
                registry.delete(subscriberPath);
            }
        } catch (RegistryException e) {
            log.error("Error while deleting subscriber details", e);
            throw new EntitlementException("Error while deleting subscriber details", e);
        }
    }
 
Example #14
Source File: CaptchaUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public static void setAnonAuthorization(String path, UserRealm userRealm)
        throws RegistryException {

    if (userRealm == null) {
        return;
    }

    try {
        AuthorizationManager accessControlAdmin = userRealm.getAuthorizationManager();
        String everyoneRole = CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME;

        accessControlAdmin.authorizeRole(everyoneRole, path, ActionConstants.GET);
        accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.PUT);
        accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.DELETE);
        accessControlAdmin.denyRole(everyoneRole, path, AccessControlConstants.AUTHORIZE);

    } catch (UserStoreException e) {
        String msg = "Could not set authorizations for the " + path + ".";
        log.error(msg, e);
        throw new RegistryException(msg);
    }
}
 
Example #15
Source File: SAMLSSOServiceProviderDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public SAMLSSOServiceProviderDO[] getServiceProviders() throws IdentityException {
    List<SAMLSSOServiceProviderDO> serviceProvidersList = new ArrayList<>();
    try {
        if (registry.resourceExists(IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS)) {
            Resource samlSSOServiceProvidersResource = registry.get(IdentityRegistryResources
                    .SAML_SSO_SERVICE_PROVIDERS);
            if (samlSSOServiceProvidersResource instanceof Collection) {
                Collection samlSSOServiceProvidersCollection = (Collection) samlSSOServiceProvidersResource;
                String[] resources = samlSSOServiceProvidersCollection.getChildren();
                for (String resource : resources) {
                    getChildResources(resource, serviceProvidersList);
                }
            }
        }
    } catch (RegistryException e) {
        log.error("Error reading Service Providers from Registry", e);
        throw IdentityException.error("Error reading Service Providers from Registry", e);
    }
    return serviceProvidersList.toArray(new SAMLSSOServiceProviderDO[serviceProvidersList.size()]);
}
 
Example #16
Source File: RegistryPolicyReader.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * This returns given policy as Registry resource
 *
 * @param policyId policy id
 * @return policy as Registry resource
 * @throws EntitlementException throws, if fails
 */
private Resource getPolicyResource(String policyId) throws EntitlementException {
    String path = null;

    if (log.isDebugEnabled()) {
        log.debug("Retrieving entitlement policy");
    }

    try {
        path = policyStorePath + policyId;

        if (!registry.resourceExists(path)) {
            if (log.isDebugEnabled()) {
                log.debug("Trying to access an entitlement policy which does not exist");
            }
            return null;
        }
        return registry.get(path);
    } catch (RegistryException e) {
        log.error("Error while retrieving entitlement policy : " + policyId, e);
        throw new EntitlementException("Error while retrieving entitlement policy : " + policyId, e);
    }
}
 
Example #17
Source File: Utils.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * gets no of verified user challenges
 *
 * @param userDTO bean class that contains user and tenant Information
 * @return no of verified challenges
 * @throws IdentityException if fails
 */
public static int getVerifiedChallenges(UserDTO userDTO) throws IdentityException {

    int noOfChallenges = 0;

    try {
        UserRegistry registry = IdentityMgtServiceComponent.getRegistryService().
                getConfigSystemRegistry(MultitenantConstants.SUPER_TENANT_ID);
        String identityKeyMgtPath = IdentityMgtConstants.IDENTITY_MANAGEMENT_CHALLENGES +
                RegistryConstants.PATH_SEPARATOR + userDTO.getUserId() +
                RegistryConstants.PATH_SEPARATOR + userDTO.getUserId();

        Resource resource;
        if (registry.resourceExists(identityKeyMgtPath)) {
            resource = registry.get(identityKeyMgtPath);
            String property = resource.getProperty(IdentityMgtConstants.VERIFIED_CHALLENGES);
            if (property != null) {
                return Integer.parseInt(property);
            }
        }
    } catch (RegistryException e) {
        log.error("Error while processing userKey", e);
    }

    return noOfChallenges;
}
 
Example #18
Source File: OpenIDAdminDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve OpenID admin for a tenant.
 *
 * @return open id admin of the tenant
 * @throws IdentityException if error occurs while retrieving the OpenID admin
 */
public OpenIDAdminDO getOpenIDAdminDO() throws IdentityException {
    OpenIDAdminDO opdo = null;
    Resource resource = null;

    if (log.isDebugEnabled()) {
        log.debug("Retrieving OpenID admin for tenant");
    }
    try {
        if (registry.resourceExists(IdentityRegistryResources.OPEN_ID_ADMIN_SETTINGS)) {
            resource = registry.get(IdentityRegistryResources.OPEN_ID_ADMIN_SETTINGS);
            return resourceToObject(resource);
        }
    } catch (RegistryException e) {
        log.error("Error while retreiving openid admin", e);
        throw IdentityException.error("Error while retreiving openid admin", e);
    }
    return opdo;
}
 
Example #19
Source File: RegistryResourceMgtServiceImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void putIdentityResource(Resource identityResource,
                                String path,
                                String tenantDomain) throws IdentityRuntimeException {
    startTenantFlow(tenantDomain);
    try {
        Registry registry = getRegistryForTenant(tenantDomain);
        registry.put(path, identityResource);
        if (log.isDebugEnabled()) {
            log.debug(String.format(MSG_RESOURCE_PERSIST, path, tenantDomain));
        }
    } catch (RegistryException e) {
        String errorMsg = String.format(ERROR_PERSIST_RESOURCE, tenantDomain, path);
        throw IdentityRuntimeException.error(errorMsg, e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example #20
Source File: RegistryPolicyStoreManageModule.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isPolicyExist(String policyId) {

    Registry registry;
    String policyPath;
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    if (policyId == null || policyId.trim().length() == 0) {
        return false;
    }

    try {
        registry = EntitlementServiceComponent.getRegistryService().
                getGovernanceSystemRegistry(tenantId);

        policyPath = policyStorePath + policyId;
        return registry.resourceExists(policyPath);
    } catch (RegistryException e) {
        //ignore
        return false;
    }
}
 
Example #21
Source File: RegistryPolicyStoreManageModule.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public boolean deletePolicy(String policyIdentifier) {

    Registry registry;
    String policyPath;
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    if (policyIdentifier == null || policyIdentifier.trim().length() == 0) {
        return false;
    }

    try {
        registry = EntitlementServiceComponent.getRegistryService().
                getGovernanceSystemRegistry(tenantId);

        policyPath = policyStorePath + policyIdentifier;
        registry.delete(policyPath);
        return true;
    } catch (RegistryException e) {
        log.error(e);
        return false;
    }
}
 
Example #22
Source File: RegistryResourceMgtServiceImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public Resource getIdentityResource(String path,
                                    String tenantDomain) throws IdentityRuntimeException {
    startTenantFlow(tenantDomain);
    try {
        Registry registry = getRegistryForTenant(tenantDomain);
        Resource resource = null;

        if (registry.resourceExists(path)) {
            resource = registry.get(path);
        }
        return resource;
    } catch (RegistryException e) {
        String errorMsg = String.format(ERROR_GET_RESOURCE, path, tenantDomain);
        throw IdentityRuntimeException.error(errorMsg, e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example #23
Source File: ParameterDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * @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 #24
Source File: SecurityMgtServiceComponent.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private void addKeystores() throws RegistryException {
    Registry registry = SecurityServiceHolder.getRegistryService().getGovernanceSystemRegistry();
    try {
        boolean transactionStarted = Transaction.isStarted();
        if (!transactionStarted) {
            registry.beginTransaction();
        }
        if (!registry.resourceExists(SecurityConstants.KEY_STORES)) {
            Collection kstores = registry.newCollection();
            registry.put(SecurityConstants.KEY_STORES, kstores);

            Resource primResource = registry.newResource();
            if (!registry.resourceExists(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE)) {
                registry.put(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE,
                        primResource);
            }
        }
        if (!transactionStarted) {
            registry.commitTransaction();
        }
    } catch (Exception e) {
        registry.rollbackTransaction();
        throw e;
    }
}
 
Example #25
Source File: PolicyPublisher.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public PublisherDataHolder retrieveSubscriber(String id, boolean returnSecrets) throws EntitlementException {

        try {
            if (registry.resourceExists(PDPConstants.ENTITLEMENT_POLICY_PUBLISHER +
                    RegistryConstants.PATH_SEPARATOR + id)) {
                Resource resource = registry.get(PDPConstants.ENTITLEMENT_POLICY_PUBLISHER +
                        RegistryConstants.PATH_SEPARATOR + id);

                return new PublisherDataHolder(resource, returnSecrets);
            }
        } catch (RegistryException e) {
            log.error("Error while retrieving subscriber detail of id : " + id, e);
            throw new EntitlementException("Error while retrieving subscriber detail of id : " + id, e);
        }

        throw new EntitlementException("No Subscriber is defined for given Id");
    }
 
Example #26
Source File: OpenIDAdminDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Create or update the OpenID admin.
 *
 * @param opAdmin openID admin
 * @throws IdentityException if error occurs while creating or updating the OpenID admin
 */
public void createOrUpdate(OpenIDAdminDO opAdmin) throws IdentityException {
    String path = null;
    Resource resource = null;

    try {
        path = IdentityRegistryResources.OPEN_ID_ADMIN_SETTINGS;
        if (!registry.resourceExists(path)) {
            if (log.isDebugEnabled()) {
                log.debug("Creating new openid admin");
            }
            resource = registry.newResource();
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Updating openid admin");
            }
            resource = registry.get(path);
            resource.removeProperty(IdentityRegistryResources.SUB_DOMAIN);
            resource.removeProperty(IdentityRegistryResources.OPENID_PATTERN);
        }
        resource.addProperty(IdentityRegistryResources.SUB_DOMAIN, opAdmin.getSubDomain());
        resource.addProperty(IdentityRegistryResources.OPENID_PATTERN, opAdmin
                .getTenantOpenIDPattern());
        registry.put(path, resource);
    } catch (RegistryException e) {
        log.error("Error while creating/updating openid admin", e);
        throw IdentityException.error("Error while creating/updating openid admin", e);
    }
}
 
Example #27
Source File: OpenIDUserDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public void removeOpenIDSignUp(String openID) {
    try {
        if (registry.resourceExists(IdentityRegistryResources.OPENID_SIGN_UP + getOpenIdModified(openID))) {
            registry.delete(IdentityRegistryResources.OPENID_SIGN_UP + getOpenIdModified(openID));
        }
    } catch (RegistryException e) {
        log.error("Error Removing the OpenID", e);
    }
}
 
Example #28
Source File: ChallengeQuestionProcessor.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param questionDTOs
 * @throws IdentityException
 */
public void setChallengeQuestions(ChallengeQuestionDTO[] questionDTOs) throws IdentityException {
    Registry registry = null;
    try {
        int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
        registry = IdentityMgtServiceComponent.getRegistryService().getConfigSystemRegistry(tenantId);

        if (!registry.resourceExists(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH)) {
            Collection securityQuestionResource = registry.newCollection();
            registry.put(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH, securityQuestionResource);
        }
        Resource identityMgtResource = registry.get(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH);
        if (identityMgtResource != null) {
            String questionCollectionPath = IdentityMgtConstants.IDENTITY_MANAGEMENT_QUESTIONS;
            if (registry.resourceExists(questionCollectionPath)) {
                registry.delete(questionCollectionPath);
            }

            Collection questionCollection = registry.newCollection();
            registry.put(questionCollectionPath, questionCollection);

            for (int i = 0; i < questionDTOs.length; i++) {
                Resource resource = registry.newResource();
                resource.addProperty("question", questionDTOs[i].getQuestion());
                resource.addProperty("isPromoteQuestion", String.valueOf(questionDTOs[i].isPromoteQuestion()));
                resource.addProperty("questionSetId", questionDTOs[i].getQuestionSetId());
                registry.put(IdentityMgtConstants.IDENTITY_MANAGEMENT_QUESTIONS +
                        RegistryConstants.PATH_SEPARATOR + "question" + i +
                        RegistryConstants.PATH_SEPARATOR, resource);
            }
        }
    } catch (RegistryException e) {
        throw IdentityException.error("Error while setting challenge question.", e);
    }

}
 
Example #29
Source File: OpenIDUserDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Get all OpenIDs of an user
 *
 * @param username
 * @return
 */
public String[] getOpenIDsForUser(String username) {
    String[] openIDSet = new String[0];
    Resource openIDResource = null;

    try {
        if (registry.resourceExists(RegistryConstants.PROFILES_PATH + username)) {
            Association[] openIDAssociations = registry.getAssociations(
                    RegistryConstants.PROFILES_PATH + username,
                    IdentityRegistryResources.ASSOCIATION_USER_OPENID);
            openIDSet = new String[openIDAssociations.length];

            int i = 0;

            for (Association association : openIDAssociations) {
                String openIDAssociation = association.getDestinationPath().trim();
                String openID = "";
                if (registry.resourceExists(openIDAssociation)) {
                    openIDResource = registry.get(openIDAssociation);
                    openID = openIDResource.getProperty(IdentityRegistryResources.PROP_OPENID);
                }
                openIDSet[i] = openID;
                i++;
            }
        }
    } catch (RegistryException e) {
        log.error("Error retrieving user information from registry.", e);
    }
    return openIDSet;
}
 
Example #30
Source File: ParameterDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param parameterDO
 * @throws IdentityException
 */
public void createOrUpdateParameter(ParameterDO parameterDO) throws IdentityException {
    String path = null;
    Resource resource = null;

    if (log.isDebugEnabled()) {
        log.debug("Creating or updating parameter");
    }

    try {
        path = IdentityRegistryResources.CARD_ISSUER;
        if (registry.resourceExists(path)) {
            resource = registry.get(path);
        } else {
            resource = registry.newResource();
        }

        if (resource.getProperty(parameterDO.getName()) != null) {
            resource.removeProperty(parameterDO.getName());
        }

        resource.addProperty(parameterDO.getName(), parameterDO.getValue());
        registry.put(path, resource);
    } catch (RegistryException e) {
        log.error("Error while creating or updating parameter", e);
        throw IdentityException.error("Error while creating or updating parameter", e);
    }
}