Search in sources :

Example 1 with AfterReturning

use of org.aspectj.lang.annotation.AfterReturning in project ORCID-Source by ORCID.

the class ProfileLastModifiedAspect method updateProfileLastModified.

@AfterReturning(POINTCUT_DEFINITION_BASE + " && args(profileAware, ..)")
public void updateProfileLastModified(JoinPoint joinPoint, ProfileAware profileAware) {
    if (!enabled) {
        return;
    }
    ProfileEntity profile = profileAware.getProfile();
    if (profile != null) {
        String orcid = profile.getId();
        updateProfileLastModified(joinPoint, orcid);
    }
}
Also used : ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 2 with AfterReturning

use of org.aspectj.lang.annotation.AfterReturning in project entando-core by entando.

the class UserProfileManager method injectProfile.

@AfterReturning(pointcut = "execution(* com.agiletec.aps.system.services.user.IUserManager.getUser(..))", returning = "user")
public void injectProfile(Object user) {
    if (user != null) {
        AbstractUser userDetails = (AbstractUser) user;
        if (null == userDetails.getProfile()) {
            try {
                IUserProfile profile = this.getProfile(userDetails.getUsername());
                userDetails.setProfile(profile);
            } catch (Throwable t) {
                logger.error("Error injecting profile on user {}", userDetails.getUsername(), t);
            }
        }
    }
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) AbstractUser(com.agiletec.aps.system.services.user.AbstractUser) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 3 with AfterReturning

use of org.aspectj.lang.annotation.AfterReturning in project entando-core by entando.

the class UserProfileManager method addProfile.

