Search in sources :

Example 1 with MessageContext

use of org.springframework.binding.message.MessageContext in project cas by apereo.

the class AuthenticationExceptionHandlerTests method handleUnknownExceptionByDefault.

@Test
public void handleUnknownExceptionByDefault() {
    final AuthenticationExceptionHandler handler = new AuthenticationExceptionHandler();
    final MessageContext ctx = mock(MessageContext.class);
    final Map<String, Class<? extends Exception>> map = new HashMap<>();
    map.put("unknown", GeneralSecurityException.class);
    final String id = handler.handle(new AuthenticationException(map), ctx);
    assertEquals(id, "UNKNOWN");
}
Also used : HashMap(java.util.HashMap) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) MessageContext(org.springframework.binding.message.MessageContext) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) AccountLockedException(javax.security.auth.login.AccountLockedException) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) GeneralSecurityException(java.security.GeneralSecurityException) UnsatisfiedAuthenticationPolicyException(org.apereo.cas.ticket.UnsatisfiedAuthenticationPolicyException) PreventedException(org.apereo.cas.authentication.PreventedException) Test(org.junit.Test)

Example 2 with MessageContext

use of org.springframework.binding.message.MessageContext in project cas by apereo.

the class AuthenticationExceptionHandlerTests method correctHandlersOrder.

@Test
public void correctHandlersOrder() {
    final AuthenticationExceptionHandler handler = new AuthenticationExceptionHandler();
    final MessageContext ctx = mock(MessageContext.class);
    final Map<String, Class<? extends Exception>> map = new HashMap<>();
    map.put("accountLocked", AccountLockedException.class);
    map.put("accountNotFound", AccountNotFoundException.class);
    final String id = handler.handle(new AuthenticationException(map), ctx);
    assertEquals(id, AccountLockedException.class.getSimpleName());
}
Also used : AccountLockedException(javax.security.auth.login.AccountLockedException) HashMap(java.util.HashMap) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) MessageContext(org.springframework.binding.message.MessageContext) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) AccountLockedException(javax.security.auth.login.AccountLockedException) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) GeneralSecurityException(java.security.GeneralSecurityException) UnsatisfiedAuthenticationPolicyException(org.apereo.cas.ticket.UnsatisfiedAuthenticationPolicyException) PreventedException(org.apereo.cas.authentication.PreventedException) Test(org.junit.Test)

Example 3 with MessageContext

use of org.springframework.binding.message.MessageContext in project cas by apereo.

the class AuthenticationExceptionHandlerTests method handleAccountNotFoundExceptionByDefault.

@Test
public void handleAccountNotFoundExceptionByDefault() {
    final AuthenticationExceptionHandler handler = new AuthenticationExceptionHandler();
    final MessageContext ctx = mock(MessageContext.class);
    final Map<String, Class<? extends Exception>> map = new HashMap<>();
    map.put("notFound", AccountNotFoundException.class);
    final String id = handler.handle(new AuthenticationException(map), ctx);
    assertEquals(id, AccountNotFoundException.class.getSimpleName());
}
Also used : HashMap(java.util.HashMap) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) MessageContext(org.springframework.binding.message.MessageContext) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) AccountLockedException(javax.security.auth.login.AccountLockedException) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) GeneralSecurityException(java.security.GeneralSecurityException) UnsatisfiedAuthenticationPolicyException(org.apereo.cas.ticket.UnsatisfiedAuthenticationPolicyException) PreventedException(org.apereo.cas.authentication.PreventedException) Test(org.junit.Test)

Example 4 with MessageContext

use of org.springframework.binding.message.MessageContext in project cas by apereo.

the class AbstractCasWebflowEventResolver method handleAuthenticationTransactionAndGrantTicketGrantingTicket.

/**
     * Handle authentication transaction and grant ticket granting ticket set.
     *
     * @param context the context
     * @return the set
     */
protected Set<Event> handleAuthenticationTransactionAndGrantTicketGrantingTicket(final RequestContext context) {
    try {
        final Credential credential = getCredentialFromContext(context);
        AuthenticationResultBuilder builder = WebUtils.getAuthenticationResultBuilder(context);
        LOGGER.debug("Handling authentication transaction for credential [{}]", credential);
        final Service service = WebUtils.getService(context);
        builder = this.authenticationSystemSupport.handleAuthenticationTransaction(service, builder, credential);
        LOGGER.debug("Issuing ticket-granting tickets for service [{}]", service);
        return Collections.singleton(grantTicketGrantingTicketToAuthenticationResult(context, builder, service));
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        final MessageContext messageContext = context.getMessageContext();
        messageContext.addMessage(new MessageBuilder().error().code(DEFAULT_MESSAGE_BUNDLE_PREFIX.concat(e.getClass().getSimpleName())).build());
        return Collections.singleton(new EventFactorySupport().error(this));
    }
}
Also used : Credential(org.apereo.cas.authentication.Credential) MessageBuilder(org.springframework.binding.message.MessageBuilder) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) MessageContext(org.springframework.binding.message.MessageContext) AuthenticationResultBuilder(org.apereo.cas.authentication.AuthenticationResultBuilder) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 5 with MessageContext

use of org.springframework.binding.message.MessageContext in project head by mifos.

the class QuestionController method addSmartChoiceTag.

public String addSmartChoiceTag(QuestionForm questionForm, RequestContext requestContext, int choiceIndex) {
    MessageContext context = requestContext.getMessageContext();
    boolean result = validateSmartChoice(questionForm, context, choiceIndex);
    if (result) {
        questionForm.getCurrentQuestion().addSmartChoiceTag(choiceIndex);
    }
    return result ? "success" : "failure";
}
Also used : MessageContext(org.springframework.binding.message.MessageContext)

Aggregations

MessageContext (org.springframework.binding.message.MessageContext)48 Test (org.junit.Test)18 Message (org.springframework.binding.message.Message)16 MessageBuilder (org.springframework.binding.message.MessageBuilder)6 ArrayList (java.util.ArrayList)5 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)4 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)4 UnsatisfiedAuthenticationPolicyException (org.apereo.cas.ticket.UnsatisfiedAuthenticationPolicyException)4 LocalDate (org.joda.time.LocalDate)4 BigDecimal (java.math.BigDecimal)3 GeneralSecurityException (java.security.GeneralSecurityException)3 HashMap (java.util.HashMap)3 AccountLockedException (javax.security.auth.login.AccountLockedException)3 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)3 PreventedException (org.apereo.cas.authentication.PreventedException)3 DateTime (org.joda.time.DateTime)3 LoanCreationInstallmentDto (org.mifos.dto.domain.LoanCreationInstallmentDto)2 LoanScheduleDto (org.mifos.dto.screen.LoanScheduleDto)2 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)2 ErrorEntry (org.mifos.platform.validations.ErrorEntry)2