@PostConstruct
public void validate() {
if (countBeans(AuthorizationServerEndpointsConfiguration.class) > 0) {
// If we are an authorization server we don't need remote resource token
// services
return;
}
if (countBeans(ResourceServerTokenServicesConfiguration.class) == 0) {
// If we are not a resource server or an SSO client we don't need remote
// resource token services
return;
}
if (!StringUtils.hasText(this.clientId)) {
return;
}
try {
doValidate();
}
catch (BindException ex) {
throw new IllegalStateException(ex);
}
}
java类org.springframework.validation.BindException的实例源码
ResourceServerProperties.java 文件源码
项目:spring-security-oauth2-boot
阅读 37
收藏 0
点赞 0
评论 0
ResourceServerPropertiesTests.java 文件源码
项目:spring-security-oauth2-boot
阅读 41
收藏 0
点赞 0
评论 0
private BaseMatcher<BindException> getMatcher(String message, String field) {
return new BaseMatcher<BindException>() {
@Override
public void describeTo(Description description) {
}
@Override
public boolean matches(Object item) {
BindException ex = (BindException) ((Exception) item).getCause();
ObjectError error = ex.getAllErrors().get(0);
boolean messageMatches = message.equals(error.getDefaultMessage());
if (field == null) {
return messageMatches;
}
String fieldErrors = ((FieldError) error).getField();
return messageMatches && fieldErrors.equals(field);
}
};
}
AuthenticationViaFormActionTests.java 文件源码
项目:springboot-shiro-cas-mybatis
阅读 38
收藏 0
点赞 0
评论 0
@Test
public void verifyFailedAuthenticationWithNoService() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
final UsernamePasswordCredential c = org.jasig.cas.authentication.TestUtils.getCredentialsWithDifferentUsernameAndPassword();
request.addParameter("username", c.getUsername());
request.addParameter("password", c.getPassword());
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
putCredentialInRequestScope(context, c);
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(c, "credentials"));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("authenticationFailure", this.action.submit(context, c, messageContext).getId());
}
AuthenticationViaFormActionTests.java 文件源码
项目:springboot-shiro-cas-mybatis
阅读 34
收藏 0
点赞 0
评论 0
@Test
public void verifyRenewWithServiceAndBadCredentials() throws Exception {
final Credential c = org.jasig.cas.authentication.TestUtils.getCredentialsWithSameUsernameAndPassword();
final Service service = TestUtils.getService("test");
final AuthenticationContext ctx = org.jasig.cas.authentication.TestUtils.getAuthenticationContext(
getAuthenticationSystemSupport(), service, c);
final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
request.addParameter("renew", "true");
request.addParameter("service", service.getId());
final Credential c2 = org.jasig.cas.authentication.TestUtils.getCredentialsWithDifferentUsernameAndPassword();
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
putCredentialInRequestScope(context, c2);
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(c2, "credentials"));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("authenticationFailure", this.action.submit(context, c2, messageContext).getId());
}
AuthenticationViaFormActionTests.java 文件源码
项目:springboot-shiro-cas-mybatis
阅读 40
收藏 0
点赞 0
评论 0
@Test
public void verifyFailedAuthenticationWithNoService() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
request.addParameter("username", "test");
request.addParameter("password", "test2");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
putCredentialInRequestScope(context, c);
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(c, "credentials"));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("error", this.action.submit(context, c, messageContext).getId());
}
AuthenticationViaFormActionTests.java 文件源码
项目:springboot-shiro-cas-mybatis
阅读 40
收藏 0
点赞 0
评论 0
@Test
public void verifyRenewWithServiceAndBadCredentials() throws Exception {
final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(c);
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
request.addParameter("renew", "true");
request.addParameter("service", "test");
final Credential c2 = TestUtils.getCredentialsWithDifferentUsernameAndPassword();
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
putCredentialInRequestScope(context, c2);
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(c2, "credentials"));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("error", this.action.submit(context, c2, messageContext).getId());
}
AuthenticationViaFormActionTests.java 文件源码
项目:cas-5.1.0
阅读 46
收藏 0
点赞 0
评论 0
@Test
public void verifyFailedAuthenticationWithNoService() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
request.addParameter(USERNAME_PARAM, TEST);
request.addParameter(PASSWORD_PARAM, "test2");
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
final Credential c = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword();
putCredentialInRequestScope(context, c);
context.getRequestScope().put("org.springframework.validation.BindException.credentials", new BindException(c, "credential"));
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
AuthenticationViaFormActionTests.java 文件源码
项目:cas4.0.x-server-wechat
阅读 34
收藏 0
点赞 0
评论 0
@Test
public void testFailedAuthenticationWithNoService() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
request.addParameter("username", "test");
request.addParameter("password", "test2");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
context.getRequestScope().put("credentials",
TestUtils.getCredentialsWithDifferentUsernameAndPassword());
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(TestUtils
.getCredentialsWithDifferentUsernameAndPassword(),
"credentials"));
// this.action.bind(context);
// assertEquals("error", this.action.submit(context).getId());
}
AuthenticationViaFormActionTests.java 文件源码
项目:cas4.0.x-server-wechat
阅读 40
收藏 0
点赞 0
评论 0
@Test
public void testRenewWithServiceAndBadCredentials() throws Exception {
final String ticketGrantingTicket = getCentralAuthenticationService()
.createTicketGrantingTicket(
TestUtils.getCredentialsWithSameUsernameAndPassword());
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
context.getFlowScope().put("ticketGrantingTicketId", ticketGrantingTicket);
request.addParameter("renew", "true");
request.addParameter("service", "test");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
context.getRequestScope().put("credentials",
TestUtils.getCredentialsWithDifferentUsernameAndPassword());
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(TestUtils
.getCredentialsWithDifferentUsernameAndPassword(),
"credentials"));
// this.action.bind(context);
// assertEquals("error", this.action.submit(context).getId());
}
VacuumTool.java 文件源码
项目:circus-train
阅读 28
收藏 0
点赞 0
评论 0
public static void main(String[] args) throws Exception {
// below is output *before* logging is configured so will appear on console
logVersionInfo();
try {
SpringApplication.exit(new SpringApplicationBuilder(VacuumTool.class)
.properties("spring.config.location:${config:null}")
.properties("spring.profiles.active:" + Modules.REPLICATION)
.properties("instance.home:${user.home}")
.properties("instance.name:${source-catalog.name}_${replica-catalog.name}")
.bannerMode(Mode.OFF)
.registerShutdownHook(true)
.build()
.run(args));
} catch (BeanCreationException e) {
if (e.getMostSpecificCause() instanceof BindException) {
printVacuumToolHelp(((BindException) e.getMostSpecificCause()).getAllErrors());
}
throw e;
}
}
ComparisonTool.java 文件源码
项目:circus-train
阅读 39
收藏 0
点赞 0
评论 0
public static void main(String[] args) throws Exception {
// below is output *before* logging is configured so will appear on console
logVersionInfo();
try {
SpringApplication.exit(new SpringApplicationBuilder(ComparisonTool.class)
.properties("spring.config.location:${config:null}")
.properties("spring.profiles.active:" + Modules.REPLICATION)
.properties("instance.home:${user.home}")
.properties("instance.name:${source-catalog.name}_${replica-catalog.name}")
.bannerMode(Mode.OFF)
.registerShutdownHook(true)
.build()
.run(args));
} catch (BeanCreationException e) {
if (e.getMostSpecificCause() instanceof BindException) {
printComparisonToolHelp(((BindException) e.getMostSpecificCause()).getAllErrors());
throw e;
}
if (e.getMostSpecificCause() instanceof IllegalArgumentException) {
LOG.error(e.getMessage(), e);
printComparisonToolHelp(Collections.<ObjectError> emptyList());
}
}
}
FilterTool.java 文件源码
项目:circus-train
阅读 35
收藏 0
点赞 0
评论 0
public static void main(String[] args) throws Exception {
// below is output *before* logging is configured so will appear on console
logVersionInfo();
try {
SpringApplication.exit(new SpringApplicationBuilder(FilterTool.class)
.properties("spring.config.location:${config:null}")
.properties("spring.profiles.active:" + Modules.REPLICATION)
.properties("instance.home:${user.home}")
.properties("instance.name:${source-catalog.name}_${replica-catalog.name}")
.bannerMode(Mode.OFF)
.registerShutdownHook(true)
.build()
.run(args));
} catch (BeanCreationException e) {
if (e.getMostSpecificCause() instanceof BindException) {
printFilterToolHelp(((BindException) e.getMostSpecificCause()).getAllErrors());
}
throw e;
}
}
AuthenticationViaFormActionTests.java 文件源码
项目:cas-server-4.2.1
阅读 36
收藏 0
点赞 0
评论 0
@Test
public void verifyFailedAuthenticationWithNoService() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
request.addParameter("username", "test");
request.addParameter("password", "test2");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
final Credential c = org.jasig.cas.authentication.TestUtils.getCredentialsWithSameUsernameAndPassword();
putCredentialInRequestScope(context, c);
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(c, "credentials"));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("error", this.action.submit(context, c, messageContext).getId());
}
AuthenticationViaFormActionTests.java 文件源码
项目:cas-server-4.2.1
阅读 27
收藏 0
点赞 0
评论 0
@Test
public void verifyRenewWithServiceAndBadCredentials() throws Exception {
final Credential c = org.jasig.cas.authentication.TestUtils.getCredentialsWithSameUsernameAndPassword();
final Service service = TestUtils.getService("test");
final AuthenticationContext ctx = org.jasig.cas.authentication.TestUtils.getAuthenticationContext(
getAuthenticationSystemSupport(), service, c);
final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
request.addParameter("renew", "true");
request.addParameter("service", service.getId());
final Credential c2 = org.jasig.cas.authentication.TestUtils.getCredentialsWithDifferentUsernameAndPassword();
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
putCredentialInRequestScope(context, c2);
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(c2, "credentials"));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("error", this.action.submit(context, c2, messageContext).getId());
}
WaggleDance.java 文件源码
项目:waggle-dance
阅读 32
收藏 0
点赞 0
评论 0
public static void main(String[] args) throws Exception {
// below is output *before* logging is configured so will appear on console
logVersionInfo();
int exitCode = -1;
try {
SpringApplication application = new SpringApplicationBuilder(WaggleDance.class)
.properties("spring.config.location:${server-config:null},${federation-config:null}")
.properties("server.port:${endpoint.port:18000}")
.registerShutdownHook(true)
.build();
exitCode = SpringApplication.exit(registerListeners(application).run(args));
} catch (BeanCreationException e) {
if (e.getMostSpecificCause() instanceof BindException) {
printHelp(((BindException) e.getMostSpecificCause()).getAllErrors());
}
if (e.getMostSpecificCause() instanceof ConstraintViolationException) {
logConstraintErrors(((ConstraintViolationException) e.getMostSpecificCause()));
}
throw e;
}
System.exit(exitCode);
}
BindTagTests.java 文件源码
项目:spring4-understanding
阅读 39
收藏 0
点赞 0
评论 0
@Test
public void propertyExposing() throws JspException {
PageContext pc = createPageContext();
TestBean tb = new TestBean();
tb.setName("name1");
Errors errors = new BindException(tb, "tb");
errors.rejectValue("name", "code1", null, "message & 1");
errors.rejectValue("name", "code2", null, "message2");
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
// test global property (should be null)
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb");
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertNull(tag.getProperty());
// test property set (tb.name)
tag.release();
tag.setPageContext(pc);
tag.setPath("tb.name");
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertEquals("name", tag.getProperty());
}
ModelAttributeMethodProcessor.java 文件源码
项目:spring4-understanding
阅读 36
收藏 0
点赞 0
评论 0
/**
* Resolve the argument from the model or if not found instantiate it with
* its default if it is available. The model attribute is then populated
* with request values via data binding and optionally validated
* if {@code @java.validation.Valid} is present on the argument.
* @throws BindException if data binding and validation result in an error
* and the next method parameter is not of type {@link Errors}.
* @throws Exception if WebDataBinder initialization fails.
*/
@Override
public final Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
String name = ModelFactory.getNameForParameter(parameter);
Object attribute = (mavContainer.containsAttribute(name) ?
mavContainer.getModel().get(name) : createAttribute(name, parameter, binderFactory, webRequest));
WebDataBinder binder = binderFactory.createBinder(webRequest, attribute, name);
if (binder.getTarget() != null) {
bindRequestParameters(binder, webRequest);
validateIfApplicable(binder, parameter);
if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) {
throw new BindException(binder.getBindingResult());
}
}
// Add resolved attribute and BindingResult at the end of the model
Map<String, Object> bindingResultModel = binder.getBindingResult().getModel();
mavContainer.removeAttributes(bindingResultModel);
mavContainer.addAllAttributes(bindingResultModel);
return binder.convertIfNecessary(binder.getTarget(), parameter.getParameterType(), parameter);
}
PrintingResultHandlerTests.java 文件源码
项目:spring4-understanding
阅读 26
收藏 0
点赞 0
评论 0
@Test
public void modelAndView() throws Exception {
BindException bindException = new BindException(new Object(), "target");
bindException.reject("errorCode");
ModelAndView mav = new ModelAndView("viewName");
mav.addObject("attrName", "attrValue");
mav.addObject(BindingResult.MODEL_KEY_PREFIX + "attrName", bindException);
this.mvcResult.setMav(mav);
this.handler.handle(this.mvcResult);
assertValue("ModelAndView", "View name", "viewName");
assertValue("ModelAndView", "View", null);
assertValue("ModelAndView", "Attribute", "attrName");
assertValue("ModelAndView", "value", "attrValue");
assertValue("ModelAndView", "errors", bindException.getAllErrors());
}
AddUserController.java 文件源码
项目:java-project
阅读 27
收藏 0
点赞 0
评论 0
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
HttpSession session = request.getSession();
Login manager = (Login) session.getAttribute("loginUser");
Map model = new HashMap();
if (manager != null&&manager.getUsername().equals("mr")) {
Login newUser = (Login) command;
List list = dao.QueryObject("from Login where username='"
+ newUser.getUsername() + "'");
if(list.size()>0)
model.put("message", "��¼�����Ѿ����ڣ�������û�����");
else{
dao.InsertOrUpdate(newUser);
model.put("message", "�û�\""+newUser.getName()+"\"��ӳɹ���");
}
}
else
model.put("message", "Ȩ������δ��¼���뷵�ص�½��");
return new ModelAndView("userManager/addUser",model);
}
ConventionBasedSpringValidationErrorToApiErrorHandlerListener.java 文件源码
项目:backstopper
阅读 35
收藏 0
点赞 0
评论 0
@Override
public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) {
SortedApiErrorSet handledErrors = null;
if (ex instanceof MethodArgumentNotValidException) {
handledErrors = convertSpringErrorsToApiErrors(
((MethodArgumentNotValidException) ex).getBindingResult().getAllErrors()
);
}
if (ex instanceof BindException) {
handledErrors = convertSpringErrorsToApiErrors(((BindException) ex).getAllErrors());
}
if (handledErrors != null) {
return ApiExceptionHandlerListenerResult.handleResponse(handledErrors);
}
return ApiExceptionHandlerListenerResult.ignoreResponse();
}
ConventionBasedSpringValidationErrorToApiErrorHandlerListenerTest.java 文件源码
项目:backstopper
阅读 34
收藏 0
点赞 0
评论 0
@Test
public void shouldCreateValidationErrorsForBindException() {
BindingResult bindingResult = mock(BindingResult.class);
ApiError someFieldError = testProjectApiErrors.getMissingExpectedContentApiError();
ApiError otherFieldError = testProjectApiErrors.getTypeConversionApiError();
List<ObjectError> errorsList = Arrays.<ObjectError>asList(
new FieldError("someObj", "someField", someFieldError.getName()),
new FieldError("otherObj", "otherField", otherFieldError.getName()));
when(bindingResult.getAllErrors()).thenReturn(errorsList);
BindException ex = new BindException(bindingResult);
ApiExceptionHandlerListenerResult result = listener.shouldHandleException(ex);
validateResponse(result, true, Arrays.asList(
new ApiErrorWithMetadata(someFieldError, Pair.of("field", (Object)"someField")),
new ApiErrorWithMetadata(otherFieldError, Pair.of("field", (Object)"otherField"))
));
verify(bindingResult).getAllErrors();
}
BindFailureAnalyzer.java 文件源码
项目:https-github.com-g0t4-jenkins2-course-spring-boot
阅读 33
收藏 0
点赞 0
评论 0
@Override
protected FailureAnalysis analyze(Throwable rootFailure, BindException cause) {
if (CollectionUtils.isEmpty(cause.getFieldErrors())) {
return null;
}
StringBuilder description = new StringBuilder(
String.format("Binding to target %s failed:%n", cause.getTarget()));
for (FieldError fieldError : cause.getFieldErrors()) {
description.append(String.format("%n Property: %s",
cause.getObjectName() + "." + fieldError.getField()));
description.append(
String.format("%n Value: %s", fieldError.getRejectedValue()));
description.append(
String.format("%n Reason: %s%n", fieldError.getDefaultMessage()));
}
return new FailureAnalysis(description.toString(),
"Update your application's configuration", cause);
}
PropertiesConfigurationFactory.java 文件源码
项目:https-github.com-g0t4-jenkins2-course-spring-boot
阅读 45
收藏 0
点赞 0
评论 0
public void bindPropertiesToTarget() throws BindException {
Assert.state(this.properties != null || this.propertySources != null,
"Properties or propertySources should not be null");
try {
if (this.logger.isTraceEnabled()) {
if (this.properties != null) {
this.logger.trace(String.format("Properties:%n%s", this.properties));
}
else {
this.logger.trace("Property Sources: " + this.propertySources);
}
}
this.hasBeenBound = true;
doBindPropertiesToTarget();
}
catch (BindException ex) {
if (this.exceptionIfInvalid) {
throw ex;
}
this.logger.error("Failed to load Properties validation bean. "
+ "Your Properties may be invalid.", ex);
}
}
PropertiesConfigurationFactory.java 文件源码
项目:https-github.com-g0t4-jenkins2-course-spring-boot
阅读 41
收藏 0
点赞 0
评论 0
private void doBindPropertiesToTarget() throws BindException {
RelaxedDataBinder dataBinder = (this.targetName != null
? new RelaxedDataBinder(this.target, this.targetName)
: new RelaxedDataBinder(this.target));
if (this.validator != null) {
dataBinder.setValidator(this.validator);
}
if (this.conversionService != null) {
dataBinder.setConversionService(this.conversionService);
}
dataBinder.setIgnoreNestedProperties(this.ignoreNestedProperties);
dataBinder.setIgnoreInvalidFields(this.ignoreInvalidFields);
dataBinder.setIgnoreUnknownFields(this.ignoreUnknownFields);
customizeBinder(dataBinder);
Iterable<String> relaxedTargetNames = getRelaxedTargetNames();
Set<String> names = getNames(relaxedTargetNames);
PropertyValues propertyValues = getPropertyValues(names, relaxedTargetNames);
dataBinder.bind(propertyValues);
if (this.validator != null) {
validate(dataBinder);
}
}
FormModelMethodArgumentResolver.java 文件源码
项目:nbone
阅读 30
收藏 0
点赞 0
评论 0
protected void validateComponent(WebDataBinder binder, MethodParameter parameter) throws BindException {
boolean validateParameter = validateParameter(parameter);
Annotation[] annotations = binder.getTarget().getClass().getAnnotations();
for (Annotation annot : annotations) {
if (annot.annotationType().getSimpleName().startsWith("Valid") && validateParameter) {
Object hints = AnnotationUtils.getValue(annot);
binder.validate(hints instanceof Object[] ? (Object[]) hints : new Object[]{hints});
}
}
if (binder.getBindingResult().hasErrors()) {
if (isBindExceptionRequired(binder, parameter)) {
throw new BindException(binder.getBindingResult());
}
}
}
FormModelMethodArgumentResolver.java 文件源码
项目:nbone
阅读 32
收藏 0
点赞 0
评论 0
protected void validateComponent(WebDataBinder binder, MethodParameter parameter) throws BindException {
boolean validateParameter = validateParameter(parameter);
Annotation[] annotations = binder.getTarget().getClass().getAnnotations();
for (Annotation annot : annotations) {
if (annot.annotationType().getSimpleName().startsWith("Valid") && validateParameter) {
Object hints = AnnotationUtils.getValue(annot);
binder.validate(hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
}
}
if (binder.getBindingResult().hasErrors()) {
if (isBindExceptionRequired(binder, parameter)) {
throw new BindException(binder.getBindingResult());
}
}
}
AuthenticationViaFormActionTests.java 文件源码
项目:cas4.1.9
阅读 32
收藏 0
点赞 0
评论 0
@Test
public void verifyFailedAuthenticationWithNoService() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
request.addParameter("username", "test");
request.addParameter("password", "test2");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
putCredentialInRequestScope(context, c);
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(c, "credentials"));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("error", this.action.submit(context, c, messageContext).getId());
}
AuthenticationViaFormActionTests.java 文件源码
项目:cas4.1.9
阅读 41
收藏 0
点赞 0
评论 0
@Test
public void verifyRenewWithServiceAndBadCredentials() throws Exception {
final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(c);
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
request.addParameter("renew", "true");
request.addParameter("service", "test");
final Credential c2 = TestUtils.getCredentialsWithDifferentUsernameAndPassword();
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
putCredentialInRequestScope(context, c2);
context.getRequestScope().put(
"org.springframework.validation.BindException.credentials",
new BindException(c2, "credentials"));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("error", this.action.submit(context, c2, messageContext).getId());
}
PropertiesConfigurationFactory.java 文件源码
项目:spring-boot-concourse
阅读 35
收藏 0
点赞 0
评论 0
public void bindPropertiesToTarget() throws BindException {
Assert.state(this.properties != null || this.propertySources != null,
"Properties or propertySources should not be null");
try {
if (this.logger.isTraceEnabled()) {
if (this.properties != null) {
this.logger.trace(String.format("Properties:%n%s", this.properties));
}
else {
this.logger.trace("Property Sources: " + this.propertySources);
}
}
this.hasBeenBound = true;
doBindPropertiesToTarget();
}
catch (BindException ex) {
if (this.exceptionIfInvalid) {
throw ex;
}
this.logger.error("Failed to load Properties validation bean. "
+ "Your Properties may be invalid.", ex);
}
}
PremiumSettingsController.java 文件源码
项目:subsonic
阅读 38
收藏 0
点赞 0
评论 0
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object com, BindException errors)
throws Exception {
PremiumSettingsCommand command = (PremiumSettingsCommand) com;
Date now = new Date();
settingsService.setLicenseCode(command.getLicenseCode());
settingsService.setLicenseEmail(command.getLicenseInfo().getLicenseEmail());
settingsService.setLicenseDate(now);
settingsService.save();
settingsService.scheduleLicenseValidation();
// Reflect changes in view. The validator will validate the license asynchronously.
command.setLicenseInfo(settingsService.getLicenseInfo());
command.setToast(true);
return new ModelAndView(getSuccessView(), errors.getModel());
}