#InvocationHandler
Explore tagged Tumblr posts
rayleslie691 · 2 years ago
Text
I was .... by the rad h... society they put files through out my whole file system..... and all they was able to do... See how I got there what they thought would be files that I would not be able to to accomplish... and how I out done them by....
I cannot get these files out of my system because every time I would delete one it would just disappear and pop up somewhere else in my file so I devised the way to get rid of these system files that were latched onto my system I just took my complier and one by one opened their codes deleted the code out of the file resave the file and then just deleted the file with these the files that cannot…
View On WordPress
0 notes
simplexianpo · 5 years ago
Text
Spring Digging Road 3 - SpringAOP -
###Problems encountered in development :
```
Code confusion: after more and more non-business requirements (log and verification, etc.) are added, the original business methods expand rapidly, and each method must pay attention to other concerns while dealing with the core logic.
Code dispersion: Taking the log requirement as an example, in order to meet this single requirement, the same log code has to be repeated many times in multiple modules (methods). If the log requirements change, all modules must be modified.
```
###Use dynamic proxy to solve the above problems
Principle of proxy design pattern: **A proxy is used to wrap the object**, and then the proxy object replaces the original object. Any call to the original object must pass through the proxy, and the proxy object decides whether and when to transfer the method call to the original object.
 ###Dynamic agents generally use the process:
1.Define an interface
public interface Person {
    void showName();
    void doWork();
}
 2.Define a class to implement the interface
  public class Worker implements Person{
    @Override
    public void showName() {
        System.out.println("showName XXX");
    }
    @Override
    public void doWork() {
        System.out.println("doWork XXX");
    }
}
  3.Define a generic class
  public class WorkUtil {
    public void method1() {
        System.out.println("method1");
    }
    public void method2() {
        System.out.println("method2");
    }
}
 4.Define a class that implements the InvocationHandler interface.
 Defines the private property target of Object type.
 If the class has a parameter constructor, pass in this property.
 If the class has only parameterless constructors or does not explicitly declare constructors, write a shared static method, setTarget.
 Override the invoke method:
 The second three places need to be explicitly called in the method,
 The return value is allowed to be null.
   import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
public class MyInvocationHandler implements InvocationHandler {
    private Object target;
    public MyInvocationHandler(Object target) {
        this.target = target;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        WorkUtil wu = new WorkUtil();
        wu.method1();
        method.invoke(target, args);
        wu.method2();
    return null;
    }
}
5.Define a factory class
 Write getProxy method, the parameter is target of Object, and the return value is Object.  
 Instantiate the class of step 4,
 return Proxy.newProxyInstance(,,);
  import java.lang.reflect.Proxy;
public class MyProxyFactory {
    public static Object getProxy(Object target){
        MyInvocationHandler handler = new MyInvocationHandler(target);
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), handler);
    }
}
 6.Define a test class:
 Interface target = new instance ();
 Interface variable = (interface) factoryClass. getProxy(target);
 variable.xx// calls the method
  public class ProxyTest {
    public static void main(String[] args) {
        Person target = new Worker();
        Person person = (Person) MyProxyFactory.getProxy(target);
        person.doWork();
        person.showName();
    }
}
 Output result:
method1
doWork XXX
method2
method1
showName XXX
method2
 ##Aspect Oriented Programming (AOP)
What is slice-oriented programming?  
System logic is defined as cut plane, which makes it unnecessary to pay attention to the implementation of system logic in business logic. For example, system logic such as log, security, transaction, etc., will be interspersed in the whole application, and separated at this time, which will make the program easier to understand and maintain.
 ###Spring AOP  terminology
>**Aspect**
```
Cross-cutting concerns (functions that span multiple modules of an application) are special objects that are modularized.
```
>**Advice**
```
Notifications define what a slice is and when to use it. In addition to describing the work to be done by the slice, the notification also determines when it will be executed.
>Before : Call notification before calling the target method;
>After : Call notification after the target method is called;
>After-returning : Call notification when the target method returns success;
>After-throwing : Call notification after the target method throws an exception;
>Around : The notification will be called before and after the target method is called;
```
>**Target**
```
The object to be notified.
```
>**Join point**
```
A connection point refers to a specific point where a tangent plane can be inserted during application execution (when calling a method).
For example, before a method is called, after it is called, after the method throws an exception, etc.
The connection point is determined by two information: 1. The program execution point represented by the method; 2. Orientation indicated by relative points.
```
>**Pointcut**
```
A tangent point defines where notifications are used. Defines one or more connection points into which matching notifications are woven. Usually, you should specify the names of classes and methods, or use regular expressions to match.
```
>**Weaving**
```
The process of applying a slice to a target object and creating a new proxy object.
```
 ###Spring AOP Support
