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


Java Principal.getAttributes方法代码示例

本文整理汇总了Java中org.jasig.cas.authentication.principal.Principal.getAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java Principal.getAttributes方法的具体用法?Java Principal.getAttributes怎么用?Java Principal.getAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jasig.cas.authentication.principal.Principal的用法示例。


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

示例1: convertPrincipalAttributesToPersonAttributes

import org.jasig.cas.authentication.principal.Principal; //导入方法依赖的package包/类
/***
 * Convert principal attributes to person attributes.
 * @param p  the principal carrying attributes
 * @return person attributes
 */
private Map<String, List<Object>> convertPrincipalAttributesToPersonAttributes(final Principal p) {
    final Map<String, List<Object>> convertedAttributes = new HashMap<>(p.getAttributes().size());
    final Map<String, Object> principalAttributes = p.getAttributes();

    for (final Map.Entry<String, Object> entry : principalAttributes.entrySet()) {
        final Object values = entry.getValue();
        final String key = entry.getKey();
        if (values instanceof List) {
            convertedAttributes.put(key, (List) values);
        } else {
            convertedAttributes.put(key, Collections.singletonList(values));
        }
    }
    return convertedAttributes;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:21,代码来源:AbstractPrincipalAttributesRepository.java

示例2: verify

import org.jasig.cas.authentication.principal.Principal; //导入方法依赖的package包/类
@Override
public boolean verify(final RequestContext requestContext, final Credential credential) {
    final Principal principal = getPrincipal(requestContext);
    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 true;
        }
    }

    logger.warn("Usage policy has not been accepted by {}", principal.getId());
    return false;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:18,代码来源:AbstractPrincipalAttributeAcceptableUsagePolicyRepository.java

示例3: getAttributes

