Search in sources :

Example 1 with CookieValue

use of org.springframework.web.bind.annotation.CookieValue in project spring-framework by spring-projects.

the class AbstractCookieValueMethodArgumentResolver method createNamedValueInfo.

@Override
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
    CookieValue annotation = parameter.getParameterAnnotation(CookieValue.class);
    Assert.state(annotation != null, "No CookieValue annotation");
    return new CookieValueNamedValueInfo(annotation);
}
Also used : CookieValue(org.springframework.web.bind.annotation.CookieValue)

Example 2 with CookieValue

use of org.springframework.web.bind.annotation.CookieValue in project spring-framework by spring-projects.

the class CookieValueMethodArgumentResolver method createNamedValueInfo.

@Override
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
    CookieValue ann = parameter.getParameterAnnotation(CookieValue.class);
    Assert.state(ann != null, "No CookieValue annotation");
    return new CookieValueNamedValueInfo(ann);
}
Also used : CookieValue(org.springframework.web.bind.annotation.CookieValue)

Example 3 with CookieValue

use of org.springframework.web.bind.annotation.CookieValue in project mica2 by obiba.

the class SignController method signup.

@GetMapping("/signup")
public ModelAndView signup(HttpServletRequest request, @RequestParam(value = "redirect", required = false) String redirect, @CookieValue(value = "NG_TRANSLATE_LANG_KEY", required = false, defaultValue = "en") String locale, @RequestParam(value = "language", required = false) String language) {
    if (!micaConfigService.getConfig().isSignupEnabled())
        return new ModelAndView("redirect:" + micaConfigService.getContextPath() + "/");
    ModelAndView mv = new ModelAndView("signup");
    String lang = getLang(locale, language);
    List<OidcProvider> providers = getOidcProviders(lang, true).stream().map(o -> new OidcProvider(o, getOidcSignupUrl(o.getName(), request, redirect))).collect(Collectors.toList());
    mv.getModel().put("oidcProviders", providers);
    mv.getModel().put("authConfig", getAuthConfiguration());
    return mv;
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) OidcProvider(org.obiba.mica.web.controller.domain.OidcProvider) Controller(org.springframework.stereotype.Controller) Collectors(java.util.stream.Collectors) UserAuthService(org.obiba.mica.core.service.UserAuthService) CookieValue(org.springframework.web.bind.annotation.CookieValue) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) ModelAndView(org.springframework.web.servlet.ModelAndView) JSONException(org.json.JSONException) HttpServletRequest(javax.servlet.http.HttpServletRequest) URLEncoder(java.net.URLEncoder) List(java.util.List) Lists(com.google.common.collect.Lists) JSONObject(org.json.JSONObject) OIDCAuthProviderSummary(org.obiba.oidc.OIDCAuthProviderSummary) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) AgateServerConfigService(org.obiba.mica.core.service.AgateServerConfigService) GetMapping(org.springframework.web.bind.annotation.GetMapping) AuthConfiguration(org.obiba.mica.web.controller.domain.AuthConfiguration) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ModelAndView(org.springframework.web.servlet.ModelAndView) OidcProvider(org.obiba.mica.web.controller.domain.OidcProvider) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with CookieValue

use of org.springframework.web.bind.annotation.CookieValue in project com.revolsys.open by revolsys.

the class WebMethodHandler method cookie.

public static WebParameterHandler cookie(final WebAnnotationMethodHandlerAdapter adapter, final Parameter parameter, final Annotation annotation) {
    final Class<?> parameterClass = parameter.getType();
    final DataType dataType = DataTypes.getDataType(parameterClass);
    final CookieValue cookieValue = (CookieValue) annotation;
    final String name = getName(parameter, cookieValue.value());
    final boolean required = cookieValue.required();
    final Object defaultValue = parseDefaultValueAttribute(dataType, cookieValue.defaultValue());
    BiFunction<HttpServletRequest, HttpServletResponse, Object> function;
    if (Cookie.class.equals(parameterClass)) {
        function = (request, response) -> {
            final Cookie cookie = WebUtils.getCookie(request, name);
            return cookie;
        };
    } else {
        function = (request, response) -> {
            final Cookie cookie = WebUtils.getCookie(request, name);
            if (cookie == null) {
                return null;
            } else {
                return cookie.getValue();
            }
        };
    }
    return // 
    WebParameterHandler.function(// 
    name, // 
    function, // 
    dataType, // 
    required, // 
    defaultValue);
}
Also used : MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Cookie(javax.servlet.http.Cookie) CookieValue(org.springframework.web.bind.annotation.CookieValue) DataType(com.revolsys.datatype.DataType) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 5 with CookieValue

use of org.springframework.web.bind.annotation.CookieValue in project mica2 by obiba.

the class SignController method signin.

@GetMapping("/signin")
public ModelAndView signin(HttpServletRequest request, @RequestParam(value = "redirect", required = false) String redirect, @CookieValue(value = "NG_TRANSLATE_LANG_KEY", required = false, defaultValue = "en") String locale, @RequestParam(value = "language", required = false) String language) {
    ModelAndView mv = new ModelAndView("signin");
    String lang = getLang(locale, language);
    List<OidcProvider> providers = getOidcProviders(lang, false).stream().map(o -> new OidcProvider(o, getOidcSigninUrl(o.getName(), request, redirect))).collect(Collectors.toList());
    mv.getModel().put("oidcProviders", providers);
    return mv;
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) OidcProvider(org.obiba.mica.web.controller.domain.OidcProvider) Controller(org.springframework.stereotype.Controller) Collectors(java.util.stream.Collectors) UserAuthService(org.obiba.mica.core.service.UserAuthService) CookieValue(org.springframework.web.bind.annotation.CookieValue) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) ModelAndView(org.springframework.web.servlet.ModelAndView) JSONException(org.json.JSONException) HttpServletRequest(javax.servlet.http.HttpServletRequest) URLEncoder(java.net.URLEncoder) List(java.util.List) Lists(com.google.common.collect.Lists) JSONObject(org.json.JSONObject) OIDCAuthProviderSummary(org.obiba.oidc.OIDCAuthProviderSummary) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) AgateServerConfigService(org.obiba.mica.core.service.AgateServerConfigService) GetMapping(org.springframework.web.bind.annotation.GetMapping) AuthConfiguration(org.obiba.mica.web.controller.domain.AuthConfiguration) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ModelAndView(org.springframework.web.servlet.ModelAndView) OidcProvider(org.obiba.mica.web.controller.domain.OidcProvider) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

CookieValue (org.springframework.web.bind.annotation.CookieValue)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Strings (com.google.common.base.Strings)2 Lists (com.google.common.collect.Lists)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URLEncoder (java.net.URLEncoder)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 AgateServerConfigService (org.obiba.mica.core.service.AgateServerConfigService)2 UserAuthService (org.obiba.mica.core.service.UserAuthService)2 MicaConfigService (org.obiba.mica.micaConfig.service.MicaConfigService)2 AuthConfiguration (org.obiba.mica.web.controller.domain.AuthConfiguration)2 OidcProvider (org.obiba.mica.web.controller.domain.OidcProvider)2 OIDCAuthProviderSummary (org.obiba.oidc.OIDCAuthProviderSummary)2 Controller (org.springframework.stereotype.Controller)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 RequestParam (org.springframework.web.bind.annotation.RequestParam)2