当前位置: 首页>>代码示例>>Java>>正文


Java AuthenticationException类代码示例

本文整理汇总了Java中org.apereo.cas.authentication.AuthenticationException的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationException类的具体用法?Java AuthenticationException怎么用?Java AuthenticationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AuthenticationException类属于org.apereo.cas.authentication包,在下文中一共展示了AuthenticationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loginUnsuccessfully

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
@Override
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("POST");
    request.setParameter("username", username);
    request.setRemoteAddr(fromAddress);
    final MockRequestContext context = new MockRequestContext();
    context.setCurrentEvent(new Event(StringUtils.EMPTY, "error"));
    request.setAttribute("flowRequestContext", context);
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

    throttle.preHandle(request, response, null);

    try {
        authenticationManager.authenticate(AuthenticationTransaction.wrap(CoreAuthenticationTestUtils.getService(), badCredentials(username)));
    } catch (final AuthenticationException e) {
        throttle.postHandle(request, response, null, null);
        return response;
    }
    fail("Expected AbstractAuthenticationException");
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:25,代码来源:InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests.java

示例2: handle

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
/**
 * Maps an authentication exception onto a state name. Also sets an ERROR severity message in the message context.
 *
 * @param e              Authentication error to handle.
 * @param messageContext the spring message context
 * @return Name of next flow state to transition to or {@value #UNKNOWN}
 */
