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


Java Pair类代码示例

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


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

示例1: convertPersonAttributesToPrincipal

import org.jasig.cas.util.Pair; //导入依赖的package包/类
/**
 * Convert person attributes to principal pair.
 *
 * @param extractedPrincipalId the extracted principal id
 * @param attributes           the attributes
 * @return the pair
 */
protected Pair<String, Map<String, Object>> convertPersonAttributesToPrincipal(final String extractedPrincipalId,
                                                                               final Map<String, List<Object>> attributes) {
    final Map<String, Object> convertedAttributes = new HashMap<>();
    String principalId = extractedPrincipalId;
    for (final Map.Entry<String, List<Object>> entry : attributes.entrySet()) {
        final String key = entry.getKey();
        final List<Object> values = entry.getValue();
        if (StringUtils.isNotBlank(this.principalAttributeName)
                && key.equalsIgnoreCase(this.principalAttributeName)) {
            if (values.isEmpty()) {
                logger.debug("{} is empty, using {} for principal", this.principalAttributeName, extractedPrincipalId);
            } else {
                principalId = values.get(0).toString();
                logger.debug(
                        "Found principal attribute value {}; removing {} from attribute map.",
                        extractedPrincipalId,
                        this.principalAttributeName);
            }
        } else {
            convertedAttributes.put(key, values.size() == 1 ? values.get(0) : values);
        }
    }

    return new Pair<>(principalId, convertedAttributes);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:33,代码来源:PersonDirectoryPrincipalResolver.java

示例2: resolve

import org.jasig.cas.util.Pair; //导入依赖的package包/类
@Override
public Principal resolve(final Credential credential) {
    logger.debug("Attempting to resolve a principal...");

    final String principalId = extractPrincipalId(credential);

    if (principalId == null) {
        logger.debug("Got null for extracted principal ID; returning null.");
        return null;
    }

    logger.debug("Creating SimplePrincipal for [{}]", principalId);

    final Map<String, List<Object>> attributes = retrievePersonAttributes(principalId);

    if (attributes == null || attributes.isEmpty()) {
        if (!this.returnNullIfNoAttributes) {
            return this.principalFactory.createPrincipal(principalId);
        }
        return null;
    }


    final Pair<String, Map<String, Object>> pair = convertPersonAttributesToPrincipal(principalId, attributes);
    return this.principalFactory.createPrincipal(pair.getFirst(), pair.getSecond());
}
 
开发者ID:xuchengdong,项目名称:cas4.1.9,代码行数:27,代码来源:PersonDirectoryPrincipalResolver.java

示例3: convertPersonAttributesToPrincipal

import org.jasig.cas.util.Pair; //导入依赖的package包/类
/**
 * Convert person attributes to principal pair.
 *
 * @param extractedPrincipalId the extracted principal id
 * @param attributes           the attributes
 * @return the pair
 */
protected Pair<String, Map<String, Object>> convertPersonAttributesToPrincipal(final String extractedPrincipalId,
                                                                               final Map<String, List<Object>> attributes) {
    final Map<String, Object> convertedAttributes = new HashMap<>();
    String principalId = extractedPrincipalId;
    for (final Map.Entry<String, List<Object>> entry : attributes.entrySet()) {
        final String key = entry.getKey();
        final List<Object> values = entry.getValue();
        if (key.equalsIgnoreCase(this.principalAttributeName)) {
            if (values.isEmpty()) {
                logger.debug("{} is empty, using {} for principal", this.principalAttributeName, extractedPrincipalId);
            } else {
                principalId = values.get(0).toString();
                logger.debug(
                        "Found principal attribute value {}; removing {} from attribute map.",
                        extractedPrincipalId,
                        this.principalAttributeName);
            }
        } else {
            convertedAttributes.put(key, values.size() == 1 ? values.get(0) : values);
        }
    }

    return new Pair<>(principalId, convertedAttributes);
}
 
开发者ID:xuchengdong,项目名称:cas4.1.9,代码行数:32,代码来源:PersonDirectoryPrincipalResolver.java

示例4: resolve

import org.jasig.cas.util.Pair; //导入依赖的package包/类
@Override
public Principal resolve(final Credential credential) {
    logger.debug("Attempting to resolve a principal...");

    final String principalId = extractPrincipalId(credential);

    if (principalId == null) {
        logger.debug("Got null for extracted principal ID; returning null.");
        return null;
    }

    logger.debug("Creating SimplePrincipal for [{}]", principalId);

    final Map<String, List<Object>> attributes = retrievePersonAttributes(principalId, credential);

    if (attributes == null || attributes.isEmpty()) {
        logger.debug("Principal id [{}] did not specify any attributes", principalId);

        if (!this.returnNullIfNoAttributes) {
            logger.debug("Returning the principal with id [{}] without any attributes", principalId);
            return this.principalFactory.createPrincipal(principalId);
        }
        logger.debug("[{}] is configured to return null if no attributes are found for [{}]",
                this.getClass().getName(), principalId);
        return null;
    }
    logger.debug("Retrieved [{}] attribute(s) from the repository", attributes.size());


    final Pair<String, Map<String, Object>> pair = convertPersonAttributesToPrincipal(principalId, attributes);
    return this.principalFactory.createPrincipal(pair.getFirst(), pair.getSecond());
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:33,代码来源:PersonDirectoryPrincipalResolver.java

示例5: verifyRegisteredService

import org.jasig.cas.util.Pair; //导入依赖的package包/类
private RegisteredService verifyRegisteredService(final JsonGenerator jsonGenerator, final Pair<String, Service> pair)
        throws IOException {
    final RegisteredService service = this.servicesManager.findServiceBy(Long.parseLong(pair.getSecond().getId()));
    if (service == null || !service.getAccessStrategy().isServiceAccessAllowed()) {
        logger.warn("Service {}] is not found in the registry or it is disabled.", service);
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField("error", OAuthConstants.INVALID_REQUEST);
        jsonGenerator.writeEndObject();
        return null;
    }
    return service;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:13,代码来源:OAuth20ProfileController.java

示例6: degenerate

import org.jasig.cas.util.Pair; //导入依赖的package包/类
@Override
public Pair<String, Service> degenerate(final String accessTokenInput) {
    final String accessTokenEncoded = new String(CompressionUtils.decodeBase64(accessTokenInput));
    final String[] token = accessTokenEncoded.split(UserProfile.SEPARATOR);
    if (token.length == 2) {
        return new Pair(token[0], this.webApplicationServiceFactory.createService(token[1]));
    }
    throw new IllegalArgumentException("Access token received must include both the id and the requesting service");
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:10,代码来源:DefaultAccessTokenGenerator.java

示例7: resolve

import org.jasig.cas.util.Pair; //导入依赖的package包/类
@Override
public Principal resolve(final Credential credential) {
    logger.debug("Attempting to resolve a principal...");

    final String principalId = extractPrincipalId(credential);

    if (principalId == null) {
        logger.debug("Got null for extracted principal ID; returning null.");
        return null;
    }

    logger.debug("Creating SimplePrincipal for [{}]", principalId);

    final Map<String, List<Object>> attributes = retrievePersonAttributes(principalId, credential);
    logger.debug("Principal id [{}] could not be found", principalId);

    if (attributes == null || attributes.isEmpty()) {
        logger.debug("Principal id [{}] did not specify any attributes", principalId);

        if (!this.returnNullIfNoAttributes) {
            logger.debug("Returning the principal with id [{}] without any attributes", principalId);
            return this.principalFactory.createPrincipal(principalId);
        }
        logger.debug("[{}] is configured to return null if no attributes are found for [{}]",
                this.getClass().getName(), principalId);
        return null;
    }
    logger.debug("Retrieved [{}] attribute(s) from the repository", attributes.size());


    final Pair<String, Map<String, Object>> pair = convertPersonAttributesToPrincipal(principalId, attributes);
    return this.principalFactory.createPrincipal(pair.getFirst(), pair.getSecond());
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:34,代码来源:PersonDirectoryPrincipalResolver.java

示例8: internalHandleRequest

import org.jasig.cas.util.Pair; //导入依赖的package包/类
@Override
protected ModelAndView internalHandleRequest(final String method, final HttpServletRequest request,
                                             final HttpServletResponse response) throws Exception {

    String accessToken = request.getParameter(OAuthConstants.ACCESS_TOKEN);
    if (StringUtils.isBlank(accessToken)) {
        final String authHeader = request.getHeader(HttpConstants.AUTHORIZATION_HEADER);
        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;
        }
        try {
            final Pair<String, Service> pair = this.accessTokenGenerator.degenerate(accessToken);
            accessToken = pair.getFirst();

            final TicketGrantingTicket ticketGrantingTicket = verifyAccessToken(accessToken, jsonGenerator);
            if (ticketGrantingTicket == null) {
                return null;
            }

            final RegisteredService service = verifyRegisteredService(jsonGenerator, pair);
            if (service == null) {
                return null;
            }

            final Principal principal = ticketGrantingTicket.getAuthentication().getPrincipal();
            if (!verifyPrincipalServiceAccess(jsonGenerator, service, principal)) {
                return null;
            }

            writeOutProfileResponse(jsonGenerator, service, principal);
        } catch (final Exception e) {
            jsonGenerator.writeStartObject();
            jsonGenerator.writeStringField("error", OAuthConstants.INVALID_REQUEST + ". " + e.getMessage());
            jsonGenerator.writeEndObject();
        }
        return null;
    } finally {
        response.flushBuffer();
    }
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:55,代码来源:OAuth20ProfileController.java

示例9: internalHandleRequest

import org.jasig.cas.util.Pair; //导入依赖的package包/类
@Override
protected ModelAndView internalHandleRequest(final String method, final HttpServletRequest request,
                                             final HttpServletResponse response) throws Exception {

    String accessToken = request.getParameter(OAuthConstants.ACCESS_TOKEN);
    if (StringUtils.isBlank(accessToken)) {
        final String authHeader = request.getHeader(HttpConstants.AUTHORIZATION_HEADER);
        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 (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;
        }
        try {
            final Pair<String, Service> pair = this.accessTokenGenerator.degenerate(accessToken);
            accessToken = pair.getFirst();

            final TicketGrantingTicket ticketGrantingTicket = verifyAccessToken(accessToken, jsonGenerator);
            if (ticketGrantingTicket == null) {
                return null;
            }

            final RegisteredService service = verifyRegisteredService(jsonGenerator, pair);
            if (service == null) {
                return null;
            }

            final Principal principal = ticketGrantingTicket.getAuthentication().getPrincipal();
            if (!verifyPrincipalServiceAccess(jsonGenerator, service, principal)) {
                return null;
            }

            writeOutProfileResponse(jsonGenerator, service, principal);
        } catch (final Exception e) {
            jsonGenerator.writeStartObject();
            jsonGenerator.writeStringField("error", OAuthConstants.INVALID_REQUEST + ". " + e.getMessage());
            jsonGenerator.writeEndObject();
        }
        return null;
    } finally {
        response.flushBuffer();
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:55,代码来源:OAuth20ProfileController.java

示例10: degenerate

import org.jasig.cas.util.Pair; //导入依赖的package包/类
/**
 * Degenerate an access token received from the client and
 * translates it to something CAS can understand as an access token.
 *
 * @param accessTokenInput the access token input
 * @return the parsed token
 */
Pair<String, Service> degenerate(String accessTokenInput);
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:9,代码来源:AccessTokenGenerator.java


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