Example usage for org.aspectj.lang ProceedingJoinPoint toString

List of usage examples for org.aspectj.lang ProceedingJoinPoint toString

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint toString.

Prototype

String toString();

Source Link

Usage

From source file:org.opentestsystem.delivery.testreg.aop.SecuredAnnotationAspect.java

License:Open Source License

@Around("execution(* org.opentestsystem.delivery.test*.*.*Controller.*(..)) && @annotation(method) && @annotation(secured)")
public Object aroundMethodInControllerClass(ProceedingJoinPoint pjp, final RequestMapping method,
        final Secured secured) throws Throwable {

    String[] permissions = secured.value();
    Object[] params = pjp.getArgs();
    Object retVal = null;// ww w. ja v a 2  s. co  m

    if (method.method() != null) {
        for (RequestMethod requestMethod : method.method()) {
            LOGGER.debug("intercepting " + requestMethod + " for " + pjp.toString() + " secured by "
                    + permissionArrayToString(permissions));
            if (requestMethod.equals(POST) || requestMethod.equals(PUT) || requestMethod.equals(DELETE)
                    || requestMethod.equals(PATCH)) {
                // in these situations we need to check the incoming params to deduce if we have access prior to the
                // action
                if (params != null) {
                    if (!checkIncomingParameters(params, permissions)) {
                        throw new AccessDeniedException("permission denied");
                    }
                    // in this special case we want to check if the file upload type specified in the params matches
                    // what file upload permission(s) the user has...
                    // they are allowed to upload based on having any one of these: "ROLE_Accommodations Upload",
                    // "ROLE_Student Upload", "ROLE_Entity Upload", "ROLE_StudentGroup Upload", "ROLE_User Upload, "ROLE_ExplicitEligibility Upload"
                    if (pjp.getSignature().getName().equals("uploadFile")
                            && pjp.getSignature().getDeclaringType().equals(Class.forName(
                                    "org.opentestsystem.delivery.testreg.rest.FileUploadDataController"))) {
                        // We should throw AccessDeniedException here if they don't have the proper upload
                        // role based on the file upload type (check params)
                        SbacUser currentUser = testRegUserDetailsService.getCurrentUser();
                        String testRegPermission = getCorrectRolePermissionByFormatType((String) params[1]);
                        // checking if logged-in-user has permission to upload corresponding file(user/student/institutions/..)
                        if (currentUser != null && !currentUser.hasPermission(testRegPermission)) {
                            throw new AccessDeniedException("permission denied");
                        }
                    } else if (pjp.getSignature().getName().equals("saveStudents")
                            && pjp.getSignature().getDeclaringType().equals(Class.forName(
                                    "org.opentestsystem.delivery.testreg.rest.ExternalStudentController"))) {
                        // We should throw AccessDeniedException here if they don't have the proper upload
                        // role based on the file upload type (check params)
                        SbacUser currentUser = testRegUserDetailsService.getCurrentUser();
                        String testRegPermission = getCorrectRolePermissionByFormatType("STUDENT");
                        // checking if logged-in-user has permission to upload corresponding file(user/student/institutions/..)
                        if (currentUser != null && !currentUser.hasPermission(testRegPermission)) {
                            throw new AccessDeniedException("permission denied");
                        }
                    }
                }
                // we let things continue normally...
                retVal = pjp.proceed();
            } else if (requestMethod.equals(GET)) {
                // in these situations we need to check the return values to determine if we have access
                retVal = pjp.proceed();
                if (retVal != null && !checkReturnValue(retVal, permissions)) {
                    throw new AccessDeniedException("permission denied");
                }
            } else {
                // for now we only handle securing methods get/post/put/delete (enhance code here for additional
                // request methods)
                throw new AccessDeniedException(
                        "non-standard request type for a @Secured rest request: " + requestMethod);
            }
        }
    }
    return retVal;
}

From source file:org.osaf.cosmo.security.aop.SecurityAdviceMonitor.java

License:Apache License

