Java Code Examples for org.springframework.binding.message.MessageContext#addMessage()

The following examples show how to use org.springframework.binding.message.MessageContext#addMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PersonSearchAction.java    From openregistry with Apache License 2.0 6 votes vote down vote up
public void setConfirmationMessage(final ServiceExecutionResult<Person> serviceExecutionResult, final ReconciliationResult reconciliationResult, final MessageContext context) {
    //if reconciliation result is EXACT or MAYBE then only a role was added, not a new person.
    //a force add, would result in no reconciliationResult.

    if (reconciliationResult != null){
        if (reconciliationResult.getReconciliationType() == ReconciliationResult.ReconciliationType.EXACT ||
                reconciliationResult.getReconciliationType() == ReconciliationResult.ReconciliationType.MAYBE) {
            context.addMessage(new MessageBuilder().info().code("roleAdded").build());
            return;
        }
    }

    final Person person = serviceExecutionResult.getTargetObject();
    final Identifier netId = person.getPrimaryIdentifiersByType().get(this.preferredPersonIdentifierType);

    if (person.getCurrentActivationKey() != null) {
        final MessageResolver message = new MessageBuilder().info().code("personAddedFinalConfirm").arg(netId.getValue()).arg(person.getCurrentActivationKey().asString()).build();
        context.addMessage(message);
    } else {
        context.addMessage(new MessageBuilder().info().code("personAddedFinalConfirm").arg(netId.getValue()).arg("TempKey").build());
    }
}
 
Example 2
Source File: PersonSearchAction.java    From openregistry with Apache License 2.0 6 votes vote down vote up
public void setConfirmationMessage(final ServiceExecutionResult<Person> serviceExecutionResult, final ReconciliationResult reconciliationResult, final MessageContext context) {
    //if reconciliation result is EXACT or MAYBE then only a role was added, not a new person.
    //a force add, would result in no reconciliationResult.

    if (reconciliationResult != null){
        if (reconciliationResult.getReconciliationType() == ReconciliationResult.ReconciliationType.EXACT ||
                reconciliationResult.getReconciliationType() == ReconciliationResult.ReconciliationType.MAYBE) {
            context.addMessage(new MessageBuilder().info().code("roleAdded").build());
            return;
        }
    }

    final Person person = serviceExecutionResult.getTargetObject();
    final Identifier netId = person.getPrimaryIdentifiersByType().get(this.preferredPersonIdentifierType);

    if (person.getCurrentActivationKey() != null) {
        final MessageResolver message = new MessageBuilder().info().code("personAddedFinalConfirm").arg(netId.getValue()).arg(person.getCurrentActivationKey().asString()).build();
        context.addMessage(message);
    } else {
        context.addMessage(new MessageBuilder().info().code("personAddedFinalConfirm").arg(netId.getValue()).arg("TempKey").build());
    }
}
 
Example 3
Source File: AbstractMultiFactorAuthenticationViaFormAction.java    From cas-mfa with Apache License 2.0 5 votes vote down vote up
/**
 * Populate errors instance.
 *
 * @param code the error code
 * @param messageContext the message context
 */
protected final void populateErrorsInstance(final String code, final MessageContext messageContext) {
    try {
        messageContext.addMessage(new MessageBuilder().error().code(code).defaultText(code).build());
    }  catch (final Exception fe) {
        logger.error(fe.getMessage(), fe);
    }
}
 
Example 4
Source File: AbstractPersonServiceAction.java    From openregistry with Apache License 2.0 5 votes vote down vote up
public final boolean convertAndReturnStatus(final ServiceExecutionResult<?> serviceExecutionResult, final MessageContext messageContext, final String successMessageCode) {
    this.converter.convertValidationErrors(serviceExecutionResult.getValidationErrors(), messageContext);

    if (serviceExecutionResult.succeeded() && successMessageCode != null) {
        messageContext.addMessage(new MessageBuilder().info().code(successMessageCode).build());
    }
    return serviceExecutionResult.succeeded();
}
 
Example 5
Source File: RoleAction.java    From openregistry with Apache License 2.0 5 votes vote down vote up
public boolean isRoleNewForPerson(SorPerson sorPerson, Type affiliationType, MessageContext context) {
	//check if person already has the role to be added.
	logger.info("IsRoleNewForPerson: code:"+ affiliationType);
	final Person person = getPersonService().findPersonById(sorPerson.getPersonId());
	if (person.pickOutRole(affiliationType) != null){
		context.addMessage(new MessageBuilder().error().code("roleAlreadyExists").build());
		return false;
	}
	return true;
}
 
Example 6
Source File: AbstractPersonServiceAction.java    From openregistry with Apache License 2.0 5 votes vote down vote up
public final boolean convertAndReturnStatus(final ServiceExecutionResult<?> serviceExecutionResult, final MessageContext messageContext, final String successMessageCode) {
    this.converter.convertValidationErrors(serviceExecutionResult.getValidationErrors(), messageContext);

    if (serviceExecutionResult.succeeded() && successMessageCode != null) {
        messageContext.addMessage(new MessageBuilder().info().code(successMessageCode).build());
    }
    return serviceExecutionResult.succeeded();
}
 
