org.apereo.cas.validation.Assertion.getPrimaryAuthentication()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.apereo.cas.validation.Assertion.getPrimaryAuthentication()方法的一些代码示例,展示了Assertion.getPrimaryAuthentication()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assertion.getPrimaryAuthentication()方法的具体详情如下:
包路径:org.apereo.cas.validation.Assertion
类名称:Assertion
方法名:getPrimaryAuthentication

Assertion.getPrimaryAuthentication介绍

[英]Gets the authentication event that is basis of this assertion.
[中]获取作为此断言基础的身份验证事件。

代码示例

代码示例来源:origin: org.apereo.cas/cas-server-core-web-api

/**
 * Gets the authentication from the model.
 *
 * @param model the model
 * @return the assertion from
 * @since 4.1.0
 */
protected Authentication getPrimaryAuthenticationFrom(final Map<String, Object> model) {
  return getAssertionFrom(model).getPrimaryAuthentication();
}

代码示例来源:origin: org.apereo.cas/cas-server-core-authentication-mfa-api

@Override
  public Pair<Boolean, Optional<MultifactorAuthenticationProvider>> validateAuthenticationContext(final Assertion assertion, final HttpServletRequest request) {
    LOGGER.debug("Locating the primary authentication associated with this service request [{}]", assertion.getService());
    val registeredService = servicesManager.findServiceBy(assertion.getService());
    val authentication = assertion.getPrimaryAuthentication();

    val requestedContext = multifactorTriggerSelectionStrategy.resolve(request, registeredService, authentication, assertion.getService());
    if (requestedContext.isEmpty()) {
      LOGGER.debug("No particular authentication context is required for this request");
      return Pair.of(Boolean.TRUE, Optional.empty());
    }

    return authenticationContextValidator.validate(authentication, requestedContext.get(), registeredService);
  }
}

代码示例来源:origin: org.apereo.cas/cas-server-support-openid

/**
 * Determine identity.
 *
 * @param service   the service
 * @param assertion the assertion
 * @return the string
 */
protected String determineIdentity(final OpenIdService service, final Assertion assertion) {
  if (assertion != null && OpenIdProtocolConstants.OPENID_IDENTIFIERSELECT.equals(service.getIdentity())) {
    return this.openIdPrefixUrl + '/' + assertion.getPrimaryAuthentication().getPrincipal().getId();
  }
  return service.getIdentity();
}

代码示例来源:origin: org.apereo.cas/cas-server-core-validation-api

@Override
  public void authorize(final HttpServletRequest request, final Service service, final Assertion assertion) {
    val registeredService = this.servicesManager.findServiceBy(service);
    RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service, registeredService);

    if (registeredService.getRequiredHandlers() != null && !registeredService.getRequiredHandlers().isEmpty()) {
      LOGGER.debug("Evaluating service [{}] to ensure required authentication handlers can satisfy assertion", service);
      val attributes = assertion.getPrimaryAuthentication().getAttributes();
      if (attributes.containsKey(AuthenticationHandler.SUCCESSFUL_AUTHENTICATION_HANDLERS)) {
        val assertedHandlers = CollectionUtils.toCollection(
          attributes.get(AuthenticationHandler.SUCCESSFUL_AUTHENTICATION_HANDLERS));
        val matchesAll = assertedHandlers.containsAll(registeredService.getRequiredHandlers());
        if (!matchesAll) {
          throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, StringUtils.EMPTY);
        }
      }
    }
  }
}

代码示例来源:origin: org.apereo.cas/cas-server-support-pac4j-core

@Override
  public void authorize(final HttpServletRequest request, final Service service, final Assertion assertion) {
    val registeredService = this.servicesManager.findServiceBy(service);
    RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service, registeredService);
    LOGGER.debug("Evaluating service [{}] for delegated authentication policy", service);
    val policy = registeredService.getAccessStrategy().getDelegatedAuthenticationPolicy();
    if (policy != null) {
      val attributes = assertion.getPrimaryAuthentication().getAttributes();

      if (attributes.containsKey(ClientCredential.AUTHENTICATION_ATTRIBUTE_CLIENT_NAME)) {
        val clientNameAttr = attributes.get(ClientCredential.AUTHENTICATION_ATTRIBUTE_CLIENT_NAME);
        val value = CollectionUtils.firstElement(clientNameAttr);
        if (value.isPresent()) {
          val client = value.get().toString();
          LOGGER.debug("Evaluating delegated authentication policy [{}] for client [{}] and service [{}]", policy, client, registeredService);

          val context = AuditableContext.builder()
            .registeredService(registeredService)
            .properties(CollectionUtils.wrap(Client.class.getSimpleName(), client))
            .build();
          val result = delegatedAuthenticationPolicyEnforcer.execute(context);
          result.throwExceptionIfNeeded();
        }
      }
    }
  }
}

相关文章