@AfterReturning(pointcut = "execution(* com.agiletec.aps.system.services.user.IUserManager.addUser(..)) && args(user,..)")
public void addProfile(Object user) {
    if (user != null) {
        UserDetails userDetails = (UserDetails) user;
        Object profile = userDetails.getProfile();
        if (null != profile) {
            try {
                this.addProfile(userDetails.getUsername(), (IUserProfile) profile);
            } catch (Throwable t) {
                logger.error("Error adding profile on user {}", userDetails.getUsername(), t);
            }
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 4 with AfterReturning

use of org.aspectj.lang.annotation.AfterReturning in project ORCID-Source by ORCID.

the class OrcidApiAuthorizationSecurityAspect method visibilityResponseFilter.

@AfterReturning(pointcut = "@annotation(accessControl)", returning = "response")
public void visibilityResponseFilter(Response response, AccessControl accessControl) {
    if (accessControl.requestComesFromInternalApi()) {
        return;
    }
    Object entity = response.getEntity();
    if (entity != null && OrcidMessage.class.isAssignableFrom(entity.getClass())) {
        OrcidMessage orcidMessage = (OrcidMessage) entity;
        // If it is search results, don't filter them, just return them
        if (orcidMessage.getOrcidSearchResults() != null) {
            return;
        }
        // get the client id
        Object authentication = getAuthentication();
        Set<Visibility> visibilities = new HashSet<Visibility>();
        if (allowAnonymousAccess((Authentication) authentication, accessControl)) {
            visibilities.add(Visibility.PUBLIC);
        } else {
            visibilities = permissionChecker.obtainVisibilitiesForAuthentication(getAuthentication(), accessControl.requiredScope(), orcidMessage);
        }
        // If the message contains a bio, and the given name is filtered, restore it as an empty space
        boolean setEmptyGivenNameIfFiltered = false;
        if (orcidMessage.getOrcidProfile() != null) {
            if (orcidMessage.getOrcidProfile() != null && orcidMessage.getOrcidProfile().getOrcidBio() != null) {
                setEmptyGivenNameIfFiltered = true;
            }
        }
        ScopePathType requiredScope = accessControl.requiredScope();
        // If the required scope is */read-limited or */update
        if (isUpdateOrReadScope(requiredScope)) {
            // if it should be able to
            if (OrcidOAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
                OrcidOAuth2Authentication orcidAuth = (OrcidOAuth2Authentication) getAuthentication();
                OAuth2Request authorization = orcidAuth.getOAuth2Request();
                String clientId = authorization.getClientId();
                // #1: Get the user orcid
                String userOrcid = getUserOrcidFromOrcidMessage(orcidMessage);
                // #2: Evaluate the scope to know which field to filter
                boolean allowWorks = false;
                boolean allowFunding = false;
                boolean allowAffiliations = false;
                // Get the update equivalent scope, if it is reading, but,
                // doesnt have the read permissions, check if it have the
                // update permissions
                ScopePathType equivalentUpdateScope = getEquivalentUpdateScope(requiredScope);
                if (requiredScope.equals(ScopePathType.READ_LIMITED)) {
                    if (hasScopeEnabled(clientId, userOrcid, ScopePathType.ORCID_WORKS_READ_LIMITED.getContent(), ScopePathType.ORCID_WORKS_UPDATE.getContent()))
                        allowWorks = true;
                    if (hasScopeEnabled(clientId, userOrcid, ScopePathType.FUNDING_READ_LIMITED.getContent(), ScopePathType.FUNDING_UPDATE.getContent()))
                        allowFunding = true;
                    if (hasScopeEnabled(clientId, userOrcid, ScopePathType.AFFILIATIONS_READ_LIMITED.getContent(), ScopePathType.AFFILIATIONS_UPDATE.getContent()))
                        allowAffiliations = true;
                } else if (requiredScope.equals(ScopePathType.ORCID_WORKS_UPDATE) || requiredScope.equals(ScopePathType.ORCID_WORKS_READ_LIMITED)) {
                    // works
                    if (hasScopeEnabled(clientId, userOrcid, requiredScope.getContent(), equivalentUpdateScope == null ? null : equivalentUpdateScope.getContent()))
                        // If so, allow him to see private works
                        allowWorks = true;
                } else if (requiredScope.equals(ScopePathType.FUNDING_UPDATE) || requiredScope.equals(ScopePathType.FUNDING_READ_LIMITED)) {
                    // funding
                    if (hasScopeEnabled(clientId, userOrcid, requiredScope.getContent(), equivalentUpdateScope == null ? null : equivalentUpdateScope.getContent()))
                        // If so, allow him to see private funding
                        allowFunding = true;
                } else if (requiredScope.equals(ScopePathType.AFFILIATIONS_UPDATE) || requiredScope.equals(ScopePathType.AFFILIATIONS_READ_LIMITED)) {
                    // affiliations
                    if (hasScopeEnabled(clientId, userOrcid, requiredScope.getContent(), equivalentUpdateScope == null ? null : equivalentUpdateScope.getContent()))
                        // If so, allow him to see private affiliations
                        allowAffiliations = true;
                }
                visibilityFilter.filter(orcidMessage, clientId, allowWorks, allowFunding, allowAffiliations, visibilities.toArray(new Visibility[visibilities.size()]));
            } else {
                visibilityFilter.filter(orcidMessage, null, false, false, false, visibilities.toArray(new Visibility[visibilities.size()]));
            }
        } else {
            visibilityFilter.filter(orcidMessage, null, false, false, false, visibilities.toArray(new Visibility[visibilities.size()]));
        }
        // If the given name was set at the beginning and now is filtered, it means we should restore it as an empty field
        if (setEmptyGivenNameIfFiltered) {
            if (orcidMessage.getOrcidProfile() != null) {
                if (orcidMessage.getOrcidProfile().getOrcidBio() == null) {
                    orcidMessage.getOrcidProfile().setOrcidBio(new OrcidBio());
                }
                if (orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails() == null) {
                    orcidMessage.getOrcidProfile().getOrcidBio().setPersonalDetails(new PersonalDetails());
                }
            }
        }
        // Filter given or family names visibility
        if (orcidMessage.getOrcidProfile() != null) {
            if (orcidMessage.getOrcidProfile().getOrcidBio() != null) {
                if (orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails() != null) {
                    if (orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames() != null) {
                        orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames().setVisibility(null);
                    } else {
                        // Null given names could break client integrations, so, lets return an empty string
                        GivenNames empty = new GivenNames();
                        empty.setContent(StringUtils.EMPTY);
                        orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().setGivenNames(empty);
                    }
                    if (orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName() != null) {
                        orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName().setVisibility(null);
                    }
                }
            }
        }
        // replace section visibilities now we may have filtered items
        if (orcidMessage.getOrcidProfile() != null) {
            if (orcidMessage.getOrcidProfile().getOrcidBio() != null) {
                if (orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails() != null) {
                    OtherNames n = orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getOtherNames();
                    if (n != null) {
                        n.setVisibility(getMostFromCollection(n.getOtherName()));
                    }
                }
                ExternalIdentifiers ids = orcidMessage.getOrcidProfile().getOrcidBio().getExternalIdentifiers();
                if (ids != null) {
                    ids.setVisibility(getMostFromCollection(ids.getExternalIdentifier()));
                }
                Keywords kws = orcidMessage.getOrcidProfile().getOrcidBio().getKeywords();
                if (kws != null) {
                    kws.setVisibility(getMostFromCollection(kws.getKeyword()));
                }
                ResearcherUrls urls = orcidMessage.getOrcidProfile().getOrcidBio().getResearcherUrls();
                if (urls != null) {
                    urls.setVisibility(getMostFromCollection(urls.getResearcherUrl()));
                }
            }
        }
    }
}
Also used : Keywords(org.orcid.jaxb.model.message.Keywords) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) OtherNames(org.orcid.jaxb.model.message.OtherNames) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) GivenNames(org.orcid.jaxb.model.message.GivenNames) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) ResearcherUrls(org.orcid.jaxb.model.message.ResearcherUrls) Visibility(org.orcid.jaxb.model.message.Visibility) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) HashSet(java.util.HashSet) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Example 5 with AfterReturning

