You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.3 KiB
62 lines
2.3 KiB
package com.tptj.course.hg.login.expand; |
|
|
|
|
|
import com.fr.decision.authority.data.User; |
|
import com.fr.decision.webservice.utils.ControllerFactory; |
|
import com.fr.decision.webservice.utils.controller.AuthenticController; |
|
import com.fr.invoke.Reflect; |
|
import com.fr.stable.web.Device; |
|
import com.fr.third.springframework.web.context.request.RequestContextHolder; |
|
import com.fr.third.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
import java.lang.reflect.Proxy; |
|
|
|
/** |
|
* @author 秃破天际 |
|
* @version 10.0 |
|
* Created by 秃破天际 on 2021/6/23 |
|
**/ |
|
public class SpControllerFactory extends ControllerFactory { |
|
|
|
private ControllerFactory old = null; |
|
|
|
public static void proxy(){ |
|
unProxy(); |
|
SpControllerFactory item = new SpControllerFactory( ControllerFactory.getInstance() ); |
|
Reflect.on(ControllerFactory.class).set("instance",item); |
|
} |
|
|
|
public static void unProxy(){ |
|
ControllerFactory instance = ControllerFactory.getInstance(); |
|
if( SpControllerFactory.class.getName().equals( instance.getClass().getName() ) ){ |
|
ControllerFactory old = Reflect.on(instance).get("old"); |
|
if( null != old ){ |
|
Reflect.on(ControllerFactory.class).set("instance",old); |
|
} |
|
} |
|
} |
|
|
|
private SpControllerFactory( ControllerFactory old ){ |
|
this.old = old; |
|
} |
|
|
|
public AuthenticController getAuthenticController(String userId) { |
|
final AuthenticController ctrl = super.getAuthenticController(userId); |
|
return (AuthenticController) Proxy.newProxyInstance( |
|
ctrl.getClass().getClassLoader(), |
|
new Class[]{AuthenticController.class}, |
|
(proxy, method, args) -> { |
|
if( "doAuthentication".equals(method.getName()) && 3 == args.length ){ |
|
String password = (String)args[1]; |
|
User user = (User)args[0]; |
|
Device device = (Device)args[2]; |
|
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
|
if( SpPassport.check(attrs.getRequest(),user,password,device) ){ |
|
return true; |
|
} |
|
} |
|
return method.invoke(ctrl,args); |
|
}); |
|
|
|
} |
|
}
|
|
|