private void loadApplicationPermissions(
      String serviceProviderName, ServiceProvider serviceProvider)
      throws IdentityApplicationManagementException {
    List<ApplicationPermission> permissionList =
        ApplicationMgtUtil.loadPermissions(serviceProviderName);

    if (permissionList != null) {
      PermissionsAndRoleConfig permissionAndRoleConfig;
      if (serviceProvider.getPermissionAndRoleConfig() == null) {
        permissionAndRoleConfig = new PermissionsAndRoleConfig();
      } else {
        permissionAndRoleConfig = serviceProvider.getPermissionAndRoleConfig();
      }
      permissionAndRoleConfig.setPermissions(
          permissionList.toArray(new ApplicationPermission[permissionList.size()]));
      serviceProvider.setPermissionAndRoleConfig(permissionAndRoleConfig);
    }
  }
  /** @param identityProvider */
  public ExternalIdPConfig(IdentityProvider identityProvider) {
    this.identityProvider = identityProvider;

    claimConfiguration = identityProvider.getClaimConfig();
    roleConfiguration = identityProvider.getPermissionAndRoleConfig();
    justInTimeProConfig = identityProvider.getJustInTimeProvisioningConfig();

    RoleMapping[] mappings = roleConfiguration.getRoleMappings();

    if (mappings != null && mappings.length > 0) {
      for (RoleMapping roleMapping : mappings) {
        this.roleMappings.put(
            roleMapping.getRemoteRole(), roleMapping.getLocalRole().getLocalRoleName());
      }
    }
  }
 /** @return */
 public String[] getRoles() {
   if (roleConfiguration != null) {
     return roleConfiguration.getIdpRoles();
   }
   return new String[0];
 }