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


Java RequestContextHolder.getRequestContext方法代码示例

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


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

示例1: doAuthentication

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
    try {
        final RadiusTokenCredential radiusCredential = (RadiusTokenCredential) credential;
        final String password = radiusCredential.getToken();

        final RequestContext context = RequestContextHolder.getRequestContext();
        final String username = WebUtils.getAuthentication(context).getPrincipal().getId();

        final Pair<Boolean, Optional<Map<String, Object>>> result =
                RadiusUtils.authenticate(username, password, this.servers,
                        this.failoverOnAuthenticationFailure, this.failoverOnException);
        if (result.getKey()) {
            return createHandlerResult(credential,
                    this.principalFactory.createPrincipal(username, result.getValue().get()),
                    new ArrayList<>());
        }
        throw new FailedLoginException("Radius authentication failed for user " + username);
    } catch (final Exception e) {
        throw new FailedLoginException("Radius authentication failed " + e.getMessage());
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:23,代码来源:RadiusTokenAuthenticationHandler.java

示例2: doAuthentication

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
    try {
        final AzureAuthenticatorTokenCredential c = (AzureAuthenticatorTokenCredential) credential;
        final RequestContext context = RequestContextHolder.getRequestContext();
        final Principal principal = WebUtils.getAuthentication(context).getPrincipal();

        LOGGER.debug("Received principal id [{}]", principal.getId());
        final PFAuthParams params = authenticationRequestBuilder.build(principal, c);
        final PFAuthResult r = azureAuthenticatorInstance.authenticate(params);

        if (r.getAuthenticated()) {
            return createHandlerResult(c, principalFactory.createPrincipal(principal.getId()), null);
        }
        LOGGER.error("Authentication failed. Call status: [{}]-[{}]. Error: [{}]", r.getCallStatus(),
                r.getCallStatusString(), r.getMessageError());

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    throw new FailedLoginException("Failed to authenticate user");
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:23,代码来源:AzureAuthenticatorAuthenticationHandler.java

示例3: doExecute

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    final RequestContext context = RequestContextHolder.getRequestContext();
    final String uid = WebUtils.getAuthentication(context).getPrincipal().getId();

    final String secretKey = repository.getSecret(uid);
    if (StringUtils.isBlank(secretKey)) {
        final OneTimeTokenAccount keyAccount = this.repository.create(uid);
        final String keyUri = "otpauth://totp/" + this.label + ':' + uid + "?secret=" + keyAccount.getSecretKey() + "&issuer=" + this.issuer;
        requestContext.getFlowScope().put("key", keyAccount);
        requestContext.getFlowScope().put("keyUri", keyUri);
        LOGGER.debug("Registration key URI is [{}]", keyUri);
        return new EventFactorySupport().event(this, "register");
    }
    return success();
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:OneTimeTokenAccountCheckRegistrationAction.java

示例4: doAuthentication

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
    final AuthyTokenCredential tokenCredential = (AuthyTokenCredential) credential;
    final RequestContext context = RequestContextHolder.getRequestContext();
    final Principal principal = WebUtils.getAuthentication(context).getPrincipal();

    final User user = instance.getOrCreateUser(principal);
    if (!user.isOk()) {
        throw new FailedLoginException(AuthyClientInstance.getErrorMessage(user.getError()));
    }

    final Map<String, String> options = new HashMap<>(1);
    options.put("force", this.forceVerification.toString());

    final Token verification = this.instance.getAuthyTokens().verify(user.getId(), tokenCredential.getToken(), options);

    if (!verification.isOk()) {
        throw new FailedLoginException(AuthyClientInstance.getErrorMessage(verification.getError()));
    }

    return createHandlerResult(tokenCredential, principal, new ArrayList<>());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:23,代码来源:AuthyAuthenticationHandler.java

示例5: findBean

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T findBean(String beanName) {
    FacesContext context = FacesContext.getCurrentInstance();
    if (context != null) {
        try {
            return (T) context.getApplication().evaluateExpressionGet(context, "#{" + beanName + "}", Object.class);
           } catch (ELException e) {}
    }
    final RequestContext rc = RequestContextHolder.getRequestContext();
    T r;
       r = (T) rc.getFlowScope().get(beanName);
       if (r == null)
           r = (T) rc.getRequestScope().get(beanName);
       if (r == null)
           r = (T) rc.getViewScope().get(beanName);
       return r;
}
 
开发者ID:suewonjp,项目名称:civilizer,代码行数:18,代码来源:ViewUtil.java

示例6: doExecute

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext,
        @Nonnull final ProfileInterceptorContext interceptorContext) {

    final RequestContext requestContext =
            RequestContextHolder.getRequestContext();

    final MutableAttributeMap<Object> flowScope =
            requestContext.getFlowScope();

    // full name?
    flowScope.put("userName",
            IdPHelper.getPrincipalName(profileRequestContext));

    log.debug("{} Decorated user name", getLogPrefix());
}
 
开发者ID:cmu-cylab-privacylens,项目名称:PrivacyLens,代码行数:17,代码来源:DecorateUserName.java

示例7: doExecute

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext,
        @Nonnull final ProfileInterceptorContext interceptorContext) {

    final RequestContext requestContext =
            RequestContextHolder.getRequestContext();

    final MutableAttributeMap<Object> flowScope =
            requestContext.getFlowScope();

    final String relyingPartyId =
            IdPHelper.getRelyingPartyId(profileRequestContext);
    flowScope.put("service",
            Oracle.getInstance().getServiceName(relyingPartyId));
    flowScope.put("idpOrganization", General.getInstance().getOrganizationName());

    log.debug("{} Decorated other data", getLogPrefix());
}
 