use of org.aspectj.lang.annotation.AfterReturning in project spf4j by zolyfarkas.

the class SamplingAllocationMonitorAspect method afterAllocation.

@AfterReturning(pointcut = "call(*.new(..))", returning = "obj", argNames = "jp,obj")
public void afterAllocation(final JoinPoint jp, final Object obj) {
    MutableInteger counter = ThreadLocalCounter.get();
    int value = counter.getValue();
    if (value < SAMPLE_COUNT) {
        counter.setValue(value + 1);
    } else {
        // the stack trace get and the object size method are expensive to be done at every allocation...
        counter.setValue(0);
        StackTrace st = StackTrace.from(Thread.currentThread().getStackTrace(), 2);
        RECORDER.getRecorder(st).record(InstrumentationHelper.getObjectSize(obj));
    }
}
Also used : StackTrace(org.spf4j.stackmonitor.StackTrace) MutableInteger(org.spf4j.base.MutableInteger) JoinPoint(org.aspectj.lang.JoinPoint) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Aggregations

AfterReturning (org.aspectj.lang.annotation.AfterReturning)16 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 AbstractUser (com.agiletec.aps.system.services.user.AbstractUser)2 User (com.topcom.cms.domain.User)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JoinPoint (org.aspectj.lang.JoinPoint)2 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)2 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)2 ValidateAnnotation (com.paascloud.core.annotation.ValidateAnnotation)1 BaseEntityModel (com.topcom.cms.base.model.BaseEntityModel)1 LoginLog (com.topcom.cms.domain.LoginLog)1 OperationLog (com.topcom.cms.domain.OperationLog)1 OperationRecord (com.weibo.model.OperationRecord)1 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 HashSet (java.util.HashSet)1 AfterThrowing (org.aspectj.lang.annotation.AfterThrowing)1 Profile (org.craftercms.profile.api.Profile)1 Authentication (org.craftercms.security.authentication.Authentication)1 DefaultAuthentication (org.craftercms.security.authentication.impl.DefaultAuthentication)1