org.apereo.cas.authentication.principal.Principal.getAttributes()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(109)

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

Principal.getAttributes介绍

暂无

代码示例

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

@Override
  protected Map<String, Object> getPrincipalAttributesForPrincipal(final Principal principal, final Map<String, Object> principalAttributes) {
    return principal.getAttributes();
  }
}

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

@Override
public Map<String, Object> getAttributes() {
  return surrogate.getAttributes();
}

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

@Override
protected Map<String, Object> getPrincipalAttributes(final Principal p) {
  val attributes = p.getAttributes();
  LOGGER.debug("[{}] will return the collection of attributes directly associated with the principal object which are [{}]",
    this.getClass().getSimpleName(), attributes);
  return attributes;
}

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

private static Optional<Object> getFirstAttributeByName(final Principal principal, final String attribute) {
  val value = principal.getAttributes().get(attribute);
  return CollectionUtils.firstElement(value);
}

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

@Override
public Map<String, Object> getPrincipalAttributesFrom(final String ticketGrantingTicketId) throws RuntimeException {
  val principal = getAuthenticatedPrincipalFrom(ticketGrantingTicketId);
  return principal == null ? null : principal.getAttributes();
}

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

/***
 * Convert principal attributes to person attributes.
 * @param p  the principal carrying attributes
 * @return person attributes
 */
private static Map<String, List<Object>> convertPrincipalAttributesToPersonAttributes(final Principal p) {
  val convertedAttributes = new TreeMap<String, List<Object>>(String.CASE_INSENSITIVE_ORDER);
  val principalAttributes = p.getAttributes();
  principalAttributes.forEach((key, values) -> {
    if (values instanceof List) {
      convertedAttributes.put(key, (List) values);
    } else {
      convertedAttributes.put(key, CollectionUtils.wrap(values));
    }
  });
  return convertedAttributes;
}

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

@Override
public Pair<Boolean, Principal> verify(final RequestContext requestContext, final Credential credential) {
  final Principal principal = WebUtils.getPrincipalFromRequestContext(requestContext, this.ticketRegistrySupport);
  final Map<String, Object> attributes = principal.getAttributes();
  LOGGER.debug("Principal attributes found for [{}] are [{}]", principal.getId(), attributes);
  if (attributes != null && attributes.containsKey(this.aupAttributeName)) {
    final Object value = attributes.get(this.aupAttributeName);
    LOGGER.debug("Evaluating attribute value [{}] found for [{}]", value, this.aupAttributeName);
    if (value.toString().equalsIgnoreCase(Boolean.TRUE.toString())) {
      return Pair.of(true, principal);
    }
  }
  LOGGER.warn("Usage policy has not been accepted by [{}]", principal.getId());
  return Pair.of(false, principal);
}

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

/**
   * Is usage policy accepted by user?
   * Looks into the attributes collected by the principal to find {@link #aupAttributeName}.
   * If the attribute contains {@code true}, then the policy is determined as accepted.
   *
   * @param principal the principal
   * @return true if accepted, false otherwise.
   */
  protected boolean isUsagePolicyAcceptedBy(final Principal principal) {
    val attributes = principal.getAttributes();
    LOGGER.debug("Principal attributes found for [{}] are [{}]", principal.getId(), attributes);

    if (attributes != null && attributes.containsKey(this.aupAttributeName)) {
      val value = CollectionUtils.toCollection(attributes.get(this.aupAttributeName));
      LOGGER.debug("Evaluating attribute value [{}] found for [{}]", value, this.aupAttributeName);
      return value.stream().anyMatch(v -> v.toString().equalsIgnoreCase(Boolean.TRUE.toString()));
    }
    return false;
  }
}

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

/**
 * Gets principal attributes.
 * Single-valued attributes are converted to a collection
 * so the review can easily loop through all.
 *
 * @param model the model
 * @return the attributes
 * @since 4.1.0
 */
protected Map<String, Object> getPrincipalAttributesAsMultiValuedAttributes(final Map<String, Object> model) {
  return CoreAuthenticationUtils.convertAttributeValuesToMultiValuedObjects(getPrincipal(model).getAttributes());
}

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

@Override
protected String resolveUsernameInternal(final Principal principal, final Service service, final RegisteredService registeredService) {
  try {
    LOGGER.debug("Found groovy script to execute");
    val result = ScriptingUtils.executeScriptEngine(this.script, new Object[]{principal.getAttributes(), principal.getId(), LOGGER}, Object.class);
    if (result != null) {
      LOGGER.debug("Found username [{}] from script [{}]", result, this.script);
      return result.toString();
    }
  } catch (final Exception e) {
    LOGGER.error(e.getMessage(), e);
  }
  LOGGER.warn("Script [{}] returned no value for username attribute. Fallback to default [{}]", this.script, principal.getId());
  return principal.getId();
}

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

/**
 * Sms.
 *
 * @param principal the principal
 * @param attribute the attribute
 * @param text      the text
 * @param from      the from
 * @return the boolean
 */
public boolean sms(final Principal principal,
          final String attribute,
          final String text, final String from) {
  if (StringUtils.isNotBlank(attribute) && principal.getAttributes().containsKey(attribute) && isSmsSenderDefined()) {
    val to = getFirstAttributeByName(principal, attribute);
    if (to.isPresent()) {
      return sms(from, to.get().toString(), text);
    }
  }
  LOGGER.debug("Phone attribute [{}] cannot be found or no configuration for sms provider is defined", attribute);
  return false;
}

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

