use of org.aspectj.lang.ProceedingJoinPoint in project PhotoNoter by yydcdut.
the class PermissionAspect method aroundCheckAndRequestPermission.
@Around("pointcut2CheckAndRequestPermissions(permission)")
public void aroundCheckAndRequestPermission(ProceedingJoinPoint proceedingJoinPoint, Permission permission) {
if (permission == null) {
return;
}
IPresenter iPresenter = (IPresenter) proceedingJoinPoint.getTarget();
int value = permission.value();
switch(value) {
case PermissionUtils.CODE_CAMERA:
case PermissionUtils.CODE_ADJUST_CAMERA:
{
if (hasPermission4Camera(PermissionInstance.context)) {
try {
proceedingJoinPoint.proceed();
} catch (Throwable throwable) {
YLog.e(throwable);
}
} else {
if (iPresenter.getIView().getRequestType().isActivity()) {
requestPermissions4Activity(iPresenter.getIView().getRequestType().getActivity(), PermissionInstance.context.getString(R.string.permission_camera_init), PermissionUtils.PERMISSION_CAMERA, value);
} else {
requestPermissions4Fragment(iPresenter.getIView().getRequestType().getFragment(), PermissionInstance.context.getString(R.string.permission_camera_init), PermissionUtils.PERMISSION_CAMERA, value);
}
}
}
break;
case PermissionUtils.CODE_STORAGE:
{
if (hasPermission4Storage(PermissionInstance.context)) {
try {
proceedingJoinPoint.proceed();
} catch (Throwable throwable) {
YLog.e(throwable);
}
} else {
if (iPresenter.getIView().getRequestType().isActivity()) {
requestPermissions4Activity(iPresenter.getIView().getRequestType().getActivity(), PermissionInstance.context.getString(R.string.permission_storage_init), PermissionUtils.PERMISSION_STORAGE, value);
} else {
requestPermissions4Fragment(iPresenter.getIView().getRequestType().getFragment(), PermissionInstance.context.getString(R.string.permission_storage_init), PermissionUtils.PERMISSION_STORAGE, value);
}
}
}
break;
case PermissionUtils.CODE_LOCATION_AND_CAMERA:
{
if (hasPermission4LocationAndCamera(PermissionInstance.context)) {
try {
proceedingJoinPoint.proceed();
} catch (Throwable throwable) {
YLog.e(throwable);
}
} else {
if (iPresenter.getIView().getRequestType().isActivity()) {
requestPermissions4Activity(iPresenter.getIView().getRequestType().getActivity(), PermissionInstance.context.getString(R.string.permission_location), PermissionUtils.PERMISSION_LOCATION_AND_CAMERA, value);
} else {
requestPermissions4Fragment(iPresenter.getIView().getRequestType().getFragment(), PermissionInstance.context.getString(R.string.permission_location), PermissionUtils.PERMISSION_LOCATION_AND_CAMERA, value);
}
}
}
break;
case PermissionUtils.CODE_AUDIO:
{
if (hasPermission4Audio(PermissionInstance.context)) {
try {
proceedingJoinPoint.proceed();
} catch (Throwable throwable) {
YLog.e(throwable);
}
} else {
if (iPresenter.getIView().getRequestType().isActivity()) {
requestPermissions4Activity(iPresenter.getIView().getRequestType().getActivity(), PermissionInstance.context.getString(R.string.permission_audio), PermissionUtils.PERMISSION_AUDIO, value);
} else {
requestPermissions4Fragment(iPresenter.getIView().getRequestType().getFragment(), PermissionInstance.context.getString(R.string.permission_audio), PermissionUtils.PERMISSION_AUDIO, value);
}
}
}
break;
case PermissionUtils.CODE_PHONE_STATE:
{
if (hasPermission4PhoneState(PermissionInstance.context)) {
try {
proceedingJoinPoint.proceed();
} catch (Throwable throwable) {
YLog.e(throwable);
}
} else {
if (iPresenter.getIView().getRequestType().isActivity()) {
requestPermissions4Activity(iPresenter.getIView().getRequestType().getActivity(), PermissionInstance.context.getString(R.string.permission_phone_state), PermissionUtils.PERMISSION_PHONE_STATE, value);
} else {
requestPermissions4Fragment(iPresenter.getIView().getRequestType().getFragment(), PermissionInstance.context.getString(R.string.permission_phone_state), PermissionUtils.PERMISSION_PHONE_STATE, value);
}
}
}
break;
}
}
use of org.aspectj.lang.ProceedingJoinPoint in project gocd by gocd.
the class InterceptorInjectorTest method testShouldReturnNullWhenNoHandlerFound.
@Test
public void testShouldReturnNullWhenNoHandlerFound() throws Throwable {
ProceedingJoinPoint proceedingJoinPoint = mock(ProceedingJoinPoint.class);
when(proceedingJoinPoint.proceed()).thenReturn(null);
InterceptorInjector injector = new InterceptorInjector();
HandlerExecutionChain handlers = injector.mergeInterceptorsToTabs(proceedingJoinPoint);
assertNull(handlers);
}
use of org.aspectj.lang.ProceedingJoinPoint in project JavaForFun by gumartinm.
the class DeadlockRetryAspect method doAround.
@Around(value = "@annotation(deadlockRetry)", argNames = "deadlockRetry")
public Object doAround(final ProceedingJoinPoint pjp, final DeadlockRetry deadlockRetry) throws Throwable {
final int maxTries = deadlockRetry.maxTries();
final long interval = deadlockRetry.interval();
final Object target = pjp.getTarget();
final MethodSignature signature = (MethodSignature) pjp.getSignature();
final Method method = signature.getMethod();
int count = 0;
Throwable lastException = null;
do {
try {
count++;
logger.info("Attempting to invoke method " + method.getName() + " on " + target.getClass() + " count " + count);
// Calling real method
final Object result = pjp.proceed();
logger.info("Completed invocation of method " + method.getName() + " on " + target.getClass());
return result;
} catch (final Throwable ex) {
if (!isDeadLock(ex)) {
throw ex;
}
lastException = ex;
if (interval > 0) {
try {
Thread.sleep(interval);
} catch (final InterruptedException exi) {
logger.warn("Deadlock retry thread interrupt", exi);
// Restore interrupt status.
Thread.currentThread().interrupt();
}
}
}
} while (count < maxTries);
// The exception being thrown will depend on the API that you are using.
throw lastException;
}
use of org.aspectj.lang.ProceedingJoinPoint in project irida by phac-nml.
the class RunAsUserAspect method setSecurityContextFromAnalysisSubmission.
/**
* Advice around a method annotated with {@link RunAsUser}. This method will
* set the {@link User} specified in the {@link RunAsUser#value()} using
* SpEL in the security context before the method is run, then reset the
* original user after the method completes.
*
* @param jp
* {@link ProceedingJoinPoint} for the called method
* @param userAnnotation
* {@link RunAsUser} annotation specifying the user
* @return Return value of the method called
* @throws Throwable
* if the method throws an exception
*/
@Around(value = "execution(* *(..)) && @annotation(userAnnotation)")
public Object setSecurityContextFromAnalysisSubmission(ProceedingJoinPoint jp, RunAsUser userAnnotation) throws Throwable {
// Get the method arguments and apply them to an evaluation context
MethodSignature signature = (MethodSignature) jp.getSignature();
String[] parameterNames = signature.getParameterNames();
Object[] args = jp.getArgs();
StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
for (int i = 0; i < args.length; i++) {
String name = parameterNames[i];
Object val = args[i];
evaluationContext.setVariable(name, val);
}
// get the expression from the annotation and apply it to the evaluation
// context
String expression = userAnnotation.value();
ExpressionParser parser = new SpelExpressionParser();
Expression parseExpression = parser.parseExpression(expression);
Object expressionValue = parseExpression.getValue(evaluationContext);
if (!(expressionValue instanceof User)) {
throw new IllegalArgumentException("RunAsUser value must refer to a User");
}
User submitter = (User) expressionValue;
// get the original security context
logger.trace("Updating user authentication");
SecurityContext originalConext = SecurityContextHolder.getContext();
logger.trace("Original user: " + originalConext.getAuthentication().getName());
logger.trace("Setting user " + submitter.getUsername());
Object returnValue = null;
try {
// set the new user authentication
PreAuthenticatedAuthenticationToken submitterAuthenticationToken = new PreAuthenticatedAuthenticationToken(submitter, null, Lists.newArrayList(submitter.getSystemRole()));
SecurityContext newContext = SecurityContextHolder.createEmptyContext();
newContext.setAuthentication(submitterAuthenticationToken);
SecurityContextHolder.setContext(newContext);
// run the method
returnValue = jp.proceed();
} finally {
// return the old authentication
logger.trace("Resetting authentication to " + originalConext.getAuthentication().getName());
SecurityContextHolder.setContext(originalConext);
}
return returnValue;
}
use of org.aspectj.lang.ProceedingJoinPoint in project onebusaway-application-modules by camsys.
the class CacheableMethodKeyFactoryManager method getMatchingMethodsForJoinPoint.
public List<Method> getMatchingMethodsForJoinPoint(ProceedingJoinPoint pjp) {
Signature sig = pjp.getSignature();
Object target = pjp.getTarget();
Class<?> type = target.getClass();
List<Method> matches = new ArrayList<Method>();
for (Method m : type.getDeclaredMethods()) {
if (!m.getName().equals(sig.getName()))
continue;
// if (m.getModifiers() != sig.getModifiers())
// continue;
Object[] args = pjp.getArgs();
Class<?>[] types = m.getParameterTypes();
if (args.length != types.length)
continue;
boolean miss = false;
for (int i = 0; i < args.length; i++) {
Object arg = args[i];
Class<?> argType = types[i];
if (argType.isPrimitive()) {
if (argType.equals(Double.TYPE) && !arg.getClass().equals(Double.class))
miss = true;
} else {
if (arg != null && !argType.isInstance(arg))
miss = true;
}
}
if (miss)
continue;
matches.add(m);
}
return matches;
}
Aggregations