import org.jasig.cas.authentication.principal.Principal; //导入方法依赖的package包/类
@Override
public final Map<String, Object> getAttributes(final Principal p) {
    final Map<String, Object> principalAttributes = this.principalAttributesRepository == null
            ? p.getAttributes() : this.principalAttributesRepository.getAttributes(p);
    final Map<String, Object> attributesToRelease = getAttributesInternal(principalAttributes);
    
    if (this.registeredServiceAttributeFilter != null) {
        return this.registeredServiceAttributeFilter.filter(attributesToRelease);
    }
    return attributesToRelease;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:12,代码来源:AbstractRegisteredServiceAttributeReleasePolicy.java

示例4: createAuthenticationSuccess

import org.jasig.cas.authentication.principal.Principal; //导入方法依赖的package包/类
private CasServiceResponseAuthenticationSuccess createAuthenticationSuccess(final Map<String, Object> model) {
    final CasServiceResponseAuthenticationSuccess success = new CasServiceResponseAuthenticationSuccess();

    final Authentication authentication = getPrimaryAuthenticationFrom(model);
    final Principal principal = getPrincipal(model);

    final Service service = getServiceFrom(model);
    final RegisteredService registeredService = this.servicesManager.findServiceBy(service);

    Map<String, Object> attributes = new HashMap<>(principal.getAttributes());
    decideIfCredentialPasswordShouldBeReleasedAsAttribute(attributes, model, registeredService);
    decideIfProxyGrantingTicketShouldBeReleasedAsAttribute(attributes, model, registeredService);

    attributes = this.casAttributeEncoder.encodeAttributes(attributes, getServiceFrom(model));
    if (!attributes.isEmpty()) {
        success.setAttributes(attributes);
    }
    success.setUser(principal.getId());

    attributes = new HashMap<>(authentication.getAttributes());
    decideIfCredentialPasswordShouldBeReleasedAsAttribute(attributes, model, registeredService);
    decideIfProxyGrantingTicketShouldBeReleasedAsAttribute(attributes, model, registeredService);
    attributes = this.casAttributeEncoder.encodeAttributes(attributes, getServiceFrom(model));

    if (!attributes.isEmpty()) {
        success.setAuthenticationAttributes(attributes);
    }

    final Collection<Authentication> chainedAuthentications = getChainedAuthentications(model);
    if (chainedAuthentications != null && !chainedAuthentications.isEmpty()) {
        final List<String> proxies = new ArrayList<>();
        for (final Authentication authn : chainedAuthentications) {
            proxies.add(authn.getPrincipal().getId());
        }
        success.setProxies(proxies);
    }
    return success;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:39,代码来源:Cas30JsonResponseView.java

示例5: resolveUsername

import org.jasig.cas.authentication.principal.Principal; //导入方法依赖的package包/类
@Override
public String resolveUsername(final Principal principal, final Service service) {
    String principalId = principal.getId();
    final Map<String, Object> originalPrincipalAttributes = principal.getAttributes();
    final Map<String, Object> attributes = getPrincipalAttributes(principal, service);

    if (attributes.containsKey(this.usernameAttribute)) {
        principalId = attributes.get(this.usernameAttribute).toString();
    } else if (originalPrincipalAttributes.containsKey(this.usernameAttribute)) {
        LOGGER.warn("The selected username attribute [{}] was retrieved as a direct "
                   + "principal attributes and not through the attribute release policy for service [{}]. "
                   + "CAS is unable to detect new attribute values for [{}] after authentication unless the attribute "
                   + "is explicitly authorized for release via the service attribute release policy.", 
                this.usernameAttribute, service, this.usernameAttribute);
        principalId = originalPrincipalAttributes.get(this.usernameAttribute).toString();
    } else {
        LOGGER.warn("Principal [{}] does not have an attribute [{}] among attributes [{}] so CAS cannot "
                + "provide the user attribute the service expects. "
                + "CAS will instead return the default principal id [{}]. Ensure the attribute selected as the username "
                + "is allowed to be released by the service attribute release policy.",
                principalId,
                this.usernameAttribute,
                attributes,
                principalId);
    }

    LOGGER.debug("Principal id to return for [{}] is [{}]. The default principal id is [{}].",
            service.getId(), principalId, principal.getId());
    return principalId;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:31,代码来源:PrincipalAttributeRegisteredServiceUsernameProvider.java

示例6: getPrincipalAttributes

import org.jasig.cas.authentication.principal.Principal; //导入方法依赖的package包/类
/**
 * Gets principal attributes. Will attempt to locate the principal
 * attribute repository from the context if one is defined to use
 * that instance to locate attributes. If none is available,
 * will use the default principal attributes.
 *
 * @param p       the principal
 * @param service the service
 * @return the principal attributes
 */
protected Map<String, Object> getPrincipalAttributes(final Principal p, final Service service) {
    final ApplicationContext context = ApplicationContextProvider.getApplicationContext();
    if (context != null) {
        LOGGER.debug("Located application context to locate the service registry entry");
        final ReloadableServicesManager servicesManager = context.getBean(ReloadableServicesManager.class);
        if (servicesManager != null) {
            final RegisteredService registeredService = servicesManager.findServiceBy(service);

            if (registeredService != null && registeredService.getAccessStrategy().isServiceAccessAllowed()) {
                LOGGER.debug("Located service {} in the registry. Attempting to resolve attributes for {}",
                        service.getId(), p.getId());

                if (registeredService.getAttributeReleasePolicy() == null) {
                    LOGGER.debug("No attribute release policy is defined for {}. Returning default principal attributes",
                            service.getId());
                    return p.getAttributes();
                }
                return registeredService.getAttributeReleasePolicy().getAttributes(p);
            }
        }

        LOGGER.debug("Could not locate service {} in the registry.", service.getId());
        throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE);
    }
    LOGGER.warn("No application context could be detected. Returning default principal attributes");
    return p.getAttributes();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:38,代码来源:PrincipalAttributeRegisteredServiceUsernameProvider.java

示例7: determinePrincipalIdForRegisteredService

import org.jasig.cas.authentication.principal.Principal; //导入方法依赖的package包/类
/**
 * Determines the principal id to use for a {@link RegisteredService} using the following rules:
 *
 * <ul>
 *  <li> If the service is marked to allow anonymous access, a persistent id is returned. </li>
 *  <li> If the {@link org.jasig.cas.services.RegisteredService#getUsernameAttribute()} is blank, then the default
 *  principal id is returned.</li>
 *  <li>If the username attribute is available as part of the principal's attributes,
 *  the corresponding attribute value will be returned.
 *  </li>
 *   <li>Otherwise, the default principal's id is returned as the username attribute
 *   with an additional warning.</li>
 * </ul>
 *
 * @param principal The principal object to be validated and constructed
 * @param registeredService Requesting service for which a principal is being validated.
 * @param serviceTicket An instance of the service ticket used for validation
 *
 * @return The principal id to use for the requesting registered service
 */
private String determinePrincipalIdForRegisteredService(final Principal principal,
                                                        final RegisteredService registeredService,
                                                        final ServiceTicket serviceTicket) {
    String principalId = null;
    final String serviceUsernameAttribute = registeredService.getUsernameAttribute();

    if (registeredService.isAnonymousAccess()) {
        principalId = this.persistentIdGenerator.generate(principal, serviceTicket.getService());
    } else if (StringUtils.isBlank(serviceUsernameAttribute)) {
        principalId = principal.getId();
    } else {
        if (principal.getAttributes().containsKey(serviceUsernameAttribute)) {
            principalId = principal.getAttributes().get(serviceUsernameAttribute).toString();
        } else {
            principalId = principal.getId();
            final Object[] errorLogParameters = new Object[] {
                    principalId,
                    registeredService.getUsernameAttribute(),
                    principal.getAttributes(),
                    registeredService.getServiceId(),
                    principalId };
            logger.warn("Principal [{}] did not have attribute [{}] among attributes [{}] so CAS cannot "
                    + "provide on the validation response the user attribute the registered service [{}] expects. "
                    + "CAS will instead return the default username attribute [{}]", errorLogParameters);
        }

    }

    logger.debug("Principal id to return for service [{}] is [{}]. The default principal id is [{}].",
            new Object[]{registeredService.getName(), principal.getId(), principalId});
    return principalId;
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:53,代码来源:CentralAuthenticationServiceImpl.java

示例8: getPrincipalAttributes

import org.jasig.cas.authentication.principal.Principal; //导入方法依赖的package包/类
/**
 * Gets principal attributes. Will attempt to locate the principal
 * attribute repository from the context if one is defined to use
 * that instance to locate attributes. If none is available,
 * will use the default principal attributes.
 *
 * @param p       the principal
 * @param service the service
 * @return the principal attributes
 */
protected Map<String, Object> getPrincipalAttributes(final Principal p, final Service service) {
    final ApplicationContext context = ApplicationContextProvider.getApplicationContext();
    if (context != null) {
        logger.debug("Located application context to locate the service registry entry");
        final ReloadableServicesManager servicesManager = context.getBean(ReloadableServicesManager.class);
        if (servicesManager != null) {
            final RegisteredService registeredService = servicesManager.findServiceBy(service);

            if (registeredService != null && registeredService.getAccessStrategy().isServiceAccessAllowed()) {
                logger.debug("Located service {} in the registry. Attempting to resolve attributes for {}",
                        service.getId(), p.getId());

                if (registeredService.getAttributeReleasePolicy() == null) {
                    logger.debug("No attribute release policy is defined for {}. Returning default principal attributes",
                            service.getId());
                    return p.getAttributes();
                }
                return registeredService.getAttributeReleasePolicy().getAttributes(p);
            }
        }

        logger.debug("Could not locate service {} in the registry.", service.getId());
        throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE);
    }
    logger.warn("No application context could be detected. Returning default principal attributes");
    return p.getAttributes();
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:38,代码来源:PrincipalAttributeRegisteredServiceUsernameProvider.java

示例9: getPrincipalAttributesFrom

import org.jasig.cas.authentication.principal.Principal; //导入方法依赖的package包/类
@Override
public Map<String, Object> getPrincipalAttributesFrom(final String ticketGrantingTicketId) throws RuntimeException {
    final Principal principal = getAuthenticatedPrincipalFrom(ticketGrantingTicketId);
    return principal == null ? null : principal.getAttributes();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:6,代码来源:DefaultTicketRegistrySupport.java

示例10: handleRequestInternal

import org.jasig.cas.authentication.principal.Principal; //导入方法依赖的package包/类
@Override
protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    String accessToken = request.getParameter(OAuthConstants.ACCESS_TOKEN);
    if (StringUtils.isBlank(accessToken)) {
        final String authHeader = request.getHeader("Authorization");
        if (StringUtils.isNotBlank(authHeader) 
                && authHeader.toLowerCase().startsWith(OAuthConstants.BEARER_TOKEN.toLowerCase() + ' ')) {
            accessToken = authHeader.substring(OAuthConstants.BEARER_TOKEN.length() + 1);
        }
    }
    LOGGER.debug("{} : {}", OAuthConstants.ACCESS_TOKEN, accessToken);

    try (final JsonGenerator jsonGenerator = this.jsonFactory.createJsonGenerator(response.getWriter())) {
        response.setContentType("application/json");
        // accessToken is required
        if (StringUtils.isBlank(accessToken)) {
            LOGGER.error("Missing {}", OAuthConstants.ACCESS_TOKEN);
            jsonGenerator.writeStartObject();
            jsonGenerator.writeStringField("error", OAuthConstants.MISSING_ACCESS_TOKEN);
            jsonGenerator.writeEndObject();
            return null;
        }
        // get ticket granting ticket
        final TicketGrantingTicket ticketGrantingTicket = (TicketGrantingTicket) this.ticketRegistry.getTicket(accessToken);
        if (ticketGrantingTicket == null || ticketGrantingTicket.isExpired()) {
            LOGGER.error("expired accessToken : {}", accessToken);
            jsonGenerator.writeStartObject();
            jsonGenerator.writeStringField("error", OAuthConstants.EXPIRED_ACCESS_TOKEN);
            jsonGenerator.writeEndObject();
            return null;
        }
        // generate profile : identifier + attributes
        final Principal principal = ticketGrantingTicket.getAuthentication().getPrincipal();
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField(ID, principal.getId());
        jsonGenerator.writeArrayFieldStart(ATTRIBUTES);
        final Map<String, Object> attributes = principal.getAttributes();
        for (final Map.Entry<String, Object> entry : attributes.entrySet()) {
            jsonGenerator.writeStartObject();
            jsonGenerator.writeObjectField(entry.getKey(), entry.getValue());
            jsonGenerator.writeEndObject();
        }
        jsonGenerator.writeEndArray();
        jsonGenerator.writeEndObject();
        return null;
    } finally {
        response.flushBuffer();
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:50,代码来源:OAuth20ProfileController.java

示例11: handleRequestInternal

import org.jasig.cas.authentication.principal.Principal; //导入方法依赖的package包/类
@Override
protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response)
        throws Exception {

    final String accessToken = request.getParameter(OAuthConstants.ACCESS_TOKEN);
    LOGGER.debug("{} : {}", OAuthConstants.ACCESS_TOKEN, accessToken);

    final JsonGenerator jsonGenerator = this.jsonFactory.createJsonGenerator(response.getWriter());

    try {
        response.setContentType("application/json");

        // accessToken is required
        if (StringUtils.isBlank(accessToken)) {
            LOGGER.error("Missing {}", OAuthConstants.ACCESS_TOKEN);
            jsonGenerator.writeStartObject();
            jsonGenerator.writeStringField("error", OAuthConstants.MISSING_ACCESS_TOKEN);
            jsonGenerator.writeEndObject();
            return null;
        }
        // get ticket granting ticket
        final TicketGrantingTicket ticketGrantingTicket = (TicketGrantingTicket) this.ticketRegistry
                .getTicket(accessToken);
        if (ticketGrantingTicket == null || ticketGrantingTicket.isExpired()) {
            LOGGER.error("expired accessToken : {}", accessToken);
            jsonGenerator.writeStartObject();
            jsonGenerator.writeStringField("error", OAuthConstants.EXPIRED_ACCESS_TOKEN);
            jsonGenerator.writeEndObject();
            return null;
        }
        // generate profile : identifier + attributes
        final Principal principal = ticketGrantingTicket.getAuthentication().getPrincipal();
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField(ID, principal.getId());
        jsonGenerator.writeArrayFieldStart(ATTRIBUTES);
        final Map<String, Object> attributes = principal.getAttributes();
        for (final String key : attributes.keySet()) {
            jsonGenerator.writeStartObject();
            jsonGenerator.writeObjectField(key, attributes.get(key));
            jsonGenerator.writeEndObject();
        }
        jsonGenerator.writeEndArray();
        jsonGenerator.writeEndObject();
        return null;
    } finally {
        IOUtils.closeQuietly(jsonGenerator);
        response.flushBuffer();
    }
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:50,代码来源:OAuth20ProfileController.java


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