当前位置: 首页>>代码示例>>Java>>正文


Java ContainerRequest.setSecurityContext方法代码示例

本文整理汇总了Java中com.sun.jersey.spi.container.ContainerRequest.setSecurityContext方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerRequest.setSecurityContext方法的具体用法?Java ContainerRequest.setSecurityContext怎么用?Java ContainerRequest.setSecurityContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.jersey.spi.container.ContainerRequest的用法示例。


在下文中一共展示了ContainerRequest.setSecurityContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
	// Get session id from request header
	final String sessionId = request.getHeaderValue("session-id");

	SessionUser user = null;
	Session session = null;

	if (sessionId != null && sessionId.length() > 0) {
		// Load session object from repository
		// session = sessionRepository.findOne(sessionId);

		// Load associated user from session
		// if (session != null) {
		// // user = userRepository.findOne(session.getUserId());
		// }
	}

	request.setSecurityContext(new ElabSecurityContext(session, user));
	return request;
}
 
开发者ID:HuygensING,项目名称:elaborate4-backend,代码行数:22,代码来源:SecurityContextFilterFactory.java

示例2: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
	
	// No authentication needed for GET requests.
	if(request.getMethod().equalsIgnoreCase("GET")) {
		return request;
	}
	
	final User user = authenticate(request);
	SecurityContext ctxt = new SecurityContext() {
		@Override
		public boolean isUserInRole(String arg0) {
			return true;
		}
		@Override
		public boolean isSecure() {
			return false;
		}
		@Override
		public Principal getUserPrincipal() {
			return new Principal() {
				
				@Override
				public String getName() {
					return user.getUsername();
				}
			};
		}
		@Override
		public String getAuthenticationScheme() {
			return SecurityContext.BASIC_AUTH;
		}
	};
	request.setSecurityContext(ctxt);
	return request;
}
 
开发者ID:yeastrc,项目名称:msdapl,代码行数:37,代码来源:AuthenticationFilter.java

示例3: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
	// OPTIONS calls don't need authorization, apparently
	if ("OPTIONS".equals(request.getMethod())) {
		return request;
	}

	// Authentication via header or cookie
	String authentication = request.getHeaderValue(HEADER);
	if (StringUtils.isBlank(authentication)) {
		Cookie cookie = request.getCookies().get(HEADER);
		if (cookie != null) {
			authentication = cookie.getValue();
		}
	}
	// Log.info("authentication={}", authentication);
	if (StringUtils.isNotBlank(authentication)) {
		List<String> parts = Lists.newArrayList(Splitter.on(" ").split(authentication));
		if (parts.size() == 2) {
			String scheme = parts.get(0);
			String key = parts.get(1);
			try {
				SecurityContext securityContext = sessionService.getSecurityContext(scheme, key);
				if (securityContext != null) {
					request.setSecurityContext(securityContext);
					return request;
				}
			} catch (nl.knaw.huygens.security.client.UnauthorizedException e) {
				throw new UnauthorizedException(e.getMessage());
			}
		}
	} else {

	}
	throw new UnauthorizedException("No valid " + HEADER + " header in request");
}
 
开发者ID:HuygensING,项目名称:elaborate4-backend,代码行数:37,代码来源:AuthenticationResourceFilter.java

示例4: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
    String username = request.getHeaderValue(AuthConstants.USERNAME_HEADER);
    String token = request.getHeaderValue(AuthConstants.TOKEN_HEADER);
    String auth = request.getHeaderValue(HttpHeaders.AUTHORIZATION);

    if (username == null) {
        if (auth != null) {
            if (!auth.startsWith("Basic ")) {
                throw new WebApplicationException(Status.BAD_REQUEST);
            }
            String decoded = new String(Base64.decode(auth
                    .replaceFirst("Basic ", "")));
            int sep = decoded.indexOf(':');
            if (sep >= 0) {
                username = decoded.substring(0, sep);
                token = decoded.substring(sep + 1);
            } else {
                throw new WebApplicationException(Status.BAD_REQUEST);
            }
        }
    }
    if (username != null) {
        if (username.isEmpty() || token == null || token.isEmpty()) {
            throw new WebApplicationException(Status.BAD_REQUEST);
        }
        try {
            User user = service.getUser(username);
            if (passwordEncoder.verify(token, user.getToken())) {
                request.setSecurityContext(
                        new SecurityContextImpl(user, request.isSecure()));
            } else {
                throw new WebApplicationException(Status.FORBIDDEN);
            }
        } catch (UserNotFoundException ex) {
            throw new WebApplicationException(ex, Status.FORBIDDEN);
        }
    }
    return request;
}
 
开发者ID:enviroCar,项目名称:enviroCar-server,代码行数:41,代码来源:AuthenticationFilter.java

示例5: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
    User user = authenticate(request);
    request.setSecurityContext(new HttpBasicAuthContext(user));
    return request;
}
 
开发者ID:anotheria,项目名称:moskito-central,代码行数:7,代码来源:RESTConnectorHttpBasicAuthTest.java


注:本文中的com.sun.jersey.spi.container.ContainerRequest.setSecurityContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。