⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 openidextension.java

📁 开源的OpenId的一个java实现
💻 JAVA
字号:
/*
 * Copyright 2005-2008 WSO2, Inc. (http://wso2.com) Licensed under the Apache
 * License, Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
 * or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

package org.wso2.solutions.identity.openid.extensions;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.openid4java.message.MessageExtension;
import org.wso2.solutions.identity.IdentityConstants;
import org.wso2.solutions.identity.IdentityProviderException;
import org.wso2.solutions.identity.UserStore;
import org.wso2.solutions.identity.openid.OpenIDClaim;
import org.wso2.solutions.identity.persistence.dataobject.ClaimDO;

public abstract class OpenIDExtension {

    /**
     * Creates an instance of MessageExtension for the OpenID authentication
     * response
     * @param request OpenID authentication request
     * @return An instance of MessageExtension
     * @throws RelyingPartyException
     */
    public abstract MessageExtension getMessageExtension(String userId,
            String profileName) throws IdentityProviderException;

    /**
     * 
     * @param requiredAttributes
     * @throws IdentityProviderException
     */
    public abstract void addRequiredAttributes(List<String> requiredAttributes)
            throws IdentityProviderException;

    protected void mapToAttriId(Collection<String> requiredClaims,
            List<String> requiredAttributes, Map<String, ClaimDO> claims) {

        Iterator<String> iterator = null;
        // Get the column names for the URIs
        iterator = requiredClaims.iterator();

        String tag = null;
        ClaimDO claim = null;

        // First we need to figure-out which attributes we need to retrieve from
        // the user store.
        while (iterator.hasNext()) {
            tag = (String) iterator.next();
            claim = (ClaimDO) claims.get(tag);
            if (claim != null
                    && !claim.getUri().equals(IdentityConstants.CLAIM_PPID)) {
                if (claim.isSupported())
                    requiredAttributes.add(claim.getAttrId());
            }
        }
    }

    /**
     * Populate the required claims with claim values.
     * @param requiredClaims Required claims as requested by the RP.
     * @param userId User ID.
     * @return A map, populated with ClaimDO objects which have OpenIDTag, that
     *         is OpenID supported claims.
     * @throws IdentityProviderException
     */
    protected Map<String, OpenIDClaim> populateAttributeValues(
            Collection<String> requiredClaims, String userId,
            Map<String, ClaimDO> claims, Map<String, String> openIDTagMapping,
            String profileName) throws IdentityProviderException {

        UserStore connector = null;
        Map<String, OpenIDClaim> claimValues = null;
        Iterator<String> iterator = null;
        List<String> list = null;

        if (claims == null || claims.isEmpty())
            return null;

        connector = UserStore.getInstance();

        // Get the column names for the URIs
        iterator = requiredClaims.iterator();
        list = new ArrayList<String>();

        String tag = null;
        ClaimDO claim = null;

        // First we need to figure-out which attributes we need to retrieve from
        // the user store.
        while (iterator.hasNext()) {
            tag = (String) iterator.next();
            claim = (ClaimDO) claims.get(tag);
            if (claim != null
                    && !claim.getUri().equals(IdentityConstants.CLAIM_PPID)) {
                if (claim.isSupported())
                    list.add(claim.getAttrId());
            }
        }

        Map<String, String> mapValues = null;
        OpenIDClaim openIDClaim = null;
        String profile = null;

        if (profileName == null)
            profile = IdentityConstants.DEFAULT_PROFILE;
        else
            profile = profileName;

        // Get the claims values corresponding to the user from the user store.
        mapValues = connector.getClaimValues(userId, profile, list);

        claimValues = new HashMap<String, OpenIDClaim>();

        iterator = requiredClaims.iterator();

        // Iterate through the claim values retrieved and requestedClaims will
        // be populated with the corresponding values.
        while (iterator.hasNext()) {
            tag = iterator.next();
            claim = claims.get(tag);
            if (claim != null && claim.isSupported()) {
                openIDClaim = new OpenIDClaim();
                openIDClaim.setClaimValue(mapValues.get(claim.getAttrId()));
                openIDClaim.setTypeUri(claim.getUri());
                if (openIDTagMapping != null)
                    openIDClaim.setOpenIDTag(openIDTagMapping.get(claim
                            .getOpenIDTag()));
                else
                    openIDClaim.setOpenIDTag(claim.getOpenIDTag());
                if (openIDClaim.getClaimValue() != null)
                    claimValues.put(openIDClaim.getTypeUri(), openIDClaim);
            }
        }

        return claimValues;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -