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


Java BasicLTIUtil类代码示例

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


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

示例1: validateParams

import org.imsglobal.basiclti.BasicLTIUtil; //导入依赖的package包/类
/**
	 * Ensure that this is a proper lti request and it is authorized
	 * @param payload Map of the request parameters
	 * @param application
	 * @param outTrace
	 * @throws LTIException
	 */
	protected static void validateParams(Map<String, Object> payload, ServletContext application, StringBuffer outTrace) throws LTIException {


        //check parameters
        String lti_message_type = (String) payload.get(BasicLTIConstants.LTI_MESSAGE_TYPE);
//        String lti_version = (String) payload.get(BasicLTIConstants.LTI_VERSION);
        String oauth_consumer_key = (String) payload.get(LTIServletUtils.OAUTH_CONSUMER_KEY);
        String user_id = (String) payload.get(BasicLTIConstants.USER_ID);
//        String context_id = (String) payload.get(BasicLTIConstants.CONTEXT_ID);

        outTrace.append("\nHere I am!");
        if(!BasicLTIUtil.equals(lti_message_type, "basic-lti-launch-request")) {
            throw new LTIException("launch.invalid", "lti_message_type="+lti_message_type, null);
        }

//        if(!BasicLTIUtil.equals(lti_version, "LTI-1p0")) {
//            throw new LTIException( "launch.invalid", "lti_version="+lti_version, null);
//        }

        if(BasicLTIUtil.isBlank(oauth_consumer_key)) {
            throw new LTIException( "launch.missing", "oauth_consumer_key", null);
        }

        if(BasicLTIUtil.isBlank(user_id)) {
            throw new LTIException( "launch.missing", "user_id", null);
        }
        outTrace.append("user_id=" + user_id);

        // Lookup the secret
        //TODO: Maybe put this in a db table for scalability?
        final String configPrefix = "basiclti.provider." + oauth_consumer_key + ".";
        final String oauth_secret = (String)application.getAttribute(configPrefix+ "secret");
        //final String oauth_secret = ServerConfigurationService.getString(configPrefix+ "secret", null);
        if (oauth_secret == null) {
            throw new LTIException( "launch.key.notfound",oauth_consumer_key, null);
        }
    }
 
开发者ID:karutaproject,项目名称:karuta-backend,代码行数:45,代码来源:LTIServletUtils.java

示例2: doBasicLTI

import org.imsglobal.basiclti.BasicLTIUtil; //导入依赖的package包/类
private void doBasicLTI(final UserRequest ureq) {
    run = createVelocityContainer("run");

    // push title and learning objectives, only visible on intro page
    run.contextPut("menuTitle", courseNode.getShortTitle());
    run.contextPut("displayTitle", courseNode.getLongTitle());

    // put url in template to show content on extern page
    URL url = null;
    try {
        url = new URL((String) config.get(LTIConfigForm.CONFIGKEY_PROTO), (String) config.get(LTIConfigForm.CONFIGKEY_HOST),
                ((Integer) config.get(LTIConfigForm.CONFIGKEY_PORT)).intValue(), (String) config.get(LTIConfigForm.CONFIGKEY_URI));
    } catch (final MalformedURLException e) {
        // this should not happen since the url was already validated in edit mode
        run.contextPut("url", "");
    }
    if (url != null) {
        final StringBuilder sb = new StringBuilder(128);
        sb.append(url.toString());
        // since the url only includes the path, but not the query (?...), append
        // it here, if any
        final String query = (String) config.get(LTIConfigForm.CONFIGKEY_QUERY);
        if (query != null) {
            sb.append("?");
            sb.append(query);
        }
        run.contextPut("url", sb.toString());

        final String key = (String) config.get(LTIConfigForm.CONFIGKEY_KEY);
        final String pass = (String) config.get(LTIConfigForm.CONFIGKEY_PASS);
        final String debug = (String) config.get(LTIConfigForm.CONFIG_KEY_DEBUG);

        talkbackMapper = new Mapper() {

            @Override
            public MediaResource handle(final String relPath, final HttpServletRequest request) {
                /**
                 * this is the place for error handling coming from the LTI tool, depending on error state may present some information for the user or just add some
                 * information to the olat.log file
                 */
                final StringMediaResource mediares = new StringMediaResource();
                final StringBuilder sb = new StringBuilder();
                sb.append("lti_msg: ").append(request.getParameter("lti_msg")).append("<br/>");
                sb.append("lti_errormsg: ").append(request.getParameter("lti_errormsg")).append("<br/>");
                sb.append("lti_log: ").append(request.getParameter("lti_log")).append("<br/>");
                sb.append("lti_errorlog: ").append(request.getParameter("lti_errorlog")).append("<br/>");
                mediares.setData("<html><body>" + sb.toString() + "</body></html>");
                mediares.setContentType("text/html");
                mediares.setEncoding("UTF-8");
                return mediares;
            }
        };
        final String backMapperUrl = registerMapper(talkbackMapper);

        final String serverUri = ureq.getHttpReq().getScheme() + "://" + ureq.getHttpReq().getServerName() + ":" + ureq.getHttpReq().getServerPort();

        Properties props = LTIProperties(ureq);
        setProperty(props, "launch_presentation_return_url", serverUri + backMapperUrl + "/");
        props = BasicLTIUtil.signProperties(props, sb.toString(), "POST", key, pass, null, null, null);

        postData = BasicLTIUtil.postLaunchHTML(props, sb.toString(), "true".equals(debug));

        contentMapper = new Mapper() {
            @Override
            public MediaResource handle(final String relPath, final HttpServletRequest request) {
                final StringMediaResource mediares = new StringMediaResource();
                mediares.setData(postData);
                mediares.setContentType("text/html");
                mediares.setEncoding("UTF-8");
                return mediares;
            }

        };
        log.debug("Basic LTI Post data: " + postData, null);

    }
    final String mapperUri = registerMapper(contentMapper);
    run.contextPut("mapperUri", mapperUri + "/");

    main.setContent(run);
}
 
