本文整理汇总了Java中org.jboss.resteasy.core.ResourceMethodInvoker.getMethod方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceMethodInvoker.getMethod方法的具体用法?Java ResourceMethodInvoker.getMethod怎么用?Java ResourceMethodInvoker.getMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.resteasy.core.ResourceMethodInvoker
的用法示例。
在下文中一共展示了ResourceMethodInvoker.getMethod方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filter
import org.jboss.resteasy.core.ResourceMethodInvoker; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
final ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) requestContext.getProperty("org.jboss.resteasy.core.ResourceMethodInvoker");
final Method method = methodInvoker.getMethod();
// Verifies if it isn't annotated with @PermitAll
if (!method.isAnnotationPresent(PermitAll.class)) {
if (method.isAnnotationPresent(DenyAll.class)) {
LOGGER.info("Access denied!");
requestContext.abortWith(Response.status(Status.FORBIDDEN).entity(new User()).build());
}
}
}
示例2: filter
import org.jboss.resteasy.core.ResourceMethodInvoker; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext ctx) throws IOException {
if (!(ctx instanceof PostMatchContainerRequestContext)) {
return;
}
PostMatchContainerRequestContext context = (PostMatchContainerRequestContext) ctx;
ResourceMethodInvoker resourceMethod = context.getResourceMethod();
Method method = resourceMethod.getMethod();
Class<?> resource = method.getDeclaringClass();
checkRequireAuthentication(ctx, method, resource);
}
示例3: filter
import org.jboss.resteasy.core.ResourceMethodInvoker; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext arg0,
ContainerResponseContext responseContext) throws IOException {
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
headers.putSingle("Access-Control-Allow-Origin", "*");
/* headers.putSingle("Access-Control-Allow-Methods", "HEAD, DELETE,GET,OPTIONS,POST,PUT");
headers.putSingle("Access-Control-Allow-Headers", "Accept, Content-Type, Authorization, Content-Length, X-Requested-With");*/
headers.putSingle("Access-Control-Allow-Credentials", true);
final ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker)arg0.getProperty("org.jboss.resteasy.core.ResourceMethodInvoker");
if ( methodInvoker != null) {
final Method method = methodInvoker.getMethod();
if (!method.isAnnotationPresent(AuthenticationNotRequired.class) &&
!method.isAnnotationPresent(NdexOpenFunction.class) &&
!BasicAuthenticationFilter.setAuthHeaderIsFalse(arg0)) {
headers.putSingle("WWW-Authenticate", "Basic");
}
int responseCode = responseContext.getStatus();
String error = MDC.get("error");
logger.info("[end]\t["+ method.getName() + "]\t[status: " + responseCode + "]" +
(error !=null? "\t[error: "+ error + "]" : "" ));
if ( error !=null)
MDC.remove("error");
}
}
示例4: filter
import org.jboss.resteasy.core.ResourceMethodInvoker; //导入方法依赖的package包/类
public void filter(ContainerRequestContext requestContext) throws IOException {
ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker)
requestContext.getProperty("org.jboss.resteasy.core.ResourceMethodInvoker");
Method method = methodInvoker.getMethod();
//Access allowed for all
if( ! method.isAnnotationPresent(PermitAll.class))
{
//Access denied for all
if(method.isAnnotationPresent(DenyAll.class))
{
requestContext.abortWith(ACCESS_FORBIDDEN);
return;
}
//Get request headers
final MultivaluedMap<String, String> headers = requestContext.getHeaders();
//Fetch authorization header
final List<String> authorization = headers.get(AUTHORIZATION_PROPERTY);
//If no authorization information present; block access
if(authorization == null || authorization.isEmpty())
{
requestContext.abortWith(ACCESS_DENIED);
return;
}
Subject subject = securityService.getSubject();
if (!subject.isAuthenticated()) {
requestContext.abortWith(SERVER_ERROR);
return;
}
//Verify user access
if(method.isAnnotationPresent(RolesAllowed.class))
{
boolean isAllowed = false;
RolesAllowed rolesAnnotation = method.getAnnotation(RolesAllowed.class);
Set<String> rolesSet = new HashSet<String>(Arrays.asList(rolesAnnotation.value()));
//Is user allowed?
for(String s : rolesSet)
if(subject.hasRole(s))
{
isAllowed = true;
}
if(!isAllowed)
{
requestContext.abortWith(ACCESS_DENIED);
}
}
}
}
示例5: filter
import org.jboss.resteasy.core.ResourceMethodInvoker; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) requestContext.getProperty("org.jboss.resteasy.core.ResourceMethodInvoker");
Method method = methodInvoker.getMethod();
//Access allowed for all
if( ! method.isAnnotationPresent(PermitAll.class))
{
//Access denied for all
if(method.isAnnotationPresent(DenyAll.class))
{
requestContext.abortWith(ACCESS_FORBIDDEN);
return;
}
//Get request headers
final MultivaluedMap<String, String> headers = requestContext.getHeaders();
//Fetch authorization header
final List<String> authorization = headers.get(AUTHORIZATION_PROPERTY);
//If no authorization information present; block access
if(authorization == null || authorization.isEmpty())
{
requestContext.abortWith(ACCESS_DENIED);
return;
}
//Get user token
final String userToken = authorization.get(0);
DefaultUserService userService = DefaultUserService.getInstance();
User user = userService.getUser(userToken);
if(user == null) {
requestContext.abortWith(ACCESS_DENIED);
return;
}
//Verifying Username and password
System.out.println(user.getUserName());
System.out.println(user.getPassword());
//Verify user access
if(method.isAnnotationPresent(RolesAllowed.class))
{
RolesAllowed rolesAnnotation = method.getAnnotation(RolesAllowed.class);
Set<String> rolesSet = new HashSet<String>(Arrays.asList(rolesAnnotation.value()));
//Is user valid?
if(!rolesSet.contains(user.getRole().name()))
{
requestContext.abortWith(ACCESS_DENIED);
return;
}
}
}
}
示例6: filter
import org.jboss.resteasy.core.ResourceMethodInvoker; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) {
ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) requestContext
.getProperty("org.jboss.resteasy.core.ResourceMethodInvoker");
Method method = methodInvoker.getMethod();
// Access allowed for all
if (!method.isAnnotationPresent(PermitAll.class)) {
// Access denied for all
if (method.isAnnotationPresent(DenyAll.class)) {
requestContext.abortWith(ACCESS_FORBIDDEN);
return;
}
// Get request headers
final MultivaluedMap<String, String> headersMap = requestContext.getHeaders();
// Fetch authorization header
final List<String> authorization = headersMap.get(AUTHORIZATION_PROPERTY);
// If no authorization information present; block access
if (authorization == null || authorization.isEmpty()) {
requestContext.abortWith(ACCESS_DENIED);
return;
}
// Get encoded username and password
final String encodedUserPassword = authorization.get(0).replaceFirst(AUTHENTICATION_SCHEME + " ", "");
// Decode username and password
String usernameAndPassword = new String(Base64.decodeBase64(encodedUserPassword));
// Split username and password tokens
final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
final String username = tokenizer.nextToken();
final String password = tokenizer.nextToken();
// Verify user access
if (method.isAnnotationPresent(RolesAllowed.class)) {
RolesAllowed rolesAnnotation = method.getAnnotation(RolesAllowed.class);
Set<String> rolesSet = new HashSet<String>(Arrays.asList(rolesAnnotation.value()));
// Is user valid?
if (!isUserAllowed(username, password, rolesSet)) {
requestContext.abortWith(ACCESS_DENIED);
return;
}
}
}
}
示例7: filter
import org.jboss.resteasy.core.ResourceMethodInvoker; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) {
ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) requestContext
.getProperty(RESOURCE_METHOD_INVOKER);
Method method = methodInvoker.getMethod();
// Access allowed for all
if (!method.isAnnotationPresent(PermitAll.class)) {
// Access denied for all
if (method.isAnnotationPresent(DenyAll.class)) {
requestContext.abortWith(ACCESS_FORBIDDEN);
return;
}
// Get request headers
final MultivaluedMap<String, String> headersMap = requestContext.getHeaders();
// Fetch authorization header
final List<String> authorizationList = headersMap.get(AUTHORIZATION_PROPERTY);
// If no authorization information present; block access
if (authorizationList == null || authorizationList.isEmpty()) {
requestContext.abortWith(ACCESS_DENIED);
return;
}
// Get encoded username and password
final String encodedUserPassword = authorizationList.get(0).replaceFirst(AUTHENTICATION_SCHEME + " ", "");
// Decode username and password
String usernameAndPassword = new String(Base64.decodeBase64(encodedUserPassword));
// Split username and password tokens
final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
final String userName = tokenizer.nextToken();
final String password = tokenizer.nextToken();
// Verify user access
if (method.isAnnotationPresent(RolesAllowed.class)) {
RolesAllowed rolesAnnotation = method.getAnnotation(RolesAllowed.class);
Set<String> rolesSet = new HashSet<String>(Arrays.asList(rolesAnnotation.value()));
// Is user valid?
if (!isUserAllowed(userName, password, rolesSet)) {
requestContext.abortWith(ACCESS_DENIED);
return;
}
}
}
}
示例8: filter
import org.jboss.resteasy.core.ResourceMethodInvoker; //导入方法依赖的package包/类
public void filter(ContainerRequestContext requestContext) throws IOException {
if(requestContext.getMethod().equalsIgnoreCase("OPTIONS")) {
//Preflight in here?
return;
}
SecurityContext securityContext = requestContext.getSecurityContext();
if(securityContext.getUserPrincipal() == null) {
//Not logged in. Auth restriction should be done via web.xml, if no userPrincipal is set it uses anonymous login
return;
}
ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) requestContext.getProperty("org.jboss.resteasy.core.ResourceMethodInvoker");
if(methodInvoker == null) {
log.error("Unable to fetch method from ResourceMethodInvoker");
requestContext.abortWith(SERVER_ERROR);
}
Method method = methodInvoker.getMethod();
if(method.isAnnotationPresent(DenyAll.class)) {
//Functionality has been disallowed.
requestContext.abortWith(ACCESS_FORBIDDEN);
return;
}
if(method.isAnnotationPresent(PermitAll.class)) {
//No authorization required.
return;
}
if(method.isAnnotationPresent(RolesAllowed.class)) {
RolesAllowed rolesAnnotation = method.getAnnotation(RolesAllowed.class);
Set<String> rolesSet = new HashSet<String>(Arrays.asList(rolesAnnotation.value()));
// System.out.println("Checking authentication for user ["+securityContext.getUserPrincipal().getName()+"] method ["+method.getAnnotation(javax.ws.rs.Path.class).value()+"] roles " + rolesSet.toString());
//Verifying username and password
if(!doAuth(securityContext, rolesSet)) {
requestContext.abortWith(ACCESS_FORBIDDEN);
return;
}
}
//Don't do anything if RolesAllowed annotation is not set
}