org.apereo.cas.authentication.Authentication类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(13.6k)|赞(0)|评价(0)|浏览(202)

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

Authentication介绍

暂无

代码示例

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

/**
 * Gets principal attributes for multifactor authentication.
 *
 * @param authentication the authentication
 * @return the principal attributes for multifactor authentication
 */
protected Principal getPrincipalForMultifactorAuthentication(final Authentication authentication) {
  return authentication.getPrincipal();
}

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

@Override
public Set<Event> resolveEventViaAuthenticationAttribute(final Authentication authentication,
                             final Collection<String> attributeNames,
                             final RegisteredService service,
                             final Optional<RequestContext> context,
                             final Collection<MultifactorAuthenticationProvider> providers,
                             final Predicate<String> predicate) {
  return resolveEventViaAttribute(authentication.getPrincipal(), authentication.getAttributes(),
    attributeNames, service, context, providers, predicate);
}

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

/**
 * Build  cas assertion.
 *
 * @param authentication      the authentication
 * @param service             the service
 * @param registeredService   the registered service
 * @param attributesToCombine the attributes to combine
 * @return the assertion
 */
protected Assertion buildCasAssertion(final Authentication authentication,
                   final Service service,
                   final RegisteredService registeredService,
                   final Map<String, Object> attributesToCombine) {
  val attributes = registeredService.getAttributeReleasePolicy().getAttributes(authentication.getPrincipal(), service, registeredService);
  val principal = new AttributePrincipalImpl(authentication.getPrincipal().getId(), attributes);
  val authnAttrs = new LinkedHashMap(authentication.getAttributes());
  authnAttrs.putAll(attributesToCombine);
  return new AssertionImpl(principal, DateTimeUtils.dateOf(authentication.getAuthenticationDate()),
    null, DateTimeUtils.dateOf(authentication.getAuthenticationDate()),
    authnAttrs);
}

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

@Override
public void update(final Authentication authn) {
  this.attributes.putAll(authn.getAttributes());
  this.authenticationDate = authn.getAuthenticationDate();
}

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

@Override
  public boolean isSatisfiedBy(final Authentication authn, final Set<AuthenticationHandler> authenticationHandlers) {
    LOGGER.debug("Successful authentications: [{}], credentials: [{}]", authn.getSuccesses().keySet(), authn.getCredentials());
    if (authn.getSuccesses().size() != authn.getCredentials().size()) {
      LOGGER.warn("Number of successful authentications, [{}], does not match the number of provided credentials, [{}].",
        authn.getSuccesses().size(), authn.getCredentials().size());
      return false;
    }
    LOGGER.debug("Authentication policy is satisfied.");
    return true;
  }
}

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

/**
 * Creates a new builder initialized with data from the given authentication source.
 *
 * @param source Authentication source.
 * @return New builder instance initialized with all fields in the given authentication source.
 */
public static AuthenticationBuilder newInstance(final Authentication source) {
  val builder = new DefaultAuthenticationBuilder(source.getPrincipal());
  builder.setAuthenticationDate(source.getAuthenticationDate());
  builder.setCredentials(source.getCredentials());
  builder.setSuccesses(source.getSuccesses());
  builder.setFailures(source.getFailures());
  builder.setAttributes(source.getAttributes());
  return builder;
}

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

@Override
  public boolean supports(final Authentication authentication, final Object resultValue, final Exception exception) {
    return super.supports(authentication, resultValue, exception)
      && authentication.getAttributes().containsKey(SurrogateAuthenticationService.AUTHENTICATION_ATTR_SURROGATE_USER);
  }
}

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

private Authentication buildAuthentication(final PrincipalElectionStrategy principalElectionStrategy) {
  if (isEmpty()) {
    LOGGER.warn("No authentication event has been recorded; CAS cannot finalize the authentication result");
    return null;
  }
  val authenticationAttributes = new HashMap<String, Object>();
  val principalAttributes = new HashMap<String, Object>();
  val authenticationBuilder = DefaultAuthenticationBuilder.newInstance();
  buildAuthenticationHistory(this.authentications, authenticationAttributes, principalAttributes, authenticationBuilder);
  val primaryPrincipal = getPrimaryPrincipal(principalElectionStrategy, this.authentications, principalAttributes);
  authenticationBuilder.setPrincipal(primaryPrincipal);
  LOGGER.debug("Determined primary authentication principal to be [{}]", primaryPrincipal);
  authenticationBuilder.setAttributes(authenticationAttributes);
  LOGGER.trace("Collected authentication attributes for this result are [{}]", authenticationAttributes);
  authenticationBuilder.setAuthenticationDate(ZonedDateTime.now());
  val auth = authenticationBuilder.build();
  LOGGER.trace("Authentication result commenced at [{}]", auth.getAuthenticationDate());
  return auth;
}

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

