Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
///*
// * Copyright (c) 2017 The Hyve and respective contributors.
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * See the file LICENSE in the root of this dao.
// */
//
//package com.minlia.cloud.aop;
//
//import com.minlia.cloud.aop.common.IdentifiableRequest;
//import nl.thehyve.podium.common.IdentifiableRequest;
//import nl.thehyve.podium.common.aop.security.AccessPolicyAspect;
//import nl.thehyve.podium.common.IdentifiableOrganisation;
//import nl.thehyve.podium.common.IdentifiableUser;
//import nl.thehyve.podium.common.security.AuthorityConstants;
//import nl.thehyve.podium.common.security.annotations.*;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.Signature;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.lang.annotation.Annotation;
//import java.lang.reflect.Method;
//import java.lang.reflect.Parameter;
//import java.util.Arrays;
//import java.util.HashSet;
//import java.util.List;
//import java.util.Set;
//import java.util.UUID;
//import java.util.function.Function;
//import java.util.stream.Collectors;
//
///**
// * This service implements the security checks of the {@link AccessPolicyAspect}.
// * The list of supported annotations is in {@link #SECURITY_ANNOTATION_TYPES}.
// */
//@Service
//@Transactional
//public class AccessPolicyService {
//
// @Autowired
// SecurityService securityService;
//
// @Autowired
// RequestSecurityService requestSecurityService;
//
// private static final Logger log = LoggerFactory.getLogger(AccessPolicyService.class);
//
// private static final Set SECURITY_ANNOTATION_TYPES = new HashSet<>();
// {
// SECURITY_ANNOTATION_TYPES.add(Public.class);
// SECURITY_ANNOTATION_TYPES.add(AnyAuthorisedUser.class);
// SECURITY_ANNOTATION_TYPES.add(SecuredByAuthority.class);
// SECURITY_ANNOTATION_TYPES.add(SecuredByOrganisation.class);
// SECURITY_ANNOTATION_TYPES.add(SecuredByCurrentUser.class);
// SECURITY_ANNOTATION_TYPES.add(SecuredByRequestOwner.class);
// SECURITY_ANNOTATION_TYPES.add(SecuredByRequestOrganisationCoordinator.class);
// SECURITY_ANNOTATION_TYPES.add(SecuredByRequestOrganisationReviewer.class);
// }
//
// /**
// * Check if the annotation is a supported security annotation.
// * @param annotation The annotation to be checked.
// * @return true iff the annotation is of a type supported by this service.
// */
// public static boolean isSecurityAnnotation(Annotation annotation) {
// if (annotation == null) {
// return false;
// }
// return SECURITY_ANNOTATION_TYPES.contains(annotation.annotationType());
// }
//
// /**
// * Checks if the current user has any of the authorities listed in {@code annotation}.
// * @param annotation the {@link SecuredByAuthority} annotation.
// * @return true iff the current user has any of the authorities in {@code annotation}.
// */
// private boolean checkSecuredByAuthority(SecuredByAuthority annotation) {
// for (String authority: annotation.value()) {
// log.info("Annotation authority: {}", authority);
// }
// if (securityService.isCurrentUserInAnyRole(annotation.value())) {
// log.info("Access granted to user based on authorities {}",
// Arrays.toString(annotation.value()));
// return true;
// } else {
// log.info("Access denied to user based on authorities {}",
// Arrays.toString(annotation.value()));
// return false;
// }
// }
//
// private static UUID getOrganisationUuid(Object object) {
// if (!IdentifiableOrganisation.class.isAssignableFrom(object.getClass())) {
// log.error("Parameter value has the wrong type: {} (expected {}).",
// object.getClass().getSimpleName(),
// IdentifiableOrganisation.class.getSimpleName()
// );
// return null;
// }
// IdentifiableOrganisation organisation = (IdentifiableOrganisation)object;
// return organisation.getOrganisationUuid();
// }
//
// private static UUID getUserUuid(Object object) {
// if (!IdentifiableUser.class.isAssignableFrom(object.getClass())) {
// log.error("Parameter value has the wrong type: {} (expected {}).",
// object.getClass().getSimpleName(),
// IdentifiableUser.class.getSimpleName()
// );
// return null;
// }
// IdentifiableUser user = (IdentifiableUser)object;
// return user.getUserUuid();
// }
//
// private static UUID getRequestUuid(Object object) {
// if (!IdentifiableRequest.class.isAssignableFrom(object.getClass())) {
// log.error("Parameter value has the wrong type: {} (expected {}).",
// object.getClass().getSimpleName(),
// IdentifiableRequest.class.getSimpleName()
// );
// return null;
// }
// IdentifiableRequest request = (IdentifiableRequest)object;
// return request.getRequestUuid();
// }
//
// /**
// * Gets the parameter with name {@code name} from the current execution context ({@code joinPoint})
// * and returns the value with type {@code parameterType}.
// * Returns null if the parameter is not of a compatible type or if the metadata of the function cannot
// * be found (e.g., multiple methods with the same name).
// *
// * @param joinPoint the current execution context.
// * @return the value of the parameter with name @{code name} as type {@code parameterType} if
// * the value is of compatible type and the metadata can be found; null otherwise.
// */
// private UUID getUuid(JoinPoint joinPoint, Function