Example 7
Source File: User.java    From enhanced-pet-clinic with Apache License 2.0 5 votes vote down vote up
public void validateCreateUser(ValidationContext context) {
	MessageContext messages = context.getMessageContext();
	if (!StringUtils.equals(uiPassword, verifyPassword)) {
		messages.addMessage(new MessageBuilder().error().source("password").source("verifyPassword")
				.defaultText("Passwords must be the same.").build());
	}
}
 
Example 8
Source File: AuthenticationViaFormAction.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a warning message to the message context.
 *
 * @param context Message context.
 * @param warning Warning message.
 */
private void addWarningToContext(final MessageContext context, final Message warning) {
    final MessageBuilder builder = new MessageBuilder()
            .warning()
            .code(warning.getCode())
            .defaultText(warning.getDefaultMessage())
            .args(warning.getParams());
    context.addMessage(builder.build());
}
 
Example 9
Source File: MultifactorLoginViewPrincipalAttributeGreeter.java    From cas-mfa with Apache License 2.0 5 votes vote down vote up
@Override
public String getPersonToGreet(final Principal p, final MessageContext messageContext) {

    String personId = p.getId();
    final Object attrValue = p.getAttributes().get(this.greetingAttributeName);

    if (attrValue == null) {
        LOGGER.warn("No attribute value could be found for [{}]", this.greetingAttributeName);
        return p.getId();
    }

    String greetingPersonId = attrValue.toString();
    if (attrValue instanceof Collection) {
        final Collection col =((Collection) attrValue);
        if (!col.isEmpty()) {
            greetingPersonId = col.iterator().next().toString();
            LOGGER.warn("Found multiple attribute values [{}] for [{}] to greet. Picked [{}]",
                    attrValue, this.greetingAttributeName,
                    greetingPersonId);
        }
    }

    if (!StringUtils.isBlank(greetingPersonId)) {
        personId = greetingPersonId;
    }

    final MessageResolver resolver = new MessageBuilder().source(CODE).info().code(CODE).arg(personId).build();
    messageContext.addMessage(resolver);

    final Message[] messages = messageContext.getMessagesBySource(CODE);
    if (messages == null || messages.length == 0) {
        LOGGER.warn("The greeting message for principal [{}] could not be resolved by the "
                + "code [{}] in any of the configured message resource bundles. Falling back to principal id [{}]",
                p, CODE, p.getId());
        return p.getId();
    }
    return messages[0].getText();
}
 
Example 10
Source File: ValidateLoginCaptchaAction.java    From sso with MIT License 4 votes vote down vote up
/**
 * 跳转到错误页
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 11
Source File: AuthenticationViaFormAction.java    From springboot-shiro-cas-mybatis with MIT License 3 votes vote down vote up
/**
 * Return invalid login ticket event.
 *
 * @param context the context
 * @param messageContext the message context
 * @return the error event
 * @since 4.1.0
 */
protected Event returnInvalidLoginTicketEvent(final RequestContext context, final MessageContext messageContext) {
    final String loginTicketFromRequest = WebUtils.getLoginTicketFromRequest(context);
    logger.warn("Invalid login ticket [{}]", loginTicketFromRequest);
    messageContext.addMessage(new MessageBuilder().error().code("error.invalid.loginticket").build());
    return newEvent(ERROR);
}
 
Example 12
Source File: SpringErrorValidationErrorConverter.java    From openregistry with Apache License 2.0 3 votes vote down vote up
/**
 * Converts the validation errors returned from the {@link org.openregistry.core.service.PersonService} into
 * Spring {@link org.springframework.binding.message.MessageContext} for Spring Web flow.
 *
 * @param validationErrors the errors provided by the {@link org.openregistry.core.service.PersonService}
 * @param messages an instance of Spring's {@link org.springframework.binding.message.MessageContext}
 */
public void convertValidationErrors(final Set<ConstraintViolation> validationErrors, final MessageContext messages) {
    for (final ConstraintViolation violation : validationErrors) {
        messages.addMessage(new MessageBuilder().error().args(violation.getConstraintDescriptor().getAttributes().values().toArray())
                .source(violation.getPropertyPath().toString()).code(violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName()).defaultText(violation.getMessage()).build());
    }
}
 
Example 13
Source File: SpringErrorValidationErrorConverter.java    From openregistry with Apache License 2.0 3 votes vote down vote up
/**
 * Converts the validation errors returned from the {@link org.openregistry.core.service.PersonService} into
 * Spring {@link org.springframework.binding.message.MessageContext} for Spring Web flow.
 *
 * @param validationErrors the errors provided by the {@link org.openregistry.core.service.PersonService}
 * @param messages an instance of Spring's {@link org.springframework.binding.message.MessageContext}
 */
public void convertValidationErrors(final Set<ConstraintViolation> validationErrors, final MessageContext messages) {
    for (final ConstraintViolation violation : validationErrors) {
        messages.addMessage(new MessageBuilder().error().args(violation.getConstraintDescriptor().getAttributes().values().toArray())
                .source(violation.getPropertyPath().toString()).code(violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName()).defaultText(violation.getMessage()).build());
    }
}
 
Example 14
Source File: ValidateLoginAction.java    From CAS with Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 15
Source File: ValidateLoginAction.java    From CAS with Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 16
Source File: ValidateLoginAction.java    From CAS with Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 17
Source File: ValidateLoginAction.java    From CAS with Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 18
Source File: ValidateLoginAction.java    From CAS with Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 19
Source File: ValidateLoginAction.java    From CAS with Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 20
Source File: ValidateLoginAction.java    From CAS with Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}