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.
96 lines
3.6 KiB
96 lines
3.6 KiB
package com.tptj.course.hg.auth.template; |
|
|
|
import com.fr.decision.webservice.impl.template.TemplateAuthType; |
|
import com.fr.decision.webservice.interceptor.handler.HyperlinkValidAttr; |
|
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
|
import com.fr.decision.webservice.v10.login.LoginService; |
|
import com.fr.decision.webservice.v10.login.TokenResource; |
|
import com.fr.decision.webservice.v10.template.TempAuthValidatorStatus; |
|
import com.fr.invoke.Reflect; |
|
import com.fr.stable.StringUtils; |
|
import com.fr.state.SateVariableManager; |
|
import com.fr.third.net.sf.cglib.proxy.Enhancer; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
import java.util.Map; |
|
import java.util.Set; |
|
|
|
|
|
/** |
|
* @author 秃破天际 |
|
* @version 10.0 |
|
* Created by 秃破天际 on 2021/6/23 |
|
**/ |
|
public class SpTemplateAuthType{ |
|
|
|
private static Enhancer enhancer = new Enhancer(); |
|
|
|
private static TemplateAuthType proxy( TemplateAuthType source ){ |
|
String key = SpTemplateAuthType.class.getName()+source.toInteger(); |
|
TemplateAuthType data = (TemplateAuthType) SateVariableManager.get( key ); |
|
if( null == data ){ |
|
data = source; |
|
} |
|
enhancer.setSuperclass( source.getClass() ); |
|
enhancer.setCallback( new MethodInterceptorImpl(data) ); |
|
return (TemplateAuthType)enhancer.create(); |
|
} |
|
|
|
private static TemplateAuthType unProxy( TemplateAuthType source ){ |
|
String key = SpTemplateAuthType.class.getName()+source.toInteger(); |
|
TemplateAuthType data = (TemplateAuthType) SateVariableManager.get( key ); |
|
SateVariableManager.remove(key); |
|
return null != data ? data : source; |
|
} |
|
|
|
public static void proxy(){ |
|
Map<Integer, TemplateAuthType> typeMap = Reflect.on(TemplateAuthType.class).get("typeMap"); |
|
Set<Map.Entry<Integer, TemplateAuthType>> entries = typeMap.entrySet(); |
|
for( Map.Entry<Integer, TemplateAuthType> entry : entries ){ |
|
TemplateAuthType type = proxy( entry.getValue() ); |
|
entry.setValue(type); |
|
} |
|
} |
|
|
|
public static void unProxy(){ |
|
Map<Integer, TemplateAuthType> typeMap = Reflect.on(TemplateAuthType.class).get("typeMap"); |
|
Set<Map.Entry<Integer, TemplateAuthType>> entries = typeMap.entrySet(); |
|
for( Map.Entry<Integer, TemplateAuthType> entry : entries ){ |
|
TemplateAuthType type = unProxy( entry.getValue() ); |
|
entry.setValue(type); |
|
} |
|
} |
|
|
|
private static String getUsername( HttpServletRequest request ){ |
|
try{ |
|
return LoginService.getInstance().loginStatusValid(request, TokenResource.COOKIE).getUsername(); |
|
}catch(Exception e){ |
|
|
|
} |
|
return StringUtils.EMPTY; |
|
} |
|
|
|
public static boolean templateAuth(TempAuthValidatorStatus status, |
|
HttpServletRequest request, String templateId) throws Exception{ |
|
String username = getUsername(request); |
|
boolean rt = TemplateAuth.check(request,templateId,username); |
|
if(rt){ |
|
//设置超链接获得权限 |
|
String key = StateHubUtils.initAuthKey(templateId); |
|
request.setAttribute(DecisionServiceConstants.FINE_DIGITAL_SIGNATURE,key); |
|
} |
|
return rt; |
|
} |
|
|
|
/** |
|
* 检查超链接权限 |
|
* @param attr |
|
* @return |
|
* @throws Exception |
|
*/ |
|
public static boolean hyperlinkTokenValid(HyperlinkValidAttr attr) throws Exception{ |
|
String mainTempId = attr.getHyperlinkMainTempId(); |
|
String signature = attr.getHyperlinkDigitalSignature(); |
|
return StateHubUtils.authKey(mainTempId,signature); |
|
} |
|
}
|
|
|