當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。