@Override
  public boolean isSatisfiedBy(final Authentication authn, final Set<AuthenticationHandler> authenticationHandlers) throws Exception {
    if (this.tryAll) {
      val sum = authn.getSuccesses().size() + authn.getFailures().size();
      if (authn.getCredentials().size() != sum) {
        LOGGER.warn("Number of provided credentials [{}] does not match the sum of authentication successes and failures [{}]", authn.getCredentials().size(), sum);
        return false;
      }
      LOGGER.debug("Authentication policy is satisfied with all authentication transactions");
      return true;
    }
    if (!authn.getSuccesses().isEmpty()) {
      LOGGER.debug("Authentication policy is satisfied having found at least one authentication transactions");
      return true;
    }
    LOGGER.warn("Authentication policy has failed to find a successful authentication transaction");
    return false;
  }
}

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

/**
 * Locate matching credential type boolean.
 *
 * @param authentication      the authentication
 * @param credentialClassType the credential class type
 * @return the boolean
 */
protected boolean locateMatchingCredentialType(final Authentication authentication, final String credentialClassType) {
  return StringUtils.isNotBlank(credentialClassType) && authentication.getCredentials()
    .stream()
    .anyMatch(e -> e.getCredentialClass().getName().matches(credentialClassType));
}

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

private static void buildAuthenticationHistory(final Set<Authentication> authentications,
                        final Map<String, Object> authenticationAttributes,
                        final Map<String, Object> principalAttributes,
                        final AuthenticationBuilder authenticationBuilder) {
  LOGGER.trace("Collecting authentication history based on [{}] authentication events", authentications.size());
  authentications.forEach(authn -> {
    val authenticatedPrincipal = authn.getPrincipal();
    LOGGER.debug("Evaluating authentication principal [{}] for inclusion in result", authenticatedPrincipal);
    principalAttributes.putAll(CoreAuthenticationUtils.mergeAttributes(principalAttributes, authenticatedPrincipal.getAttributes()));
    LOGGER.debug("Collected principal attributes [{}] for inclusion in this result for principal [{}]",
      principalAttributes, authenticatedPrincipal.getId());
    authenticationAttributes.putAll(CoreAuthenticationUtils.mergeAttributes(authenticationAttributes, authn.getAttributes()));
    LOGGER.debug("Finalized authentication attributes [{}] for inclusion in this authentication result", authenticationAttributes);
    authenticationBuilder
      .addSuccesses(authn.getSuccesses())
      .addFailures(authn.getFailures())
      .addCredentials(authn.getCredentials());
  });
}

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

private Collection<MultifactorAuthenticationProvider> getSatisfiedAuthenticationProviders(final Authentication authentication,
                                               final Collection<MultifactorAuthenticationProvider> providers) {
    val contexts = CollectionUtils.toCollection(authentication.getAttributes().get(this.authenticationContextAttribute));
    if (contexts == null || contexts.isEmpty()) {
      LOGGER.debug("No authentication context could be determined based on authentication attribute [{}]", this.authenticationContextAttribute);
      return null;
    }
    return providers.stream()
            .filter(p -> contexts.contains(p.getId()))
            .collect(Collectors.toCollection(LinkedHashSet::new));
  }
}

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

val attrs = new LinkedHashMap<String, Object>(authentication.getAttributes());
attrs.keySet().removeAll(neverReleaseAttributes);
  attrs.put(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_AUTHENTICATION_DATE, CollectionUtils.wrap(authentication.getAuthenticationDate()));

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

@Override
public boolean isSatisfiedBy(final Authentication authn, final Set<AuthenticationHandler> authenticationHandlers) {
  var credsOk = true;
  val sum = authn.getSuccesses().size() + authn.getFailures().size();
  if (this.tryAll) {
    credsOk = authn.getCredentials().size() == sum;
      + "Successful authentication handlers are [{}]", authn.getCredentials().size(), sum, authn.getSuccesses().keySet());
    return false;
    credsOk = authn.getSuccesses().keySet()
      .stream()
      .anyMatch(s -> s.equalsIgnoreCase(this.requiredHandlerName));

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

/**
   * Gets principal from authentication.
   *
   * @param authentications the authentications
   * @return the principal from authentication
   */
  protected Principal getPrincipalFromAuthentication(final Collection<Authentication> authentications) {
    return authentications.iterator().next().getPrincipal();
  }
}

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

