當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。