开发者ID:huihoo,项目名称:olat,代码行数:82,代码来源:LTIRunController.java

示例3: LTIProperties

import org.imsglobal.basiclti.BasicLTIUtil; //导入依赖的package包/类
private Properties LTIProperties(final UserRequest ureq) {
    final Identity ident = ureq.getIdentity();
    final Locale loc = ureq.getLocale();
    final User u = ident.getUser();
    final String lastName = getUserService().getUserProperty(u, UserConstants.LASTNAME, loc);
    final String firstName = getUserService().getUserProperty(u, UserConstants.FIRSTNAME, loc);
    final String email = getUserService().getUserProperty(u, UserConstants.EMAIL, loc);

    final String custom = (String) config.get(LTIConfigForm.CONFIG_KEY_CUSTOM);
    final boolean sendname = Boolean.valueOf((String) config.get(LTIConfigForm.CONFIG_KEY_SENDNAME));
    final boolean sendemail = Boolean.valueOf((String) config.get(LTIConfigForm.CONFIG_KEY_SENDEMAIL));

    final Properties props = new Properties();
    setProperty(props, "resource_link_id", courseNode.getIdent());
    setProperty(props, "resource_link_title", courseNode.getShortTitle());
    setProperty(props, "resource_link_description", courseNode.getLongTitle());
    setProperty(props, "user_id", u.getKey() + "");
    setProperty(props, "launch_presentation_locale", loc.toString());
    setProperty(props, "launch_presentation_document_target", "iframe");

    if (sendname) {
        setProperty(props, "lis_person_name_given", firstName);
        setProperty(props, "lis_person_name_family", lastName);
        setProperty(props, "lis_person_name_full", firstName + " " + lastName);
    }
    if (sendemail) {
        setProperty(props, "lis_person_contact_email_primary", email);
    }

    setProperty(props, "roles", setRoles(ureq.getUserSession().getRoles()));
    setProperty(props, "context_id", courseEnv.getCourseResourceableId().toString());
    setProperty(props, "context_label", courseEnv.getCourseTitle());
    setProperty(props, "context_title", courseEnv.getCourseTitle());
    setProperty(props, "context_type", "CourseSection");

    // Pull in and parse the custom parameters
    // Note to Chuck - move this into BasicLTI Util
    if (custom != null) {
        final String[] params = custom.split("[\n;]");
        for (int i = 0; i < params.length; i++) {
            final String param = params[i];
            if (param == null) {
                continue;
            }
            if (param.length() < 1) {
                continue;
            }
            final int pos = param.indexOf("=");
            if (pos < 1) {
                continue;
            }
            if (pos + 1 > param.length()) {
                continue;
            }
            final String key = BasicLTIUtil.mapKeyName(param.substring(0, pos));
            if (key == null) {
                continue;
            }
            String value = param.substring(pos + 1);
            value = value.trim();
            if (value.length() < 1) {
                continue;
            }
            if (value == null) {
                continue;
            }
            setProperty(props, "custom_" + key, value);
        }
    }

    setProperty(props, "tool_consumer_instance_guid", Settings.getServerconfig("server_fqdn"));
    setProperty(props, "tool_consumer_instance_name", WebappHelper.getInstanceId());
    setProperty(props, "tool_consumer_instance_contact_email", WebappHelper.getMailConfig("mailSupport"));

    return props;
}
 
开发者ID:huihoo,项目名称:olat,代码行数:77,代码来源:LTIRunController.java


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