@Override
  protected InterruptResponse inquireInternal(final Authentication authentication, final RegisteredService registeredService,
                        final Service service, final Credential credential,
                        final RequestContext requestContext) {
    val attributes = new HashMap<String, Object>(authentication.getAttributes());
    attributes.putAll(authentication.getPrincipal().getAttributes());

    LOGGER.debug("Looking for [{}] in attributes [{}]", this.interruptAttributeName, attributes);
    val result = attributes.entrySet()
      .stream()
      .filter(entry -> entry.getKey().matches(this.interruptAttributeName))
      .filter(entry -> {
        val values = CollectionUtils.toCollection(entry.getValue());
        LOGGER.debug("Located attribute [{}] with values [{}]. Checking for match against [{}]",
          this.interruptAttributeName, values, this.interruptAttributeValue);
        return values.stream().anyMatch(value -> value.toString().matches(this.interruptAttributeValue));
      })
      .findAny();
    if (result.isPresent()) {
      return InterruptResponse.interrupt();
    }
    return InterruptResponse.none();
  }
}

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

.forEach(tgt -> {
  val authentication = tgt.getAuthentication();
  val principal = authentication.getPrincipal();
  val sso = new HashMap<String, Object>(SsoSessionAttributeKeys.values().length);
  sso.put(SsoSessionAttributeKeys.AUTHENTICATED_PRINCIPAL.toString(), principal.getId());
  sso.put(SsoSessionAttributeKeys.AUTHENTICATION_DATE.toString(), authentication.getAuthenticationDate());
  sso.put(SsoSessionAttributeKeys.AUTHENTICATION_DATE_FORMATTED.toString(),
    dateFormat.format(DateTimeUtils.dateOf(authentication.getAuthenticationDate())));
  sso.put(SsoSessionAttributeKeys.NUMBER_OF_USES.toString(), tgt.getCountOfUses());
  sso.put(SsoSessionAttributeKeys.TICKET_GRANTING_TICKET.toString(), tgt.getId());
  sso.put(SsoSessionAttributeKeys.PRINCIPAL_ATTRIBUTES.toString(), principal.getAttributes());
  sso.put(SsoSessionAttributeKeys.AUTHENTICATION_ATTRIBUTES.toString(), authentication.getAttributes());
  if (option != SsoSessionReportOptions.DIRECT) {
    if (tgt.getProxiedBy() != null) {

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

@Override
public String getPrincipalIdFrom(final Authentication authentication, final Object returnValue, final Exception exception) {
  if (authentication == null) {
    return Credential.UNKNOWN_ID;
  }
  if (supports(authentication, returnValue, exception)) {
    val attributes = authentication.getAttributes();
    val surrogateUser = attributes.get(SurrogateAuthenticationService.AUTHENTICATION_ATTR_SURROGATE_USER).toString();
    val principalId = attributes.get(SurrogateAuthenticationService.AUTHENTICATION_ATTR_SURROGATE_PRINCIPAL).toString();
    return String.format("(Primary User: [%s], Surrogate User: [%s])", principalId, surrogateUser);
  }
  return super.getPrincipalIdFrom(authentication, returnValue, exception);
}

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

final Collection<Object> authnMethods = CollectionUtils.toCollection(authentication.getAttributes()
  .get(SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD));
LOGGER.debug("Authentication methods found are [{}]", authnMethods);
  authentication.getAuthenticationDate(), authnMethods, principal.getId());
LOGGER.debug("Built authentication statement for [{}] dated at [{}]", principal, authentication.getAuthenticationDate());

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

private static Authentication evaluatePossibilityOfMixedPrincipals(final AuthenticationResult context, final TicketGrantingTicket ticketGrantingTicket) {
    if (context == null) {
      return null;
    }
    val currentAuthentication = context.getAuthentication();
    if (currentAuthentication != null) {
      val original = ticketGrantingTicket.getAuthentication();
      if (!currentAuthentication.getPrincipal().equals(original.getPrincipal())) {
        throw new MixedPrincipalException(currentAuthentication, currentAuthentication.getPrincipal(), original.getPrincipal());
      }
    }
    return currentAuthentication;
  }
}

相关文章