List of usage examples for org.springframework.web.bind ServletRequestDataBinder ServletRequestDataBinder
public ServletRequestDataBinder(@Nullable Object target, String objectName)
From source file:org.gvnix.web.json.DataBinderMappingJackson2HttpMessageConverter.java
/** * Before call to {@link ObjectMapper#readValue(java.io.InputStream, Class)} * creates a {@link ServletRequestDataBinder} and put it to current Thread * in order to be used by the {@link DataBinderDeserializer}. * <p/>/*from ww w . j a v a 2s. c om*/ * Ref: <a href= * "http://java.dzone.com/articles/java-thread-local-%E2%80%93-how-use">When * to use Thread Local?</a> * * @param javaType * @param inputMessage * @return */ private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) { try { Object target = null; String objectName = null; // CRear el DataBinder con un target object en funcion del javaType, // ponerlo en el thread local Class<?> clazz = javaType.getRawClass(); if (Collection.class.isAssignableFrom(clazz)) { Class<?> contentClazz = javaType.getContentType().getRawClass(); target = new DataBinderList<Object>(contentClazz); objectName = "list"; } else if (Map.class.isAssignableFrom(clazz)) { // TODO Class<?> contentClazz = // javaType.getContentType().getRawClass(); target = CollectionFactory.createMap(clazz, 0); objectName = "map"; } else { target = BeanUtils.instantiateClass(clazz); objectName = "bean"; } WebDataBinder binder = new ServletRequestDataBinder(target, objectName); binder.setConversionService(this.conversionService); binder.setAutoGrowNestedPaths(true); binder.setValidator(validator); ThreadLocalUtil.setThreadVariable(BindingResult.MODEL_KEY_PREFIX.concat("JSON_DataBinder"), binder); Object value = getObjectMapper().readValue(inputMessage.getBody(), javaType); return value; } catch (IOException ex) { throw new HttpMessageNotReadableException("Could not read JSON: ".concat(ex.getMessage()), ex); } }
From source file:com.gzeport.casserver.controller.GzeportServiceValidateController.java
/** * @:usermanger???????? //from ww w . jav a 2 s. co m * @?: luyd luyuandeng@gzeport.com * @: 2012-5-18?02:22:56 * @: GzeportServiceValidateController.java */ @SuppressWarnings("unchecked") protected final ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception { final WebApplicationService service = this.argumentExtractor.extractService(request); final String serviceTicketId = service != null ? service.getArtifactId() : null; if (service == null || serviceTicketId == null) { if (logger.isDebugEnabled()) { logger.debug(String.format("Could not process request; Service: %s, Service Ticket Id: %s", service, serviceTicketId)); } return generateErrorView("INVALID_REQUEST", "INVALID_REQUEST", null); } try { final Credentials serviceCredentials = getServiceCredentialsFromRequest(request); String proxyGrantingTicketId = null; // XXX should be able to validate AND THEN use if (serviceCredentials != null) { try { proxyGrantingTicketId = this.centralAuthenticationService .delegateTicketGrantingTicket(serviceTicketId, serviceCredentials); } catch (final TicketException e) { logger.error("TicketException generating ticket for: " + serviceCredentials, e); } } final Assertion assertion = this.centralAuthenticationService.validateServiceTicket(serviceTicketId, service); final ValidationSpecification validationSpecification = this.getCommandClass(); final ServletRequestDataBinder binder = new ServletRequestDataBinder(validationSpecification, "validationSpecification"); initBinder(request, binder); binder.bind(request); if (!validationSpecification.isSatisfiedBy(assertion)) { if (logger.isDebugEnabled()) { logger.debug( "ServiceTicket [" + serviceTicketId + "] does not satisfy validation specification."); } return generateErrorView("INVALID_TICKET", "INVALID_TICKET_SPEC", null); } onSuccessfulValidation(serviceTicketId, assertion); Principal principal = assertion.getChainedAuthentications() .get(assertion.getChainedAuthentications().size() - 1).getPrincipal(); User user = this.userManager.findUserByUserCode(principal.getId()); List<FuncModel> list = this.userManager.getFuncModelsList(null, String.valueOf(user.getUserId())); // String userInfo=user.getUserCode()+"#"+user.getUserId()+"#"+user.getUserPwd(); // logger.info("++++____+++++"+userInfo); Map userMap = new HashMap(); userMap.put("userId", StringHelp.trimNull(user.getUserId() != null ? user.getUserId().toString() : "")); userMap.put("userPwd", StringHelp.trimNull(user.getUserPwd())); userMap.put("userCode", StringHelp.trimNull(user.getUserCode())); userMap.put("userName", StringHelp.trimNull(user.getUserName())); userMap.put("isUse", StringHelp.trimNull(user.getIsUse())); userMap.put("customsCode", StringHelp.trimNull(user.getCustomsCode())); userMap.put("customsName", StringHelp.trimNull(user.getCustomsName())); userMap.put("company", StringHelp.trimNull(user.getCompany() != null ? user.getCompany().getCompanyId() : "")); userMap.put("userLoginType", StringHelp.trimNull(user.getUserLoginType())); userMap.put("createCompany", StringHelp.trimNull(user.getCreateCompany())); //userMap.put("userRoles", StringHelp.trimNull(user.getUserRoles().toString())); userMap.put("userSex", StringHelp.trimNull(user.getUserSex())); userMap.put("businessType", StringHelp.trimNull(user.getBusinessType())); userMap.put("createUser", StringHelp.trimNull(user.getCreateUser())); userMap.put("createTime", StringHelp .trimNull(user.getCreateTime() != null ? simpleDateFormat.format(user.getCreateTime()) : null)); userMap.put("workUnit", StringHelp.trimNull(user.getWorkUnit())); userMap.put("cardId", StringHelp.trimNull(user.getCardId())); userMap.put("cardType", StringHelp.trimNull(user.getCardType())); userMap.put("regRoleId", StringHelp.trimNull(user.getRegRoleId())); userMap.put("customsCodeExt", StringHelp.trimNull(user.getCustomsCodeExt())); userMap.put("userTel", StringHelp.trimNull(user.getUserTel())); userMap.put("userDpt", StringHelp.trimNull(user.getUserDpt())); userMap.put("userDuty", StringHelp.trimNull(user.getUserDuty())); userMap.put("birthday", StringHelp .trimNull(user.getBirthday() != null ? simpleDateFormat.format(user.getBirthday()) : null)); userMap.put("EMail", StringHelp.trimNull(user.getEMail())); userMap.put("certificate", StringHelp.trimNull(user.getCertificate())); userMap.put("clientsDesc", StringHelp.trimNull(user.getClientsDesc())); userMap.put("isModifyPwd", StringHelp.trimNull(user.getIsModifyPwd())); userMap.put("lastLoginTime", StringHelp.trimNull( user.getLastLoginTime() != null ? simpleDateFormat.format(user.getLastLoginTime()) : null)); userMap.put("attachmentid", StringHelp.trimNull(user.getAttachmentid() != null ? user.getAttachmentid().toString() : "")); userMap.put("modifyPwdTime", StringHelp.trimNull( user.getModifyPwdTime() != null ? simpleDateFormat.format(user.getModifyPwdTime()) : null)); userMap.put("newClients", StringHelp.trimNull(user.getNewClients())); userMap.put("newRoles", StringHelp.trimNull(user.getNewRoles())); userMap.put("roleCounts", StringHelp.trimNull(String.valueOf(user.getRoleCounts()))); userMap.put("rolesDesc", StringHelp.trimNull(user.getRolesDesc())); Map companyMap = new HashMap(); Company company = user.getCompany(); if (company != null) { companyMap.put("brokerType", StringHelp.trimNull(company.getBrokerType())); companyMap.put("coClass", StringHelp.trimNull(company.getCoClass())); companyMap.put("companyId", StringHelp.trimNull(company.getCompanyId())); companyMap.put("companyName", StringHelp.trimNull(company.getCompanyName())); companyMap.put("companyState", StringHelp.trimNull(company.getCompanyState())); companyMap.put("companyType", StringHelp.trimNull( company.getCompanyType() != null ? company.getCompanyType().getTypeId().toString() + "|" + company.getCompanyType().getTypeName() : "")); companyMap.put("customsCode", StringHelp.trimNull(company.getCustomsCode())); companyMap.put("customsName", StringHelp.trimNull(company.getCustomsName())); companyMap.put("english", StringHelp.trimNull(company.getEnglish())); companyMap.put("engName", StringHelp.trimNull(company.getEngName())); companyMap.put("eportCard", StringHelp.trimNull(company.getEportCard())); companyMap.put("orgCode", StringHelp.trimNull(company.getOrgCode())); } Map funSysModel = null; ArrayList modelList = new ArrayList(); if (list != null && list.size() > 0) { for (FuncModel model : list) { funSysModel = new HashMap(); funSysModel.put("css", StringHelp.trimNull(model.getCss())); // funSysModel.put("disabled", StringHelp.trimNull(model.get)); // System.out.println("--type--"+model.getFuncSysType()); funSysModel.put("funcCode", StringHelp.trimNull(model.getFuncCode())); funSysModel.put("funcId", StringHelp.trimNull(model.getFuncId())); funSysModel.put("funcIslast", StringHelp.trimNull(model.getFuncIslast())); funSysModel.put("funcIsmenu", StringHelp.trimNull(model.getFuncIsmenu())); funSysModel.put("funcmodel", StringHelp .trimNull(model.getFuncmodel() != null ? model.getFuncmodel().getFuncId() : "")); funSysModel.put("funcResume", StringHelp.trimNull(model.getFuncResume())); funSysModel.put("funcName", StringHelp.trimNull(model.getFuncName())); funSysModel.put("funcSysType", StringHelp.trimNull(model.getFuncSysType())); funSysModel.put("funcUrl", StringHelp.trimNull(model.getFuncUrl())); funSysModel.put("funcUseType", StringHelp.trimNull(model.getFuncUseType())); funSysModel.put("funcUseType0", StringHelp.trimNull(model.getFuncUseType0())); funSysModel.put("funcUseType1", StringHelp.trimNull(model.getFuncUseType1())); funSysModel.put("funcUseType2", StringHelp.trimNull(model.getFuncUseType2())); funSysModel.put("funcUseType34", StringHelp.trimNull(model.getFuncUseType34())); funSysModel.put("images", StringHelp.trimNull(model.getImages())); modelList.add(funSysModel); } } final ModelAndView success = new ModelAndView(this.successView); success.addObject(MODEL_ASSERTION, assertion); /* logger.info("LOGIN_USER:::========"+userMap); logger.info("LOGIN_COMPANY:::========"+companyMap); logger.info("LOGIN_FUNMODELLIST:::========"+modelList); */ success.addObject(LONIN_USER, userMap); success.addObject(USER_COMPANY, companyMap); success.addObject(USER_FUN_SYSMODEL, modelList); if (serviceCredentials != null && proxyGrantingTicketId != null) { final String proxyIou = this.proxyHandler.handle(serviceCredentials, proxyGrantingTicketId); success.addObject(MODEL_PROXY_GRANTING_TICKET_IOU, proxyIou); } if (logger.isDebugEnabled()) { logger.debug(String.format("Successfully validated service ticket: %s", serviceTicketId)); } return success; } catch (final TicketValidationException e) { return generateErrorView(e.getCode(), e.getCode(), new Object[] { serviceTicketId, e.getOriginalService().getId(), service.getId() }); } catch (final TicketException te) { return generateErrorView(te.getCode(), te.getCode(), new Object[] { serviceTicketId }); } catch (final UnauthorizedServiceException e) { return generateErrorView(e.getMessage(), e.getMessage(), null); } }
From source file:com.baosight.buapx.web.BuapxServiceValidateController.java
protected final ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception { final WebApplicationService service = this.argumentExtractor.extractService(request); final String serviceTicketId = service != null ? service.getArtifactId() : null; if (service == null || serviceTicketId == null) { if (logger.isDebugEnabled()) { logger.debug(String.format("Could not process request; Service: %s, Service Ticket Id: %s", service, serviceTicketId));/*from ww w . j av a 2 s .c o m*/ } return generateErrorView("INVALID_REQUEST", "INVALID_REQUEST", null); } try { final Credentials serviceCredentials = getServiceCredentialsFromRequest(request); String proxyGrantingTicketId = null; // XXX should be able to validate AND THEN use if (serviceCredentials != null) { try { proxyGrantingTicketId = this.centralAuthenticationService .delegateTicketGrantingTicket(serviceTicketId, serviceCredentials); } catch (final TicketException e) { logger.error("TicketException generating ticket for: " + serviceCredentials, e); } } final Assertion assertion = this.centralAuthenticationService.validateServiceTicket(serviceTicketId, service); final ValidationSpecification validationSpecification = this.getCommandClass(); final ServletRequestDataBinder binder = new ServletRequestDataBinder(validationSpecification, "validationSpecification"); initBinder(request, binder); binder.bind(request); if (!validationSpecification.isSatisfiedBy(assertion)) { if (logger.isDebugEnabled()) { logger.debug( "ServiceTicket [" + serviceTicketId + "] does not satisfy validation specification."); } return generateErrorView("INVALID_TICKET", "INVALID_TICKET_SPEC", null); } onSuccessfulValidation(serviceTicketId, assertion); final ModelAndView success = new ModelAndView(this.successView); success.addObject(MODEL_ASSERTION, assertion); // ????? String sysCode = parseSysCode(assertion); // for usename mapping.??? String mappedUser = validatePermissiontoSystem(assertion, sysCode); if (mappedUser == null) { return generateErrorView("INVALID_TICKET", "INVALID_TICKET_SPEC", null); } success.addObject("mappedUser", mappedUser); if (sysCode != null) { // add extra attribute addExtraParam(success, assertion); } if (serviceCredentials != null && proxyGrantingTicketId != null) { final String proxyIou = this.proxyHandler.handle(serviceCredentials, proxyGrantingTicketId); success.addObject(MODEL_PROXY_GRANTING_TICKET_IOU, proxyIou); } if (logger.isDebugEnabled()) { logger.debug(String.format("Successfully validated service ticket: %s", serviceTicketId)); } return success; } catch (final TicketValidationException e) { return generateErrorView(e.getCode(), e.getCode(), new Object[] { serviceTicketId, e.getOriginalService().getId(), service.getId() }); } catch (final TicketException te) { return generateErrorView(te.getCode(), te.getCode(), new Object[] { serviceTicketId }); } catch (final UnauthorizedServiceException e) { return generateErrorView(e.getMessage(), e.getMessage(), null); } }
From source file:com.revolsys.ui.web.rest.interceptor.WebAnnotationMethodHandlerAdapter.java
/** * Template method for creating a new ServletRequestDataBinder instance. * <p>// w w w . j av a2 s. co m * The default implementation creates a standard ServletRequestDataBinder. * This can be overridden for custom ServletRequestDataBinder subclasses. * * @param request current HTTP request * @param target the target object to bind onto (or <code>null</code> if the * binder is just used to convert a plain parameter value) * @param objectName the objectName of the target object * @return the ServletRequestDataBinder instance to use * @throws Exception in case of invalid state or arguments * @see ServletRequestDataBinder#bind(javax.servlet.ServletRequest) * @see ServletRequestDataBinder#convertIfNecessary(Object, Class, * MethodParameter) */ protected ServletRequestDataBinder createBinder(final HttpServletRequest request, final Object target, final String objectName) throws Exception { return new ServletRequestDataBinder(target, objectName); }
From source file:morph.plugin.views.annotation.AnnotationMethodHandlerAdapter.java
/** * Template method for creating a new ServletRequestDataBinder instance. * <p>The default implementation creates a standard ServletRequestDataBinder. * This can be overridden for custom ServletRequestDataBinder subclasses. * @param request current HTTP request//from w ww . j ava 2 s .c o m * @param target the target object to bind onto (or <code>null</code> * if the binder is just used to convert a plain parameter value) * @param objectName the objectName of the target object * @return the ServletRequestDataBinder instance to use * @throws Exception in case of invalid state or arguments * @see ServletRequestDataBinder#bind(javax.servlet.ServletRequest) * @see ServletRequestDataBinder#convertIfNecessary(Object, Class, org.springframework.core.MethodParameter) */ protected ServletRequestDataBinder createBinder(HttpServletRequest request, Object target, String objectName) throws Exception { return new ServletRequestDataBinder(target, objectName); }
From source file:net.unicon.cas.mfa.web.MultiFactorServiceValidateController.java
/** * <p>Handle the request. Specially, abides by the default behavior specified in the {@link org.jasig.cas.web.ServiceValidateController} * and then, invokes the {@link #getCommandClass()} method to delegate the task of spec validation. * @param request request object/*from w w w . ja v a2 s. c o m*/ * @param response response object * @return A {@link ModelAndView} object pointing to either {@link #setSuccessView(String)} or {@link #setFailureView(String)} * @throws Exception In case the authentication method cannot be retrieved by the binder from the incoming request. */ @Override protected final ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception { final WebApplicationService service = this.argumentExtractor.extractService(request); final String serviceTicketId = service != null ? service.getArtifactId() : null; final String authnMethod = getAuthenticationMethodFromRequest(request); if (service == null || serviceTicketId == null) { logger.debug(String.format("Could not process request; Service: %s, Service Ticket Id: %s", service, serviceTicketId)); return generateErrorView("INVALID_REQUEST", "INVALID_REQUEST", authnMethod, null); } try { final Credentials serviceCredentials = getServiceCredentialsFromRequest(request); String proxyGrantingTicketId = null; if (serviceCredentials != null) { try { proxyGrantingTicketId = this.centralAuthenticationService .delegateTicketGrantingTicket(serviceTicketId, serviceCredentials); } catch (final TicketException e) { logger.error("TicketException generating ticket for: " + serviceCredentials, e); } } final Assertion assertion = this.centralAuthenticationService.validateServiceTicket(serviceTicketId, service); final AbstractMultiFactorAuthenticationProtocolValidationSpecification validationSpecification = this .getCommandClass(); final ServletRequestDataBinder binder = new ServletRequestDataBinder(validationSpecification, "validationSpecification"); initBinder(request, binder); binder.bind(request); /** * The binder does not support field aliases. This means that the request parameter names * must exactly match the validation spec fields, or the match fails. Since the validation request * per the modified protocol will use 'authn_method', we could either create a matching field * inside the validation object, create a custom data binder object that does the conversion, * or simply bind the parameter manually. * * This implementation opts for the latter choice. */ validationSpecification.setAuthenticationMethod(authnMethod); try { if (!validationSpecification.isSatisfiedBy(assertion)) { logger.debug( "ServiceTicket [" + serviceTicketId + "] does not satisfy validation specification."); return generateErrorView("INVALID_TICKET", "INVALID_TICKET_SPEC", authnMethod, null); } } catch (final UnrecognizedMultiFactorAuthenticationMethodException e) { logger.debug(e.getMessage(), e); return generateErrorView(e.getCode(), e.getMessage(), authnMethod, new Object[] { e.getAuthenticationMethod() }); } catch (final UnacceptableMultiFactorAuthenticationMethodException e) { logger.debug(e.getMessage(), e); return generateErrorView(e.getCode(), e.getMessage(), authnMethod, new Object[] { serviceTicketId, e.getAuthenticationMethod() }); } onSuccessfulValidation(serviceTicketId, assertion); final ModelAndView success = new ModelAndView(this.successView); success.addObject(MODEL_ASSERTION, assertion); if (serviceCredentials != null && proxyGrantingTicketId != null) { final String proxyIou = this.proxyHandler.handle(serviceCredentials, proxyGrantingTicketId); success.addObject(MODEL_PROXY_GRANTING_TICKET_IOU, proxyIou); } final String authnMethods = MultiFactorUtils.getFulfilledAuthenticationMethodsAsString(assertion); if (StringUtils.isNotBlank(authnMethods)) { success.addObject(MODEL_AUTHN_METHOD, authnMethods); } logger.debug(String.format("Successfully validated service ticket: %s", serviceTicketId)); return success; } catch (final TicketValidationException e) { return generateErrorView(e.getCode(), e.getCode(), authnMethod, new Object[] { serviceTicketId, e.getOriginalService().getId(), service.getId() }); } catch (final TicketException te) { return generateErrorView(te.getCode(), te.getCode(), authnMethod, new Object[] { serviceTicketId }); } catch (final UnauthorizedServiceException e) { return generateErrorView(e.getMessage(), e.getMessage(), authnMethod, null); } }
From source file:no.abmu.abmstatistikk.web.AbstractOrganisationBrowsingController.java
/** * Browse sets up and handles pageHolder browsing of organisationUnits. * //w w w. ja va 2 s . co m * @param request current HTTP request * @param attribute in current HttpSession * @param finderBean specifies which organisationUnits to browse * @param viewName name of the View to render, to be resolved * by the DispatcherServlet's ViewResolver * @return ModelAndView holder for both Model and View in * the web MVC framework to be resolved by a DispatcherServlet. */ private ModelAndView browse(HttpServletRequest request, String attribute, OrgUnitFinderSpecificationBean finderBean, String viewName) { PageHolder pageHolder = (PageHolder) request.getSession(true).getAttribute(attribute); if (null == pageHolder) { pageHolder = browseOrganisationRegisterService.createNewPageHolder(finderBean); if (viewName.equals("kkdBrowseReportingMuseumView")) { pageHolder.setCurrentPageSize(pageHolder.getNrOfElements()); pageHolder.getSort().setProperty("countyNumberAndOrganisationUnitName"); } request.getSession().setAttribute(attribute, pageHolder); } ServletRequestDataBinder binder = new ServletRequestDataBinder(pageHolder, "pageHolder"); binder.bind(request); pageHolder.reload(false); return new ModelAndView(viewName, binder.getBindingResult().getModel()); }
From source file:no.abmu.abmstatistikk.web.AbstractOrganisationBrowsingController.java
/** * Browse children.// www .j av a 2 s. c o m * * @param request current HTTP request * @param attribute in current HttpSession * @param parentOrganisationUnitId * @param viewName name of the View to render, to be resolved * by the DispatcherServlet's ViewResolver * @return ModelAndView holder for both Model and View in * the web MVC framework to be resolved by a DispatcherServlet. */ private ModelAndView browseChildren(HttpServletRequest request, String attribute, Long parentOrganisationUnitId, String viewName) { PageHolderOrganisationUnitImpl pageHolder = (PageHolderOrganisationUnitImpl) request.getSession(true) .getAttribute(attribute); if (null == pageHolder || parentOrganisationUnitId != pageHolder.getWorkingFromOrgUnitId()) { pageHolder = browseOrganisationRegisterService .createNewPageHolderWithChildren(parentOrganisationUnitId); request.getSession().setAttribute(attribute, pageHolder); } ServletRequestDataBinder binder = new ServletRequestDataBinder(pageHolder, "pageHolder"); binder.bind(request); pageHolder.reload(false); return new ModelAndView(viewName, binder.getBindingResult().getModel()); }