@Around("execution(* org.osaf.cosmo.service.ContentService.*(..))")
public Object baseSecurityCheck(ProceedingJoinPoint pjp) throws Throwable {

    if (log.isDebugEnabled())
        log.debug("in baseSecurityCheck()");

    SecurityAdvice.setSecured(false);//from w w  w  . j a va2 s  . c o m
    Object returnVal = pjp.proceed();
    if (SecurityAdvice.getSecured() == Boolean.FALSE)
        log.warn("method not secured: " + pjp.toString());
    SecurityAdvice.setSecured(false);
    return returnVal;
}

From source file:ru.stoloto.contacts.aop.LoggingUserOperationsAspect.java

@Around("authLogExecution()")
public Object authLogExecution(ProceedingJoinPoint joinPoint) throws Throwable {

    log.info(joinPoint.toString());

    Object object = joinPoint.proceed();

    return object;
}

From source file:ru.stoloto.contacts.aop.LoggingUserOperationsAspect.java

@Around("authLogControllerExecution()")
public Object authLogControllerExecution(ProceedingJoinPoint joinPoint) throws Throwable {

    log.info(joinPoint.toString());

    Object object = joinPoint.proceed();

    return object;
}

From source file:shiver.me.timbers.waiting.WaiterAspect.java

License:Apache License

@SuppressWarnings("unchecked")
private Object wait(final ProceedingJoinPoint joinPoint, Wait wait) throws Exception {
    return waiterLoader.load(optionsLoader.load(wait)).wait(new Until() {
        @Override/*from  w ww  . j  a  v a 2s.  c  o m*/
        public Object success() throws Throwable {
            return joinPoint.proceed();
        }

        @Override
        public String toString() {
            return joinPoint.toString();
        }
    });
}

From source file:shiver.me.timbers.waiting.WaiterAspectTest.java

License:Apache License

@Test
public void Can_wait_for_method_in_class() throws Throwable {

    final ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
    final Wait wait = mock(Wait.class);

    final WaiterService waiterService = mock(WaiterService.class);
    final OptionsService options = mock(OptionsService.class);

    final Signature signature = mock(Signature.class);
    final String[] toString = new String[1];
    final Object[] success = new Object[1];
    final Object expected = new Object();

    // Given//from  w w w  . j a va2 s  .  c o  m
    given(joinPoint.getSignature()).willReturn(signature);
    given(signature.getDeclaringType()).willReturn(Object.class);
    given(signature.getName()).willReturn(someString());
    given(optionsLoader.load(wait)).willReturn(options);
    given(waiterLoader.load(options)).willReturn(waiterService);
    willAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final Until until = (Until) invocation.getArguments()[0];
            toString[0] = until.toString();
            return success[0] = until.success();
        }
    }).given(waiterService).wait(any(Until.class));
    given(joinPoint.proceed()).willReturn(expected);

    // When
    final Object actual = aspect.waitOnClass(joinPoint, wait);

    // Then
    assertThat(actual, is(success[0]));
    assertThat(actual, is(expected));
    assertThat(joinPoint.toString(), is(toString[0]));
}

From source file:shiver.me.timbers.waiting.WaiterAspectTest.java

License:Apache License

@Test
public void Can_wait_for_method() throws Throwable {

    final ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
    final Wait wait = mock(Wait.class);

    final WaiterService waiterService = mock(WaiterService.class);
    final OptionsService options = mock(OptionsService.class);

    final String[] toString = new String[1];
    final Object[] success = new Object[1];
    final Object expected = new Object();

    // Given/* w  w w .j  a  v  a 2s  . co  m*/
    given(optionsLoader.load(wait)).willReturn(options);
    given(waiterLoader.load(options)).willReturn(waiterService);
    willAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final Until until = (Until) invocation.getArguments()[0];
            toString[0] = until.toString();
            return success[0] = until.success();
        }
    }).given(waiterService).wait(any(Until.class));
    given(joinPoint.proceed()).willReturn(expected);

    // When
    final Object actual = aspect.waitOnMethod(joinPoint, wait);

    // Then
    assertThat(actual, is(success[0]));
    assertThat(actual, is(expected));
    assertThat(joinPoint.toString(), is(toString[0]));
}