Search in sources :

Example 1 with VisibilityType

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

the class PublicAPISecurityManagerV3Test method getVisibilityTypeElement.

private VisibilityType getVisibilityTypeElement(Visibility v) {
    EducationSummary s = new EducationSummary();
    s.setVisibility(v);
    return s;
}
Also used : EducationSummary(org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)

Example 2 with VisibilityType

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

the class OrcidSecurityManagerImpl method checkAndFilter.

private void checkAndFilter(String orcid, Collection<? extends VisibilityType> elements, ScopePathType requiredScope, boolean tokenAlreadyChecked) {
    if (elements == null) {
        return;
    }
    // Check the token
    if (!tokenAlreadyChecked) {
        isMyToken(orcid);
    }
    Iterator<? extends VisibilityType> it = elements.iterator();
    while (it.hasNext()) {
        VisibilityType element = it.next();
        try {
            if (element instanceof Email) {
                Email email = (Email) element;
                checkAndFilter(orcid, email, requiredScope, true);
            } else {
                checkAndFilter(orcid, element, requiredScope, true);
            }
        } catch (Exception e) {
            it.remove();
        }
    }
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) VisibilityType(org.orcid.jaxb.model.v3.dev1.common.VisibilityType) NoResultException(javax.persistence.NoResultException) OrcidNotClaimedException(org.orcid.core.exception.OrcidNotClaimedException) OrcidDeprecatedException(org.orcid.core.exception.OrcidDeprecatedException) WrongSourceException(org.orcid.core.exception.WrongSourceException) LockedException(org.orcid.core.security.aop.LockedException) AccessControlException(java.security.AccessControlException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) DeactivatedException(org.orcid.core.exception.DeactivatedException)

Example 3 with VisibilityType

use of org.orcid.jaxb.model.v3.dev1.common.VisibilityType 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

OrcidAccessControlException (org.orcid.core.exception.OrcidAccessControlException)2 AccessControlException (java.security.AccessControlException)1 NoResultException (javax.persistence.NoResultException)1 DeactivatedException (org.orcid.core.exception.DeactivatedException)1 OrcidDeprecatedException (org.orcid.core.exception.OrcidDeprecatedException)1 OrcidNotClaimedException (org.orcid.core.exception.OrcidNotClaimedException)1 OrcidUnauthorizedException (org.orcid.core.exception.OrcidUnauthorizedException)1 OrcidVisibilityException (org.orcid.core.exception.OrcidVisibilityException)1 WrongSourceException (org.orcid.core.exception.WrongSourceException)1 LockedException (org.orcid.core.security.aop.LockedException)1 Filterable (org.orcid.jaxb.model.v3.dev1.common.Filterable)1 VisibilityType (org.orcid.jaxb.model.v3.dev1.common.VisibilityType)1 Email (org.orcid.jaxb.model.v3.dev1.record.Email)1 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)1