开发者ID:cmu-cylab-privacylens,项目名称:PrivacyLens,代码行数:19,代码来源:DecorateOther.java

示例8: doExecute

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext,
        @Nonnull final ProfileInterceptorContext interceptorContext) {

    final RequestContext requestContext =
            RequestContextHolder.getRequestContext();

    final MutableAttributeMap<Object> flowScope =
            requestContext.getFlowScope();
    flowScope.put("adminUrl", General.getInstance().getAdminUrl());
    flowScope.put("adminMail", General.getInstance().getAdminMail());
    flowScope.put("IdPName", General.getInstance().getIdpName());
    flowScope.put("credits", General.getInstance().getCredits());

    log.debug("{} Decorated general data", getLogPrefix());
}
 
开发者ID:cmu-cylab-privacylens,项目名称:PrivacyLens,代码行数:17,代码来源:DecorateGeneral.java

示例9: doExecute

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected void doExecute(
        @Nonnull final ProfileRequestContext profileRequestContext,
        @Nonnull final ProfileInterceptorContext interceptorContext) {

    final RequestContext requestContext =
            RequestContextHolder.getRequestContext();

    final MutableAttributeMap<Object> flowScope =
            requestContext.getFlowScope();

    final HttpServletRequest request =
            (HttpServletRequest) requestContext.getExternalContext()
                    .getNativeRequest();

    // CHANGEME use previous consents
    final List<Attribute> attributes =
            (List<Attribute>) flowScope.get("attributes");

    final String attributeList = getReminderAttributes(attributes);

    flowScope.put("attributeList", attributeList);

    log.debug("{} added reminder list", getLogPrefix());
}
 
开发者ID:cmu-cylab-privacylens,项目名称:PrivacyLens,代码行数:27,代码来源:ReminderAttributeService.java

示例10: populateAttributes

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
@Override
public void populateAttributes(final AuthenticationBuilder authenticationBuilder, final Credential credential) {
    final RequestContext context = RequestContextHolder.getRequestContext();
    if (context != null) {
        final Service svc = WebUtils.getService(context);

        if (svc instanceof MultiFactorAuthenticationSupportingWebApplicationService) {
            final MultiFactorAuthenticationSupportingWebApplicationService mfaSvc =
                    (MultiFactorAuthenticationSupportingWebApplicationService) svc;

            authenticationBuilder.addAttribute(
                    MultiFactorAuthenticationSupportingWebApplicationService.CONST_PARAM_AUTHN_METHOD,
                    mfaSvc.getAuthenticationMethod());

            logger.debug("Captured authentication method [{}] into the authentication context",
                    mfaSvc.getAuthenticationMethod());
        }
    }
}
 
开发者ID:Unicon,项目名称:cas-mfa,代码行数:20,代码来源:RememberAuthenticationMethodMetaDataPopulator.java