public String handle(final Exception e, final MessageContext messageContext) {
    if (e instanceof AuthenticationException) {
        return handleAuthenticationException((AuthenticationException) e, messageContext);
    }

    if (e instanceof AbstractTicketException) {
        return handleAbstractTicketException((AbstractTicketException) e, messageContext);
    }

    // we don't recognize this exception
    LOGGER.trace("Unable to translate errors of the authentication exception [{}]"
            + "Returning [{}]", e, UNKNOWN);
    final String messageCode = this.messageBundlePrefix + UNKNOWN;
    messageContext.addMessage(new MessageBuilder().error().code(messageCode).build());
    return UNKNOWN;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:24,代码来源:AuthenticationExceptionHandlerAction.java

示例3: handleAuthenticationException

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
/**
 * Maps an authentication exception onto a state name equal to the simple class name of the {@link
 * AuthenticationException#getHandlerErrors()}
 * with highest precedence. Also sets an ERROR severity message in the
 * message context of the form {@code [messageBundlePrefix][exceptionClassSimpleName]}
 * for for the first handler
 * error that is configured. If no match is found, {@value #UNKNOWN} is returned.
 *
 * @param e              Authentication error to handle.
 * @param messageContext the spring message context
 * @return Name of next flow state to transition to or {@value #UNKNOWN}
 */
protected String handleAuthenticationException(final AuthenticationException e,
                                               final MessageContext messageContext) {
    // find the first error in the error list that matches the handlerErrors
    final String handlerErrorName = this.errors.stream().filter(e.getHandlerErrors().values()::contains)
            .map(Class::getSimpleName).findFirst().orElseGet(() -> {
                LOGGER.error("Unable to translate handler errors of the authentication exception [{}]"
                        + "Returning [{}]", e, UNKNOWN);
                return UNKNOWN;
            });

    // output message and return handlerErrorName
    final String messageCode = this.messageBundlePrefix + handlerErrorName;
    messageContext.addMessage(new MessageBuilder().error().code(messageCode).build());
    return handlerErrorName;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:28,代码来源:AuthenticationExceptionHandlerAction.java

示例4: doExecute

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    final String agent = WebUtils.getHttpServletRequestUserAgent();
    final GeoLocationRequest geoLocation = WebUtils.getHttpServletRequestGeoLocation();

    if (!adaptiveAuthenticationPolicy.apply(agent, geoLocation)) {
        final String msg = "Adaptive authentication policy does not allow this request for " + agent + " and " + geoLocation;
        final Map<String, Class<? extends Exception>> map = Collections.singletonMap(
                UnauthorizedAuthenticationException.class.getSimpleName(),
                UnauthorizedAuthenticationException.class);
        final AuthenticationException error = new AuthenticationException(msg, map, Collections.emptyMap());
        return new Event(this, CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE,
                new LocalAttributeMap(CasWebflowConstants.TRANSITION_ID_ERROR, error));
    }

    final Event serviceTicketEvent = this.serviceTicketRequestWebflowEventResolver.resolveSingle(requestContext);
    if (serviceTicketEvent != null) {
        fireEventHooks(serviceTicketEvent, requestContext);
        return serviceTicketEvent;
    }
    
    final Event finalEvent = this.initialAuthenticationAttemptWebflowEventResolver.resolveSingle(requestContext);
    fireEventHooks(finalEvent, requestContext);
    return finalEvent;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:26,代码来源:AbstractAuthenticationAction.java

示例5: grantServiceTicket

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
/**
 * Grant service ticket for the given credential based on the service and tgt
 * that are found in the request context.
 *
 * @param context the context
 * @return the resulting event. Warning, authentication failure or error.
 * @since 4.1.0
 */
protected Event grantServiceTicket(final RequestContext context) {
    final String ticketGrantingTicketId = WebUtils.getTicketGrantingTicketId(context);
    final Credential credential = getCredentialFromContext(context);

    try {
        final Service service = WebUtils.getService(context);
        final AuthenticationResult authenticationResult =
                this.authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(service, credential);

        final ServiceTicket serviceTicketId = this.centralAuthenticationService.grantServiceTicket(ticketGrantingTicketId, service, authenticationResult);
        WebUtils.putServiceTicketInRequestScope(context, serviceTicketId);
        WebUtils.putWarnCookieIfRequestParameterPresent(this.warnCookieGenerator, context);
        return newEvent(CasWebflowConstants.TRANSITION_ID_WARN);

    } catch (final AuthenticationException | AbstractTicketException e) {
        return newEvent(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:27,代码来源:ServiceTicketRequestWebflowEventResolver.java

示例6: validateEventIdForMatchingTransitionInContext

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
/**
 * Validate event for transition.
 *
 * @param eventId    the event id
 * @param context    the context
 * @param attributes the attributes
 * @return the event
 */
protected Event validateEventIdForMatchingTransitionInContext(final String eventId, final RequestContext context, final Map<String, Object> attributes) {
    try {
        final AttributeMap<Object> attributesMap = new LocalAttributeMap<>(attributes);
        final Event event = new Event(this, eventId, attributesMap);

        LOGGER.debug("Resulting event id is [{}]. Locating transitions in the context for that event id...", event.getId());

        final TransitionDefinition def = context.getMatchingTransition(event.getId());
        if (def == null) {
            LOGGER.warn("Transition definition cannot be found for event [{}]", event.getId());
            throw new AuthenticationException();
        }
        LOGGER.debug("Found matching transition [{}] with target [{}] for event [{}] with attributes [{}].",
                def.getId(), def.getTargetStateId(), event.getId(), event.getAttributes());
        return event;
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:28,代码来源:AbstractCasWebflowEventResolver.java

示例7: executeInternal

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
@Override
protected AuthenticationRiskContingencyResponse executeInternal(final Authentication authentication,
                                                                final RegisteredService service,
                                                                final AuthenticationRiskScore score,
                                                                final HttpServletRequest request) {
    
    final Map<String, MultifactorAuthenticationProvider> providerMap =
            WebUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext);
    if (providerMap == null || providerMap.isEmpty()) {
        LOGGER.warn("No multifactor authentication providers are available in the application context");
        throw new AuthenticationException();
    }

    String id = casProperties.getAuthn().getAdaptive().getRisk().getResponse().getMfaProvider();
    if (StringUtils.isBlank(id)) {
        if (providerMap.size() == 1) {
            id = providerMap.values().iterator().next().getId();
        } else {
            LOGGER.warn("No multifactor authentication providers are specified to handle risk-based authentication");
            throw new AuthenticationException();
        }
    }

    final String attributeName = casProperties.getAuthn().getAdaptive().getRisk().getResponse().getRiskyAuthenticationAttribute();
    final Authentication newAuthn = DefaultAuthenticationBuilder.newInstance(authentication)
            .addAttribute(attributeName, Boolean.TRUE)
            .build();
    LOGGER.debug("Updated authentication to remember risk-based authn via [{}]", attributeName);
    authentication.update(newAuthn);
    return new AuthenticationRiskContingencyResponse(new Event(this, id));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:32,代码来源:MultifactorAuthenticationContingencyPlan.java

示例8: doExecute

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
@Override
protected Event doExecute(final RequestContext context) throws Exception {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final HttpServletResponse response = WebUtils.getHttpServletResponse(context);

    final Service service = WebUtils.getService(context);
    final String ticketGrantingTicket = WebUtils.getTicketGrantingTicketId(context);

    final Authentication authentication = this.ticketRegistrySupport.getAuthenticationFrom(ticketGrantingTicket);
    if (authentication == null) {
        throw new InvalidTicketException(
                new AuthenticationException("No authentication found for ticket " + ticketGrantingTicket), ticketGrantingTicket);
    }

    final Credential credential = WebUtils.getCredential(context);
    final AuthenticationResultBuilder authenticationResultBuilder =
            authenticationSystemSupport.establishAuthenticationContextFromInitial(authentication, credential);
    final AuthenticationResult authenticationResult = authenticationResultBuilder.build(service);

    final ServiceTicket serviceTicketId = this.centralAuthenticationService.grantServiceTicket(ticketGrantingTicket, service, authenticationResult);
    WebUtils.putServiceTicketInRequestScope(context, serviceTicketId);

    if (request.getParameterMap().containsKey("ignorewarn")) {
        if (Boolean.valueOf(request.getParameter("ignorewarn"))) {
            this.warnCookieGenerator.removeCookie(response);
        }
    }
    return new Event(this, CasWebflowConstants.STATE_ID_REDIRECT);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:30,代码来源:ServiceWarningAction.java

示例9: handleProxyGrantingTicketDelivery

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
/**
 * Handle proxy granting ticket delivery.
 *
 * @param serviceTicketId the service ticket id
 * @param credential the service credential
 * @return the ticket granting ticket
 */
private TicketGrantingTicket handleProxyGrantingTicketDelivery(final String serviceTicketId, final Credential credential)
    throws AuthenticationException, AbstractTicketException {
    final ServiceTicket serviceTicket = this.centralAuthenticationService.getTicket(serviceTicketId, ServiceTicket.class);
    final AuthenticationResult authenticationResult =
            this.authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(serviceTicket.getService(), credential);
    final TicketGrantingTicket proxyGrantingTicketId = this.centralAuthenticationService.createProxyGrantingTicket(serviceTicketId, authenticationResult);
    LOGGER.debug("Generated proxy-granting ticket [{}] off of service ticket [{}] and credential [{}]",
            proxyGrantingTicketId.getId(), serviceTicketId, credential);

    return proxyGrantingTicketId;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:AbstractServiceValidateController.java

示例10: isAvailable

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
@Override
public boolean isAvailable(final RegisteredService service) throws AuthenticationException {
    RegisteredServiceMultifactorPolicy.FailureModes failureMode = RegisteredServiceMultifactorPolicy.FailureModes.CLOSED;
    final RegisteredServiceMultifactorPolicy policy = service.getMultifactorPolicy();
    if (policy != null) {
        failureMode = policy.getFailureMode();
        LOGGER.debug("Multifactor failure mode for [{}] is defined as [{}]", service.getServiceId(), failureMode);
    } else if (StringUtils.isNotBlank(this.globalFailureMode)) {
        failureMode = RegisteredServiceMultifactorPolicy.FailureModes.valueOf(this.globalFailureMode);
        LOGGER.debug("Using global multifactor failure mode for [{}] defined as [{}]", service.getServiceId(), failureMode);
    }

    if (failureMode != RegisteredServiceMultifactorPolicy.FailureModes.NONE) {
        if (isAvailable()) {
            return true;
        }
        if (failureMode == RegisteredServiceMultifactorPolicy.FailureModes.CLOSED) {
            LOGGER.warn("[{}] could not be reached. Authentication shall fail for [{}]",
                    getClass().getSimpleName(), service.getServiceId());
            throw new AuthenticationException();
        }

        LOGGER.warn("[{}] could not be reached. Since the authentication provider is configured for the "
                        + "failure mode of [{}] authentication will proceed without [{}] for service [{}]",
                getClass().getSimpleName(), failureMode, getClass().getSimpleName(), service.getServiceId());
        return false;
    }
    LOGGER.debug("Failure mode is set to [{}]. Assuming the provider is available.", failureMode);
    return true;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:31,代码来源:AbstractMultifactorAuthenticationProvider.java

示例11: handleAccountNotFoundExceptionByDefault

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
@Test
public void handleAccountNotFoundExceptionByDefault() {
    final AuthenticationExceptionHandlerAction handler = new AuthenticationExceptionHandlerAction();
    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());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:11,代码来源:AuthenticationExceptionHandlerActionTests.java

示例12: handleUnknownExceptionByDefault

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
@Test
public void handleUnknownExceptionByDefault() {
    final AuthenticationExceptionHandlerAction handler = new AuthenticationExceptionHandlerAction();
    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");
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:11,代码来源:AuthenticationExceptionHandlerActionTests.java

示例13: correctHandlersOrder

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
@Test
public void correctHandlersOrder() {
    final AuthenticationExceptionHandlerAction handler = new AuthenticationExceptionHandlerAction();
    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());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:12,代码来源:AuthenticationExceptionHandlerActionTests.java

示例14: grantServiceTicket

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
@Audit(
        action = "SERVICE_TICKET",
        actionResolverName = "GRANT_SERVICE_TICKET_RESOLVER",
        resourceResolverName = "GRANT_SERVICE_TICKET_RESOURCE_RESOLVER")
@Timed(name = "GRANT_SERVICE_TICKET_TIMER")
@Metered(name = "GRANT_SERVICE_TICKET_METER")
@Counted(name = "GRANT_SERVICE_TICKET_COUNTER", monotonic = true)
@Override
public ServiceTicket grantServiceTicket(final String ticketGrantingTicketId, final Service service, final AuthenticationResult authenticationResult)
        throws AuthenticationException, AbstractTicketException {

    final TicketGrantingTicket ticketGrantingTicket = getTicket(ticketGrantingTicketId, TicketGrantingTicket.class);
    final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
    RegisteredServiceAccessStrategyUtils.ensurePrincipalAccessIsAllowedForService(service, registeredService, ticketGrantingTicket);

    final Authentication currentAuthentication = evaluatePossibilityOfMixedPrincipals(authenticationResult, ticketGrantingTicket);
    RegisteredServiceAccessStrategyUtils.ensureServiceSsoAccessIsAllowed(registeredService, service, ticketGrantingTicket);
    evaluateProxiedServiceIfNeeded(service, ticketGrantingTicket, registeredService);

    // Perform security policy check by getting the authentication that satisfies the configured policy
    // This throws if no suitable policy is found
    getAuthenticationSatisfiedByPolicy(currentAuthentication, new ServiceContext(service, registeredService));

    final Authentication latestAuthentication = ticketGrantingTicket.getRoot().getAuthentication();
    AuthenticationCredentialsLocalBinder.bindCurrent(latestAuthentication);
    final Principal principal = latestAuthentication.getPrincipal();
    final ServiceTicketFactory factory = this.ticketFactory.get(ServiceTicket.class);
    final ServiceTicket serviceTicket = factory.create(ticketGrantingTicket, service,
            authenticationResult != null && authenticationResult.isCredentialProvided());
    this.ticketRegistry.updateTicket(ticketGrantingTicket);
    this.ticketRegistry.addTicket(serviceTicket);

    LOGGER.info("Granted ticket [{}] for service [{}] and principal [{}]",
            serviceTicket.getId(), service.getId(), principal.getId());

    doPublishEvent(new CasServiceTicketGrantedEvent(this, ticketGrantingTicket, serviceTicket));

    return serviceTicket;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:40,代码来源:DefaultCentralAuthenticationService.java

示例15: createTicketGrantingTicket

import org.apereo.cas.authentication.AuthenticationException; //导入依赖的package包/类
@Audit(
        action = "TICKET_GRANTING_TICKET",
        actionResolverName = "CREATE_TICKET_GRANTING_TICKET_RESOLVER",
        resourceResolverName = "CREATE_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name = "CREATE_TICKET_GRANTING_TICKET_TIMER")
@Metered(name = "CREATE_TICKET_GRANTING_TICKET_METER")
@Counted(name = "CREATE_TICKET_GRANTING_TICKET_COUNTER", monotonic = true)
@Override
public TicketGrantingTicket createTicketGrantingTicket(final AuthenticationResult authenticationResult)
        throws AuthenticationException, AbstractTicketException {

    final Authentication authentication = authenticationResult.getAuthentication();
    final Service service = authenticationResult.getService();
    AuthenticationCredentialsLocalBinder.bindCurrent(authentication);

    if (service != null) {
        final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
        RegisteredServiceAccessStrategyUtils.ensurePrincipalAccessIsAllowedForService(service, registeredService, authentication);
    }

    final TicketGrantingTicketFactory factory = this.ticketFactory.get(TicketGrantingTicket.class);
    final TicketGrantingTicket ticketGrantingTicket = factory.create(authentication);

    this.ticketRegistry.addTicket(ticketGrantingTicket);

    doPublishEvent(new CasTicketGrantingTicketCreatedEvent(this, ticketGrantingTicket));

    return ticketGrantingTicket;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:30,代码来源:DefaultCentralAuthenticationService.java


注:本文中的org.apereo.cas.authentication.AuthenticationException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。