package no.tornado.brap.servlet;
import no.tornado.brap.auth.*;
import no.tornado.brap.common.InputStreamArgumentPlaceholder;
import no.tornado.brap.common.InvocationRequest;
import no.tornado.brap.common.InvocationResponse;
import no.tornado.brap.exception.RemotingException;
import no.tornado.brap.modification.ChangesIgnoredModificationManager;
import no.tornado.brap.modification.ModificationManager;
import javax.servlet.*;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* This ProxyServlet is configured from web.xml for each service you wish
* to expose as a remoting service.
* <p/>
* This class provides the basic capabilities needed to instantiate and expose
* a remoting service. Only <code>service</code> is required. The rest of
* the parameters have default values.
* <p/>
* Concider subclassing to provide custom creation by overriding
* <code>getServiceWrapper</code> or just one of
* <code>getAuthenticationProvider</code> or <code>getAuthorizationProvider</code>.
* <p/>
* <p>Example of exposing a remoting service without requiring authentication:</p>
* <pre>
* <servlet>
* <servlet-name>hello</servlet-name>
* <servlet-class>no.tornado.brap.servlet.ProxyServlet</servlet-class>
* <init-param>
* <param-name>service</param-name>
* <param-value>class.of.the.service.to.instantiate</param-value>
* </init-param>
* <init-param>
* <param-name>authorizationProvider</param-name>
* <param-value>no.tornado.brap.auth.AuthenticationNotRequiredAuthorizer</param-value>
* </init-param>
* <load-on-startup>1</load-on-startup>
* </servlet>
* <servlet-mapping>
* <servlet-name>hello</servlet-name>
* <url-pattern>/remoting/hello</url-pattern>
* </servlet-mapping>
* </pre>
*/
public class ProxyServlet implements Servlet {
private static final Integer DEFAULT_STREAM_BUFFER_SIZE = 16384;
public final String INIT_PARAM_AUTHENTICATION_PROVIDER = "authenticationProvider";
public final String INIT_PARAM_AUTHORIZATION_PROVIDER = "authorizationProvider";
public final String INIT_PARAM_MODIFICATION_MANAGER = "modificationManager";
public final String INIT_PARAM_SERVICE = "service";
protected ServiceWrapper serviceWrapper;
protected ServletConfig servletConfig;
public void init(ServletConfig servletConfig) throws ServletException {
this.servletConfig = servletConfig;
try {
createServiceWrapper();
} catch (Exception e) {
throw new ServletException("Failed to instantiate the serviceWrapper", e);
}
}
/**
* Override this method to control every detail of the creation of the service wrapper.
* <p/>
* Normally you would just override one or more of the methods that provide the service wrapper details.
*
* @see ProxyServlet#getService()
* @see ProxyServlet#getAuthenticationProvider()
* @see ProxyServlet#getAuthorizationProvider()
*/
public void createServiceWrapper() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
serviceWrapper = new ServiceWrapper();
serviceWrapper.setService(getService());
serviceWrapper.setAuthenticationProvider(getAuthenticationProvider());
serviceWrapper.setAuthorizationProvider(getAuthorizationProvider());
serviceWrapper.setModificationManager(getModificationManager());
}
/**
* Override to configure a different Authorization Provider. The default provider
* authorizes every authenticated invocation. In many cases, requiring Authentication and providing
* an AuthenticationProvider is sufficient, but you can use the Authorization Provider
* to allow/deny access to spesific method-calls based on the principal in
* <code>AuthenticationContext#getPrincipal()</code>.
* <p/>
* You can either subclass or supply the "authorizationProvider" init-param to
* change the AuthorizationProvider.
*
* @return the AuthorizationProvider
*/
protected AuthorizationProvider getAuthorizationProvider() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
if (servletConfig.getInitParameter(INIT_PARAM_AUTHORIZATION_PROVIDER) != null)
return (AuthorizationProvider) Class.forName(servletConfig.getInitParameter(INIT_PARAM_AUTHORIZATION_PROVIDER)).newInstance();
return new AuthenticationRequiredAuthorizer();
}
/**
* Override to configure a different Authentication Provider. The default provider
* authenticates every invocation.
* <p/>
* You can either subclass or supply the "authenticationProvider" init-param to
* change the AuthenticationProvider.
*
* @return the AuthenticationProvider
*/
protected AuthenticationProvider getAuthenticationProvider() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
if (servletConfig.getInitParameter(INIT_PARAM_AUTHENTICATION_PROVIDER) != null)
return (AuthenticationProvider) Class.forName(servletConfig.getInitParameter(INIT_PARAM_AUTHENTICATION_PROVIDER)).newInstance();
return new AuthenticationNotRequiredAuthenticator();
}
/**
* Supply the service to expose via this servlet.
* <p/>
* You can either subclass or supply the "service" init-param to
* configure what service class to instantiate.
*
* @return
*/
protected Object getService() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
return Class.forName(servletConfig.getInitParameter(INIT_PARAM_SERVICE)).newInstance();
}
/**
* The service method performs the actual deserialization of the InvocationRequest and returns
* an InvocationResponse in the body of the ServletResponse.
* <p/>
* Standard Java object serialization/deserialization is used to retrieve and set the invocation
* request/response.
* <p/>
* The configured <code>AuthenticationProvider</code> and <code>AuthorizationProvider</code>
* are consulted.
* <p/>
* A ThreadLocal in the <code>AuthenticationContext</code> holds on to any principal created during
* authentication, so that it is available to both the AuthorizationProvider and any service
* that whishes to get hold of the principal via <code>AuthenticationContext#getPrincipal()</code>.
* <p/>
* You are encouraged to use your existing domain object AllowAllAuthorizerfor authentication :)
*
* @param request The ServletRequest
* @param response the ServletResponse
* @throws ServletException
* @throws IOException
* @see no.tornado.brap.common.InvocationRequest
* @see no.tornado.brap.common.InvocationResponse
*/
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
AuthenticationContext.enter();
InvocationResponse invocationResponse = null;
InvocationRequest invocationRequest = null;
Method method = null;
Object result = null;
try {
invocationResponse = new InvocationResponse();
invocationRequest = (InvocationRequest) new ObjectInputStream(request.getInputStream()).readObject();
serviceWrapper.getAuthenticationProvider().authenticate(invocationRequest);
serviceWrapper.getAuthorizationProvider().authorize(invocationRequest);
Object[] proxiedParameters = serviceWrapper.getModificationManager().applyModificationScheme(invocationRequest.getParameters());
method = getMethod(invocationRequest.getMethodName(), invocationRequest.getParameterTypes());
没有合适的资源?快使用搜索试试~ 我知道了~
基于java的brap(Java远程调用框架 BRAP).zip
共150个文件
svn-base:70个
java:37个
html:16个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 82 浏览量
2023-05-27
10:18:21
上传
评论
收藏 249KB ZIP 举报
温馨提示
基于java的brap(Java远程调用框架 BRAP).zip
资源推荐
资源详情
资源评论
收起资源包目录
基于java的brap(Java远程调用框架 BRAP).zip (150个子文件)
documentation.apt 14KB
index.apt 4KB
getting-brap.apt 2KB
remoting-with-streams.apt 990B
screencasts.apt 445B
source.apt 186B
wc.db 121KB
entries 3B
faq.fml 2KB
format 3B
announce-subscribe.html 3KB
users-subscribe.html 3KB
announce-unsub-confirm.html 856B
users-unsub-confirm.html 856B
users-sub-success.html 793B
announce-sub-success.html 793B
announce-sub-mod-success.html 790B
users-sub-mod-success.html 790B
announce-mod-success.html 780B
users-mod-success.html 780B
users-unsub-success.html 736B
announce-unsub-success.html 736B
announce-sub-dup.html 734B
users-sub-dup.html 734B
announce-sub-confirm.html 726B
users-sub-confirm.html 726B
brap-modification.iml 2KB
ProxyServlet.java 14KB
MethodInvocationHandler.java 8KB
SetterModificationManager.java 4KB
ServiceProxyFactory.java 4KB
SpringProxyServlet.java 3KB
ServiceWrapper.java 2KB
DatabaseUsernamePasswordAuthenticator.java 2KB
HttpClientTransportSession.java 2KB
InvocationRequest.java 2KB
AuthorizationProvider.java 2KB
AuthenticationContext.java 2KB
AuthenticationProvider.java 2KB
UsernamePasswordPrincipal.java 2KB
SingleUsernamePasswordAuthenticator.java 2KB
HttpURLTransportSession.java 2KB
HttpClientConnectionTransportProvider.java 2KB
TransportProvider.java 2KB
InvocationResponse.java 1KB
SetterModificationInterceptor.java 1KB
HelloServiceImpl.java 1KB
SpringClientExample.java 809B
ModificationList.java 603B
AuthenticationRequiredAuthorizer.java 566B
HttpURLConnectionTransportProvider.java 563B
SpringServerExample.java 448B
AuthenticationFailedException.java 438B
AuthenticationNotRequiredAuthorizer.java 410B
AnonymousPrincipal.java 378B
AuthorizationFailedException.java 364B
InputStreamArgumentPlaceholder.java 348B
ChangesIgnoredModificationManager.java 343B
RemotingException.java 324B
AuthenticationNotRequiredAuthenticator.java 313B
TransportSession.java 309B
HelloService.java 243B
ModificationManager.java 241B
MyService.java 74B
LICENSE 11KB
README 3KB
RELEASE_INSTRUCTIONS 930B
d43155e7f87e736e9cef71d94ba0ff45f3812b1f.svn-base 39KB
d6776e1b23f993463c76d6906348067481a57788.svn-base 14KB
1cca29c738cdccac0b039e872aab418b11b3fe15.svn-base 14KB
2b8b815229aa8a61e483fb4ba0588b8b6c491890.svn-base 11KB
54d9ed641c8ea0004e0005e31501c091efb811d8.svn-base 8KB
fcde208c33a12f53cdae3caba4588849b2c32bf9.svn-base 4KB
acf7028aa95f1927475c28fd7fe628b3057a8786.svn-base 4KB
67c058fd45c793881855d28787b3cd278b87a123.svn-base 4KB
262b74a39da4903daf3192ae75e8d0b10ba61b1c.svn-base 4KB
147bde140d65cc2dc26d407e538d031b2e6522f8.svn-base 3KB
dcf4ad0c2a38b66383dec5f656599cff06ba5bda.svn-base 3KB
3e917adae0aea2ffd830e12fade30ae5912ab6b1.svn-base 3KB
825fb1e755e2b6bf7044dc7d99cc638d408f200a.svn-base 3KB
f378263354cf4fd330e549523840dd64d5fef019.svn-base 3KB
4e2beaa252f559ccb735d8f6eafb9b088b3db691.svn-base 2KB
f1be1d6076dae6199dd7cdeb11aaa00919c1c946.svn-base 2KB
5a230a2396afd7f9f418150ddb050173bd6ab1c1.svn-base 2KB
88ef5a52919412568cb0a940b3f52acb8898d687.svn-base 2KB
80020dc9f0442ef8677cfe26ad12b89c08695495.svn-base 2KB
7b755835906c70d664220cd133b2cafbe0ee53ec.svn-base 2KB
09c4aa6a189600c9741c7a68912bcd373f9c59f3.svn-base 2KB
d0d035665b4993aee68356ef58cd335fe4ee1796.svn-base 2KB
aa3548caca9290a4ac8209258f2a7c8abe198672.svn-base 2KB
2fe85eb33be69810086dc6d41138d02ed7de6fb1.svn-base 2KB
b7ca904671e6e4c1b271f8d1f1911a89f91be933.svn-base 2KB
a928205d400ea1e0c94d8001b7fbd05a5c7377c9.svn-base 2KB
fdceace5a2d940b1851d649f208614769428383c.svn-base 2KB
3006d6c0a9e999a65a77c8de8b2e519f727aa0ab.svn-base 2KB
d18948d8d89c234fd612a971f10da91af5b79b26.svn-base 2KB
a54f3e9841c1d520b61e6c216257a9304faee76a.svn-base 2KB
f42ef082bf0c21d648c61f38f33b93e27c43141d.svn-base 2KB
02e8a944bfac9c1080a2115d277f85fa3186de8b.svn-base 2KB
5a47c706faa57c9bc5e4d432d704be141909310b.svn-base 2KB
共 150 条
- 1
- 2
资源评论
易小侠
- 粉丝: 6469
- 资源: 9万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 历史学习网站 JAVA+Vue.js+SpringBoot+MySQL
- µ×ɼµÂ͵ƻºÍÒ¿ÏÍɼÂÎ×Á
- 基于pytorch+OpenCV的手写数字识别源码+使用文档+全部资料(优秀项目).zip
- C++ 一个 回文素数 回文素 数
- C++ 一个 回文素数 回文素 数
- 基于pytorch+OpenCV的手写数字识别源码+使用文档+全部资料(优秀项目).zip
- C++ 一个 回文素数 回文素 数
- 基于ME4056+ME2109芯片移动电源硬件设计PDF原理图+PADS9.3 PCB文件.zip
- 基于Python+OpenCV的印章识别程序源码+使用文档+全部资料(优秀项目).zip
- python 写 一个 回文素数
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功