示例11: resolveThemeName

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
@Override
public String resolveThemeName(final HttpServletRequest request) {
    if (this.servicesManager == null) {
        return getDefaultThemeName();
    }
    // retrieve the user agent string from the request
    final String userAgent = request.getHeader("User-Agent");

    if (StringUtils.isBlank(userAgent)) {
        return getDefaultThemeName();
    }

    for (final Map.Entry<Pattern, String> entry : this.overrides.entrySet()) {
        if (entry.getKey().matcher(userAgent).matches()) {
            request.setAttribute("isMobile", "true");
            request.setAttribute("browserType", entry.getValue());
            break;
        }
    }

    final RequestContext context = RequestContextHolder.getRequestContext();
    final Service service = WebUtils.getService(context);
    if (service != null) {
        final RegisteredService rService = this.servicesManager.findServiceBy(service);
        if (rService != null && rService.getAccessStrategy().isServiceAccessAllowed()
                && StringUtils.isNotBlank(rService.getTheme())) {
            LOGGER.debug("Service [{}] is configured to use a custom theme [{}]", rService, rService.getTheme());
            final CasThemeResourceBundleMessageSource messageSource = new CasThemeResourceBundleMessageSource();
            messageSource.setBasename(rService.getTheme());
            if (messageSource.doGetBundle(rService.getTheme(), request.getLocale()) != null) {
                LOGGER.debug("Found custom theme [{}] for service [{}]", rService.getTheme(), rService);
                return rService.getTheme();
            } else {
                LOGGER.warn("Custom theme {} for service {} cannot be located. Falling back to default theme...",
                        rService.getTheme(), rService);
            }
        }
    }
    return getDefaultThemeName();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:41,代码来源:ServiceThemeResolver.java

示例12: buildView

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
/**
 * Uses the viewName and the theme associated with the service.
 * being requested and returns the appropriate view.
 * @param viewName the name of the view to be resolved
 * @return a theme-based UrlBasedView
 * @throws Exception an exception
 */
@Override
protected AbstractUrlBasedView buildView(final String viewName) throws Exception {
    final RequestContext requestContext = RequestContextHolder.getRequestContext();
    final WebApplicationService service = WebUtils.getService(requestContext);
    final RegisteredService registeredService = this.servicesManager.findServiceBy(service);

    final String themeId = service != null && registeredService != null
            && registeredService.getAccessStrategy().isServiceAccessAllowed()
            && StringUtils.hasText(registeredService.getTheme()) ? registeredService.getTheme() : defaultThemeId;

    final String themePrefix = String.format("%s/%s/ui/", pathPrefix, themeId);
    LOGGER.debug("Prefix {} set for service {} with theme {}", themePrefix, service, themeId);

    //Build up the view like the base classes do, but we need to forcefully set the prefix for each request.
    //From UrlBasedViewResolver.buildView
    final InternalResourceView view = (InternalResourceView) BeanUtils.instantiateClass(getViewClass());
    view.setUrl(themePrefix + viewName + getSuffix());
    final String contentType = getContentType();
    if (contentType != null) {
        view.setContentType(contentType);
    }
    view.setRequestContextAttribute(getRequestContextAttribute());
    view.setAttributesMap(getAttributesMap());

    //From InternalResourceViewResolver.buildView
    view.setAlwaysInclude(false);
    view.setExposeContextBeansAsAttributes(false);
    view.setPreventDispatchLoop(true);

    LOGGER.debug("View resolved: {}", view.getUrl());

    return view;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:41,代码来源:RegisteredServiceThemeBasedViewResolver.java

示例13: doAuthentication

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
    final GoogleAuthenticatorTokenCredential tokenCredential = (GoogleAuthenticatorTokenCredential) credential;

    if (!NumberUtils.isCreatable(tokenCredential.getToken())) {
        throw new PreventedException("Invalid non-numeric OTP format specified.",
                new IllegalArgumentException("Invalid token " + tokenCredential.getToken()));
    }
    final int otp = Integer.parseInt(tokenCredential.getToken());
    LOGGER.debug("Received OTP [{}]", otp);

    final RequestContext context = RequestContextHolder.getRequestContext();
    if (context == null) {
        new IllegalArgumentException("No request context could be found to locate an authentication event");
    }
    final Authentication authentication = WebUtils.getAuthentication(context);
    if (authentication == null) {
        new IllegalArgumentException("Request context has no reference to an authentication event to locate a principal");
    }
    final String uid = authentication.getPrincipal().getId();

    LOGGER.debug("Received principal id [{}]", uid);
    final String secKey = this.credentialRepository.getSecret(uid);
    if (StringUtils.isBlank(secKey)) {
        throw new AccountNotFoundException(uid + " cannot be found in the registry");
    }

    if (this.tokenRepository.exists(uid, otp)) {
        throw new AccountExpiredException(uid + " cannot reuse OTP " + otp + " as it may be expired/invalid");
    }

    final boolean isCodeValid = this.googleAuthenticatorInstance.authorize(secKey, otp);
    if (isCodeValid) {
        this.tokenRepository.store(new GoogleAuthenticatorToken(otp, uid));
        return createHandlerResult(tokenCredential, this.principalFactory.createPrincipal(uid), null);
    }
    throw new FailedLoginException("Failed to authenticate code " + otp);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:39,代码来源:GoogleAuthenticatorAuthenticationHandler.java

示例14: doAuthentication

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
    final YubiKeyCredential yubiKeyCredential = (YubiKeyCredential) credential;

    final String otp = yubiKeyCredential.getToken();

    if (!YubicoClient.isValidOTPFormat(otp)) {
        LOGGER.debug("Invalid OTP format [{}]", otp);
        throw new AccountNotFoundException("OTP format is invalid");
    }

    final RequestContext context = RequestContextHolder.getRequestContext();
    final String uid = WebUtils.getAuthentication(context).getPrincipal().getId();
    final String publicId = YubicoClient.getPublicId(otp);
    if (this.registry != null
            && !this.registry.isYubiKeyRegisteredFor(uid, publicId)) {
        LOGGER.debug("YubiKey public id [{}] is not registered for user [{}]", publicId, uid);
        throw new AccountNotFoundException("YubiKey id is not recognized in registry");
    }

    try {
        final VerificationResponse response = this.client.verify(otp);
        final ResponseStatus status = response.getStatus();
        if (status.compareTo(ResponseStatus.OK) == 0) {
            LOGGER.debug("YubiKey response status [{}] at [{}]", status, response.getTimestamp());
            return createHandlerResult(yubiKeyCredential, this.principalFactory.createPrincipal(uid), null);
        }
        throw new FailedLoginException("Authentication failed with status: " + status);
    } catch (final YubicoVerificationException | YubicoValidationFailure e) {
        LOGGER.error(e.getMessage(), e);
        throw new FailedLoginException("YubiKey validation failed: " + e.getMessage());
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:34,代码来源:YubiKeyAuthenticationHandler.java

示例15: resolveThemeName

import org.springframework.webflow.execution.RequestContextHolder; //导入方法依赖的package包/类
@Override
public String resolveThemeName(final HttpServletRequest request) {
    if (this.servicesManager == null) {
        return getDefaultThemeName();
    }
    // retrieve the user agent string from the request
    final String userAgent = WebUtils.getHttpServletRequestUserAgent(request);

    if (StringUtils.isBlank(userAgent)) {
        return getDefaultThemeName();
    }

    overrides.entrySet().stream()
            .filter(entry -> entry.getKey().matcher(userAgent).matches())
            .findFirst()
            .ifPresent(entry -> {
                request.setAttribute("isMobile", "true");
                request.setAttribute("browserType", entry.getValue());
            });

    final RequestContext context = RequestContextHolder.getRequestContext();
    final Service service = WebUtils.getService(context);
    if (service != null) {
        final RegisteredService rService = this.servicesManager.findServiceBy(service);
        if (rService != null && rService.getAccessStrategy().isServiceAccessAllowed()
                && StringUtils.isNotBlank(rService.getTheme())) {
            LOGGER.debug("Service [{}] is configured to use a custom theme [{}]", rService, rService.getTheme());
            final CasThemeResourceBundleMessageSource messageSource = new CasThemeResourceBundleMessageSource();
            messageSource.setBasename(rService.getTheme());
            if (messageSource.doGetBundle(rService.getTheme(), request.getLocale()) != null) {
                LOGGER.debug("Found custom theme [{}] for service [{}]", rService.getTheme(), rService);
                return rService.getTheme();
            }
            LOGGER.warn("Custom theme [{}] for service [{}] cannot be located. Falling back to default theme...",
                    rService.getTheme(), rService);
        }
    }
    return getDefaultThemeName();
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:40,代码来源:ServiceThemeResolver.java


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