@Override
public String generate(final Principal principal, final Service service) {
  val attributes = principal.getAttributes();
  LOGGER.debug("Found principal attributes [{}] to use when generating persistent identifiers", attributes);
  val principalId = FunctionUtils.doIf(
    StringUtils.isNotBlank(this.attribute) && attributes.containsKey(this.attribute),
    () -> {
      val attributeValue = attributes.get(this.attribute);
      LOGGER.debug("Using attribute [{}] to establish principal id", this.attribute);
      return CollectionUtils.firstElement(attributeValue).get().toString();
    },
    () -> {
      LOGGER.debug("Using principal id [{}] to generate persistent identifier", principal.getId());
      return principal.getId();
    }
  ).get();
  return generate(principalId, service != null ? service.getId() : null);
}

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

/**
 * Resolve attributes from principal attribute repository.
 *
 * @param principal the principal
 * @return the map
 */
protected Map<String, Object> resolveAttributesFromPrincipalAttributeRepository(final Principal principal) {
  val repository = ObjectUtils.defaultIfNull(this.principalAttributesRepository,
    getPrincipalAttributesRepositoryFromApplicationContext());
  if (repository != null) {
    LOGGER.debug("Using principal attribute repository [{}] to retrieve attributes", repository);
    return repository.getAttributes(principal);
  }
  return principal.getAttributes();
}

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

/**
 * Skip bypass and support event based on principal attributes.
 *
 * @param bypass    the bypass properties
 * @param principal the principal
 * @return the boolean
 */
protected boolean locateMatchingAttributeBasedOnPrincipalAttributes(
  final MultifactorAuthenticationProviderBypassProperties bypass, final Principal principal) {
  return locateMatchingAttributeValue(bypass.getPrincipalAttributeName(), bypass.getPrincipalAttributeValue(), principal.getAttributes());
}

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

/**
   * Resolve principal attributes map.
   *
   * @param uid the uid
   * @return the map
   */
  @ReadOperation
  public Map<String, Object> resolvePrincipalAttributes(@Selector final String uid) {
    val p = defaultPrincipalResolver.resolve(new BasicIdentifiableCredential(uid));
    val map = new HashMap<String, Object>();
    map.put("uid", p.getId());
    map.put("attributes", p.getAttributes());
    return map;
  }
}

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

private static Object getGroovyAttributeValue(final Principal principal, final String script) {
  val args = CollectionUtils.wrap("attributes", principal.getAttributes(), "id", principal.getId(), "logger", LOGGER);
  return ScriptingUtils.executeGroovyShellScript(script, (Map) args, Object.class);
}

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

@Override
@Audit(action = "OAUTH2_USER_PROFILE_DATA",
  actionResolverName = "OAUTH2_USER_PROFILE_DATA_ACTION_RESOLVER",
  resourceResolverName = "OAUTH2_USER_PROFILE_DATA_RESOURCE_RESOLVER")
public Map<String, Object> createFrom(final AccessToken accessToken, final J2EContext context) {
  val service = accessToken.getService();
  val registeredService = this.servicesManager.findServiceBy(service);
  val principal = getAccessTokenAuthenticationPrincipal(accessToken, context, registeredService);
  val map = new HashMap<String, Object>();
  map.put(OAuth20UserProfileViewRenderer.MODEL_ATTRIBUTE_ID, principal.getId());
  val attributes = principal.getAttributes();
  map.put(OAuth20UserProfileViewRenderer.MODEL_ATTRIBUTE_ATTRIBUTES, attributes);
  finalizeProfileResponse(accessToken, map, principal);
  return map;
}

代码示例来源: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-support-interrupt-core

@Override
  public InterruptResponse inquireInternal(final Authentication authentication,
                       final RegisteredService registeredService,
                       final Service service, final Credential credential,
                       final RequestContext requestContext) {
    if (ResourceUtils.doesResourceExist(watchableScript.getResource())) {
      val principal = authentication.getPrincipal();
      val attributes = new HashMap<String, Object>(principal.getAttributes());
      attributes.putAll(authentication.getAttributes());
      final Object[] args = {principal.getId(), attributes, service != null ? service.getId() : null, LOGGER};
      return watchableScript.execute(args, InterruptResponse.class);
    }
    return InterruptResponse.none();
  }
}

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

@Override
@SneakyThrows
public String build(final TicketGrantingTicket ticketGrantingTicket) {
  val authentication = ticketGrantingTicket.getAuthentication();
  val attributes = new HashMap<String, Object>(authentication.getAttributes());
  attributes.putAll(authentication.getPrincipal().getAttributes());
  val dt = ZonedDateTime.now().plusSeconds(expirationPolicy.getTimeToLive());
  val validUntilDate = DateTimeUtils.dateOf(dt);
  return buildJwt(ticketGrantingTicket.getId(),
    casSeverPrefix,
    DateTimeUtils.dateOf(ticketGrantingTicket.getCreationTime()),
    authentication.getPrincipal().getId(),
    validUntilDate,
    attributes);
}

相关文章

微信公众号

最新文章

更多