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


Java JsonHelper.get方法代码示例

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


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

示例1: buildUserRoles

import org.pac4j.oauth.profile.JsonHelper; //导入方法依赖的package包/类
/**
 * Builds a list of Revenue Sharing roles according to the roles retrieved
 * from the idm and the email of the user
 * @param rolesNode, A JSON array containing the roles provided by the idm
 * @param email, Email of the user
 * @return List of revenue sharing roles
 */
public List<Role> buildUserRoles(ArrayNode rolesNode, String email) {
    List<Role> userRoles = new ArrayList<>();

    // Include idm defined roles
    for (JsonNode node : rolesNode) {
        Role r = new Role();
        String role = (String) JsonHelper.get(node, "name");

        r.setId((String) JsonHelper.get(node, "id"));
        r.setName(role.toLowerCase());
        userRoles.add(r);
    }

    // Check aggregator role
    if (this.aggregatorDao.getById(email) != null) {
        Role ag = new Role();
        ag.setId("0");
        ag.setName("aggregator");
        userRoles.add(ag);
    }

    return userRoles;
}
 
开发者ID:conwetlab,项目名称:fiware-rss,代码行数:31,代码来源:AuthUserManager.java

示例2: extractUserProfile

import org.pac4j.oauth.profile.JsonHelper; //导入方法依赖的package包/类
@Override
protected FIWAREProfile extractUserProfile(String body) {
    // Build new FIWARE User profile
    FIWAREProfile profile = new FIWAREProfile();
    if (body != null) {
        final JsonNode json = JsonHelper.getFirstNode(body);
        profile.setId(JsonHelper.get(json, "id"));

        for (final String attribute : new FIWAREAttributesDefinition().getPrincipalAttributes()) {
            Object value;
            // Populate user roles
            if (attribute.equalsIgnoreCase("roles")) {
                value = userManager.buildUserRoles(
                        (ArrayNode) JsonHelper.get(json, attribute),
                        (String) profile.getEmail());
            } else {
                value = JsonHelper.get(json, attribute);
            }
            profile.addAttribute(attribute, value);
        }
        profile.addRole("ROLE_USER");

        // User information should be stored in the local users table
        userManager.updateUser(profile);
    }

    return profile;
}
 
开发者ID:conwetlab,项目名称:fiware-rss,代码行数:29,代码来源:FIWAREClient.java

示例3: extractUserProfile

import org.pac4j.oauth.profile.JsonHelper; //导入方法依赖的package包/类
@Override
protected FIWAREProfile extractUserProfile(String body) {

	// The method is not executed when the body is null
	if (body == null) {
		return null;
	}

	FIWAREProfile profile = new FIWAREProfile();
	JsonNode json = JsonHelper.getFirstNode(body);
	
	// Profile ID is based on the ID given by the IdM
	profile.setId(JsonHelper.get(json, "id"));
	
	// Set the rest of attributes
	for (final String attribute : new FIWAREAttributesDefinition().getPrincipalAttributes()) {
		profile.addAttribute(attribute, JsonHelper.get(json, attribute));
	}

	// FIXME: By default, we are adding the default Role...
	profile.addRole("ROLE_USER");

	// Get profile parameters
	String username = (String) profile.getUsername();
	String email = (String) profile.getEmail();
	String displayName = (String) profile.getDisplayName();

	// Get current User since some default values will be required
	User user;

	try {
		// Modify the existing user
		user = userDao.findByName(username);
	} catch (UserNotFoundException e) {
		// Create a new user
		user = new User();
		user.setCreatedAt(new Date());
		user.setProvider(false);
	}

	// Determine if the user is a provider or not. Provider can only be updated when the user OAuth2 token
	// is valid for the Marketplace application. Otherwise, the provider status will be kept (based on its
	// previous value)
	String requestAppId = (String) JsonHelper.get(json, "app_id");
	ArrayNode roles = (ArrayNode) JsonHelper.get(json, "roles");
	boolean provider = user.isProvider();

	if (requestAppId.equals(key)) {

		boolean providerRoleFound = false;
		Iterator<JsonNode> iterator = roles.iterator();

		// Look for the provider role
		while (iterator.hasNext() && !providerRoleFound) {

			JsonNode role = iterator.next();
			if (role.get("name").asText().toLowerCase().equals(offeringProviderRole.toLowerCase())) {
				providerRoleFound = true;
			}
		}

		// Update provider status. The user will become provider if the provider role is found.
		// Otherwise, the user will become consumer.
		provider = providerRoleFound;
	}

	// Set field values
	user.setUserName(username);
	user.setDisplayName(displayName);
	user.setEmail(email);
	user.setPassword("");	// Password cannot be NULL
	user.setOauth2(true);
	user.setProvider(provider);

	// Create/Update the user with the new details obtained from the OAuth2 Server
	userDao.save(user);

	return profile;
}
 
开发者ID:conwetlab,项目名称:WMarket,代码行数:80,代码来源:FIWAREClient.java


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