>Classic based on agent Spring AOP
>Pure POJO section
>@AspectJ Annotation-driven section
>injection type AspectJ
 Next is the code time,
Before coding, list my directory structure and the contents of pom.xml file:
Tumblr media Tumblr media
##Classic Spring AOP based on agent
The contents of springConfig.xml are as follows:
Tumblr media
SpringText.java The code of the file is:
package spring;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringTest {
    public static void main(String[] args) {
        AbstractApplicationContext context = new ClassPathXmlApplicationContext("/spring/springConfig.xml");
        TestInterface b = (TestInterface) context.getBean("proxy");
        b.print("something");
    }
}
interface TestInterface {
    void print(String str);
}
class A implements TestInterface {
    public void print(String str) {
        System.out.println("In the method of classA " + str);
    }
}
 The first is pre-notification. AopAdvice implements MethodBeforeAdvice. The code content of AopAdvice is as follows:
package spring;
  import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;
public class AopAdvice implements MethodBeforeAdvice {
    public void before(Method method, Object[] args, Object target) throws Throwable {
        System.out.println("method:" + method);
        System.out.println("args:" + args[0]);
        System.out.println("target:" + target.getClass().getName());
    }
}
  Running results are:
method:public abstract void spring.TestInterface.print(java.lang.String)
args:something
target:spring.A
In the method of classA something
 Post-notification, AopAdvice implements AfterReturningAdvice, and the code content of AopAdvice is as follows:
package spring;
import java.lang.reflect.Method;
import org.springframework.aop.AfterReturningAdvice;
public class AopAdvice implements AfterReturningAdvice {
    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        System.out.println("method:" + method);
        System.out.println("args:" + args[0]);
        System.out.println("target:" + target.getClass().getName());
    }
}
 The output result is:
In the method of classA something
method:public abstract void spring.TestInterface.print(java.lang.String)
args:something
target:spring.A
  Around the notification, AopAdvice implements MethodInterceptor, and the code content of AopAdvice is:
package spring; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; public class AopAdvice implements MethodInterceptor {     public Object invoke(MethodInvocation invocation) throws Throwable {         System.out.println("around begin");         System.out.println("method:" + invocation.getMethod());         System.out.println("args:" + invocation.getArguments()[0]);         System.out.println("target:" + invocation.getThis().getClass().getName());         Object returnValue = null;         try {             returnValue = invocation.proceed();         } catch (Exception e) {         System.out.println("around error");         e.printStackTrace();         }         System.out.println("around end");         return returnValue;     } }
 The content of the console output is:
around begin
method:public abstract void spring.TestInterface.print(java.lang.String)
args:something
target:spring.A
In the method of classA something
around end
 Of course, multiple notifications can be made at the same time. For example, the AopAdvice code is as follows:
package spring;
import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;
public class AopAdvice implements AfterReturningAdvice, MethodBeforeAdvice, MethodInterceptor {
    public void before(Method method, Object[] args, Object target) throws Throwable {
        System.out.println("method:" + method);
        System.out.println("args:" + args[0]);
        System.out.println("target:" + target.getClass().getName());
    }
    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        System.out.println("method:" + method);
        System.out.println("args:" + args[0]);
        System.out.println("target:" + target.getClass().getName());
    }
    public Object invoke(MethodInvocation invocation) throws Throwable {
        System.out.println("around begin");
        System.out.println("method:" + invocation.getMethod());
        System.out.println("args:" + invocation.getArguments()[0]);
        System.out.println("target:" + invocation.getThis().getClass().getName());
        Object returnValue = null;
        try {
            returnValue = invocation.proceed();
        } catch (Exception e) {
            System.out.println("around error");
            e.printStackTrace();
        }
        System.out.println("around end");
        return returnValue;
    }
}
 The output at this time is as follows:
around begin
method:public abstract void spring.TestInterface.print(java.lang.String)
args:something
target:spring.A
method:public abstract void spring.TestInterface.print(java.lang.String)
args:something
target:spring.A
In the method of classA something
method:public abstract void spring.TestInterface.print(java.lang.String)
args:something
target:spring.A
around end
 ##Next is the pojo way:
First of all, let's take a look at the contents of SpringTest:
package pojo;
  import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
public class SpringTest {
    public static void main(String[] args) {
        AbstractApplicationContext context = new ClassPathXmlApplicationContext("/pojo/springConfig.xml");
        A a = (A) context.getBean("a");
        a.print("test");
    }
}
interface TestInterface {
    void print(String str);
}
@Component
class A {
    public void print(String str) {
        System.out.println("In the method of classA " + str);
    }
}
 Then there is the content in AopAdvice:
package pojo;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
@Aspect
@Component
@EnableAspectJAutoProxy
public class AopAdvice {
    public void beforeAdvice(JoinPoint point) {
        System.out.println("method = " + point.getSignature().getName());
        System.out.println("args = " + point.getArgs()[0]);
        System.out.println("target = " + point.getTarget().getClass().getName());
    }
    public void afterAdvice(JoinPoint point) {
        System.out.println("method = " + point.getSignature().getName());
        System.out.println("args = " + point.getArgs()[0]);
        System.out.println("target = " + point.getTarget().getClass().getName());
    }
    public void aroundAdvice(ProceedingJoinPoint proc) {
        try {
            beforeAdvice(proc);
            Object returnValue = proc.proceed();
            afterAdvice(proc);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
 The first is the advance notice(Before):  
The contents of springConfig.xml are as follows:
Tumblr media
Output results are:
method = print
args = something
target = pojo.A
In the method of classA something
 Then there is the post notification(After):  
The contents of springConfig.xml are as follows:
Tumblr media
The output result is:
method = print
args = something
target = pojo.A
In the method of classA something
 Next is the surround notification(Around):
The contents of springConfig.xml are as follows:
Tumblr media
The output result is:
method = print
args = something
target = pojo.A
In the method of classA something
method = print
args = something
target = pojo.A
 ##Annotation-driven facets:
 At first, present the contents of springConfig.xml file:
Tumblr media
springTest Code:
package aspectj;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
public class SpringTest {
    public static void main(String[] args) {
        AbstractApplicationContext context = new ClassPathXmlApplicationContext("/aspectj/springConfig.xml");
        TestInterface a = (TestInterface) context.getBean("a");
a.print("dosomething");
    }
}
@Component
class A implements TestInterface {
    public void print(String str) {
        System.out.println("In the method of classA " + str);
    }
}
interface TestInterface {
    public void print(String str);
}
  The first is the advance notice(Before):  
AopAdvice Code:
package aspectj;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
@Aspect
@Component
@EnableAspectJAutoProxy
public class AopAdvice {
    @Before("execution(** aspectj.A.print(..))")
    public void beforeAdvice(JoinPoint point) {
        System.out.println("method = " + point.getSignature().getName());
        System.out.println("args = " + point.getArgs()[0]);
        System.out.println("target = " + point.getTarget().getClass().getName());
    }
}
 Running results are:
method = print
args = dosomething
target = aspectj.A
In the method of classA dosomething
 Then there is the post notification(After):
AopAdvice Code:
package aspectj;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
@Aspect
@Component
@EnableAspectJAutoProxy
public class AopAdvice {
    @After("execution(** aspectj.A.print(..))")
    public void afterAdvice(JoinPoint point) {
        System.out.println("method = " + point.getSignature().getName());
        System.out.println("args = " + point.getArgs()[0]);
        System.out.println("target = " + point.getTarget().getClass().getName());
    }
}
 The output result is:
In the method of classA dosomething
method = print
args = dosomething
target = aspectj.A
 Finally, around the notice(Around):  
AopAdvice Code:
package aspectj;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
@Aspect
@Component
@EnableAspectJAutoProxy
public class AopAdvice {
      @Pointcut("execution(** aspectj.A.print(..)) && args(str)")
    public void doSomething(String str) {
      }
      public void beforeAdvice(JoinPoint point) {
        System.out.println("method = " + point.getSignature().getName());
        System.out.println("args = " + point.getArgs()[0]);
        System.out.println("target = " + point.getTarget().getClass().getName());
    }
      public void afterAdvice(JoinPoint point) {
        System.out.println("method = " + point.getSignature().getName());
        System.out.println("args = " + point.getArgs()[0]);
        System.out.println("target = " + point.getTarget().getClass().getName());
    }
      @Around("doSomething(str)")
    public void aroundAdvice(ProceedingJoinPoint proc, String str) {
        beforeAdvice(proc);
        System.out.println("str:" + str);
        try {
            proc.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    afterAdvice(proc);
    }
}
 The output result is:
method = print
args = dosomething
target = aspectj.A
str:dosomething
In the method of classA dosomething
method = print
args = dosomething
target = aspectj.A
As for the last "Injected AspectJ", it is rarely used, so we will have a special topic in the future.
0 notes
rayleslie691 · 2 years ago
Text
I was hacked by the rad hat society they put files through out my whole file system..... and all they was able to do... See how I got there what they thought would be files that I would not be able to to accomplish... and how I out done them by....
I cannot get these files out of my system because every time I would delete one it would just disappear and pop up somewhere else in my file so I devised the way to get rid of these system files that were latched onto my system I just took my complier and one by one opened their codes deleted the code out of the file resave the file and then just deleted the file with these the files that cannot…
View On WordPress
0 notes
rayleslie691 · 2 years ago
Text
I was hacked by the rad hat society they put files through out my whole file system..... and all they was able to do... See how I got there what they thought would be files that I would not be able to to accomplish... and how I out done them by....
I cannot get these files out of my system because every time I would delete one it would just disappear and pop up somewhere else in my file so I devised the way to get rid of these system files that were latched onto my system I just took my complier and one by one opened their codes deleted the code out of the file resave the file and then just deleted the file with these the files that cannot…
View On WordPress
0 notes
rayleslie691 · 2 years ago
Text
In the code section, we are performing password hashing and verification using the SHA-256 algorithm. Let's go through the comments added to the code and understand their purpose:
/* * © 3:03pm/Tue/Oct/17/2023 Your Raymond Sedrick Leslie II * All rights reserved. * This code is released under the MIT License. * *𝖈𝖔𝖒.𝖘𝖆𝖋𝖙𝖞𝕱𝖎𝖗𝖘-𝖕𝖗𝖔𝖉𝖚𝖈𝖙𝖎𝖔𝖓𝖘 * * 𝕿𝖍𝖊 𝖕𝖚𝖗𝖕𝖔𝖘𝖊 𝖔𝖋 𝖙𝖍𝖎𝖘 𝖈𝖔𝖉𝖊 𝖎𝖘 𝖙𝖔 𝖒𝖆𝖐𝖊-𝖘𝖔𝖈𝖎𝖆𝖑-𝖒𝖊𝖉𝖎𝖆-𝖘𝖆𝖋𝖊-𝖆𝖘-𝖘𝖍𝖔𝖚𝖑𝖉-𝖇𝖊-𝖘𝖔-𝖚𝖘𝖊𝖗𝖘-𝖆𝖈𝖗𝖔𝖘𝖘-𝖙𝖍𝖊-𝖌𝖑𝖔𝖇-𝖈𝖆𝖓-𝖘𝖆𝖋𝖑𝖞-𝖒𝖊𝖊𝖙-𝖓𝖊𝖜-𝖋𝖗𝖎𝖊𝖓𝖉𝖘-𝖜𝖎𝖙𝖍-𝖓𝖔-𝖜𝖔𝖗𝖗𝖎𝖊𝖘-𝖔𝖋-𝖋𝖆𝖐𝖊-𝖘𝖈𝖆𝖒𝕬𝖗𝖙𝖎𝖘𝖙𝖊𝖘𝖙.*/ i mport org.mindrot.jbcrypt.BCrypt; class PasswordUtils { public static…
View On WordPress
0 notes