本文整理汇总了Java中com.vaadin.server.VaadinService.getCurrentRequest方法的典型用法代码示例。如果您正苦于以下问题:Java VaadinService.getCurrentRequest方法的具体用法?Java VaadinService.getCurrentRequest怎么用?Java VaadinService.getCurrentRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vaadin.server.VaadinService
的用法示例。
在下文中一共展示了VaadinService.getCurrentRequest方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserRemoteAddress
import com.vaadin.server.VaadinService; //导入方法依赖的package包/类
@Nullable
protected String getUserRemoteAddress() {
VaadinRequest currentRequest = VaadinService.getCurrentRequest();
String userRemoteAddress = null;
if (currentRequest != null) {
String xForwardedFor = currentRequest.getHeader("X_FORWARDED_FOR");
if (StringUtils.isNotBlank(xForwardedFor)) {
String[] strings = xForwardedFor.split(",");
String userAddressFromHeader = StringUtils.trimToEmpty(strings[strings.length - 1]);
if (StringUtils.isNotEmpty(userAddressFromHeader)) {
userRemoteAddress = userAddressFromHeader;
} else {
userRemoteAddress = currentRequest.getRemoteAddr();
}
} else {
userRemoteAddress = currentRequest.getRemoteAddr();
}
}
return userRemoteAddress;
}
示例2: isUidlRequest
import com.vaadin.server.VaadinService; //导入方法依赖的package包/类
/**
* Test if current request is an UIDL request
* @return true if in UIDL request, false otherwise
*/
private boolean isUidlRequest() {
VaadinRequest request = VaadinService.getCurrentRequest();
if (request == null)
return false;
String pathInfo = request.getPathInfo();
if (pathInfo == null) {
return false;
}
if (pathInfo.startsWith("/" + ApplicationConstants.UIDL_PATH)) {
return true;
}
return false;
}
示例3: checkAuthentication
import com.vaadin.server.VaadinService; //导入方法依赖的package包/类
/**
* Check authentication using {@link Authenticate} annotation on given view class or the {@link UI} class to which
* navigator is bound.
* @param navigationState Navigation state
* @param viewConfiguration View configuration
* @return <code>true</code> if authentication is not required or if it is required and the current
* {@link AuthContext} is authenticated, <code>false</code> otherwise
* @throws ViewNavigationException Missing {@link AuthContext} from context or other unexpected error
*/
protected boolean checkAuthentication(final String navigationState, final ViewConfiguration viewConfiguration)
throws ViewNavigationException {
if (!suspendAuthenticationCheck) {
Authenticate authc = (viewConfiguration != null)
? viewConfiguration.getAuthentication().orElse(uiAuthenticate) : uiAuthenticate;
if (authc != null) {
// check auth context
final AuthContext authContext = AuthContext.getCurrent().orElseThrow(() -> new ViewNavigationException(
navigationState,
"No AuthContext available as Context resource: failed to process Authenticate annotation on View or UI"));
if (!authContext.getAuthentication().isPresent()) {
// not authenticated, try to authenticate from request
final VaadinRequest request = VaadinService.getCurrentRequest();
if (request != null) {
try {
authContext.authenticate(VaadinHttpRequest.create(request));
// authentication succeded
return true;
} catch (@SuppressWarnings("unused") AuthenticationException e) {
// failed, ignore
}
}
onAuthenticationFailed(authc, navigationState);
return false;
}
}
}
return true;
}
示例4: ensureInited
import com.vaadin.server.VaadinService; //导入方法依赖的package包/类
/**
* Ensure that a {@link DeviceInfo} is available from given Vaadin <code>session</code>. For successful
* initialization, a {@link VaadinService#getCurrentRequest()} must be available.
* @param session Vaadin session (not null)
*/
static void ensureInited(VaadinSession session) {
ObjectUtils.argumentNotNull(session, "VaadinSession must be not null");
synchronized (session) {
if (session.getAttribute(SESSION_ATTRIBUTE_NAME) == null && VaadinService.getCurrentRequest() != null) {
session.setAttribute(SESSION_ATTRIBUTE_NAME, create(VaadinService.getCurrentRequest()));
}
}
}
示例5: getRememberMeCookie
import com.vaadin.server.VaadinService; //导入方法依赖的package包/类
private Cookie getRememberMeCookie()
{
final VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
if(vaadinRequest == null)
{
logger.warn("Could not get the VaadinRequest. It might be that we are called from a websocket connection.");
return null;
}
//
// Get the remember me cookie
final Cookie[] cookies = vaadinRequest.getCookies();
if (cookies == null)
{
return null;
}
for (final Cookie cookie : cookies)
{
if (COOKIENAME_RememberMe.equals(cookie.getName()))
{
return cookie;
}
}
return null;
}
示例6: getWebBrowserDetails
import com.vaadin.server.VaadinService; //导入方法依赖的package包/类
protected WebBrowser getWebBrowserDetails() {
// timezone info is passed only on VaadinSession creation
WebBrowser webBrowser = VaadinSession.getCurrent().getBrowser();
VaadinRequest currentRequest = VaadinService.getCurrentRequest();
// update web browser instance if current request is not null
// it can be null in case of background/async processing of login request
if (currentRequest != null) {
webBrowser.updateRequestDetails(currentRequest);
}
return webBrowser;
}
示例7: onAppStarted
import com.vaadin.server.VaadinService; //导入方法依赖的package包/类
@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 10)
@EventListener
protected void onAppStarted(AppStartedEvent event) throws LoginException {
Connection connection = event.getApp().getConnection();
// can be already authenticated by another event listener
if (webIdpConfig.getIdpEnabled()
&& !connection.isAuthenticated()) {
VaadinRequest currentRequest = VaadinService.getCurrentRequest();
if (currentRequest != null) {
Principal principal = currentRequest.getUserPrincipal();
if (principal instanceof IdpSessionPrincipal) {
IdpSession idpSession = ((IdpSessionPrincipal) principal).getIdpSession();
Locale locale = event.getApp().getLocale();
ExternalUserCredentials credentials = new ExternalUserCredentials(principal.getName(), locale);
credentials.setSessionAttributes(
ImmutableMap.of(
IdpService.IDP_USER_SESSION_ATTRIBUTE,
idpSession.getId()
));
connection.login(credentials);
}
}
}
}
示例8: getUrls
import com.vaadin.server.VaadinService; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
@Nullable
public List<String> getUrls(String selectorId) {
VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
if (vaadinRequest != null)
return (List) vaadinRequest.getWrappedSession().getAttribute(getAttributeName(selectorId));
else {
HttpSession httpSession = getHttpSession();
return httpSession != null ? (List<String>) httpSession.getAttribute(getAttributeName(selectorId)) : null;
}
}
示例9: setUrls
import com.vaadin.server.VaadinService; //导入方法依赖的package包/类
@Override
public void setUrls(String selectorId, List<String> urls) {
VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
if (vaadinRequest != null)
vaadinRequest.getWrappedSession().setAttribute(getAttributeName(selectorId), urls);
else {
HttpSession httpSession = getHttpSession();
if (httpSession != null) {
httpSession.setAttribute(getAttributeName(selectorId), urls);
}
}
}
示例10: userSessionLoggedIn
import com.vaadin.server.VaadinService; //导入方法依赖的package包/类
@Override
public void userSessionLoggedIn(UserSession session) {
VaadinRequest currentRequest = VaadinService.getCurrentRequest();
if (currentRequest != null) {
Principal principal = currentRequest.getUserPrincipal();
if (principal instanceof IdpSessionPrincipal) {
IdpSession idpSession = ((IdpSessionPrincipal) principal).getIdpSession();
session.setAttribute(IdpService.IDP_USER_SESSION_ATTRIBUTE, idpSession.getId());
}
}
}
示例11: getCurrentRequest
import com.vaadin.server.VaadinService; //导入方法依赖的package包/类
private static VaadinRequest getCurrentRequest() {
VaadinRequest request = VaadinService.getCurrentRequest();
if (request == null) {
throw new IllegalStateException(
"No request bound to current thread");
}
return request;
}
示例12: getCurrentRequest
import com.vaadin.server.VaadinService; //导入方法依赖的package包/类
private static VaadinRequest getCurrentRequest() {
VaadinRequest request = VaadinService.getCurrentRequest();
if (request == null) {
throw new IllegalStateException("No request bound to current thread");
}
return request;
}