Search in sources :

Example 1 with Filterable

use of org.orcid.jaxb.model.v3.dev1.common.Filterable in project ORCID-Source by ORCID.

the class PublicAPISecurityManagerV3Test method setVisibility.

private void setVisibility(GroupsContainer container, Visibility... vs) {
    assertEquals(container.retrieveGroups().size(), vs.length);
    int idx = 0;
    for (Group g : container.retrieveGroups()) {
        // Every group have just one element
        assertEquals(1, g.getActivities().size());
        for (Filterable f : g.getActivities()) {
            f.setVisibility(vs[idx++]);
        }
    }
}
Also used : FundingGroup(org.orcid.jaxb.model.v3.dev1.record.summary.FundingGroup) Group(org.orcid.jaxb.model.v3.dev1.record.Group) PeerReviewGroup(org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewGroup) WorkGroup(org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup) Filterable(org.orcid.jaxb.model.v3.dev1.common.Filterable)

Example 2 with Filterable

use of org.orcid.jaxb.model.v3.dev1.common.Filterable in project ORCID-Source by ORCID.

the class PublicAPISecurityManagerV3Test method getFilterableElement.

/**
 * Utilities
 */
private Filterable getFilterableElement(Visibility v) {
    EducationSummary s = new EducationSummary();
    s.setVisibility(v);
    return s;
}
Also used : EducationSummary(org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)

Example 3 with Filterable

use of org.orcid.jaxb.model.v3.dev1.common.Filterable in project ORCID-Source by ORCID.

the class OrcidSecurityManagerImpl method checkAndFilter.

/**
 * Check the permissions of a request over an element. Private
 * implementation that will also include a parameter that indicates if we
 * should check the token or, if it was already checked previously
 *
 * @param orcid
 *            The user owner of the element
 * @param element
 *            The element to check
 * @param requiredScope
 *            The required scope to access this element
 * @param tokenAlreadyChecked
 *            Indicates if the token was already checked previously, so, we
 *            don't expend time checking it again
 * @throws OrcidUnauthorizedException
 *             In case the token used was not issued for the owner of the
 *             element
 * @throws OrcidAccessControlException
 *             In case the request doesn't have the required scopes
 * @throws OrcidVisibilityException
 *             In case the element is not visible due the visibility
 */
private void checkAndFilter(String orcid, VisibilityType element, ScopePathType requiredScope, boolean tokenAlreadyChecked) {
    if (element == null) {
        return;
    }
    // Check the token was issued for this user
    if (!tokenAlreadyChecked) {
        isMyToken(orcid);
    }
    // Check if the client is the source of the element
    if (element instanceof Filterable) {
        Filterable filterable = (Filterable) element;
        OAuth2Authentication oAuth2Authentication = getOAuth2Authentication();
        if (oAuth2Authentication != null) {
            OAuth2Request authorizationRequest = oAuth2Authentication.getOAuth2Request();
            String clientId = authorizationRequest.getClientId();
            if (clientId.equals(filterable.retrieveSourcePath())) {
                // The client doing the request is the source of the element
                return;
            }
        }
    }
    // /read-public scope
    if (Visibility.PUBLIC.equals(element.getVisibility())) {
        try {
            checkScopes(ScopePathType.READ_PUBLIC);
            // can return it
            return;
        } catch (OrcidAccessControlException e) {
        // Just continue filtering
        }
    }
    // Filter
    filter(element, requiredScope);
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) Filterable(org.orcid.jaxb.model.v3.dev1.common.Filterable) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException)

Aggregations

Filterable (org.orcid.jaxb.model.v3.dev1.common.Filterable)2 OrcidAccessControlException (org.orcid.core.exception.OrcidAccessControlException)1 Group (org.orcid.jaxb.model.v3.dev1.record.Group)1 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)1 FundingGroup (org.orcid.jaxb.model.v3.dev1.record.summary.FundingGroup)1 PeerReviewGroup (org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewGroup)1 WorkGroup (org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)1