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


Java RESTController类代码示例

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


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

示例1: authenticate

import net.sourceforge.subsonic.controller.RESTController; //导入依赖的package包/类
private RESTController.ErrorCode authenticate(String username, String password, Authentication previousAuth) {

        // Previously authenticated and username not overridden?
        if (username == null && previousAuth != null) {
            return null;
        }

        // Ensure password is given.
        if (password == null) {
            return RESTController.ErrorCode.MISSING_PARAMETER;
        }

        try {
            UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
            Authentication authResult = authenticationManager.authenticate(authRequest);
            SecurityContextHolder.getContext().setAuthentication(authResult);
//            LOG.info("Authentication succeeded for user " + username);
        } catch (AuthenticationException x) {
            LOG.info("Authentication failed for user " + username);
            return RESTController.ErrorCode.NOT_AUTHENTICATED;
        }
        return null;
    }
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:24,代码来源:RESTRequestParameterProcessingFilter.java

示例2: handleException

import net.sourceforge.subsonic.controller.RESTController; //导入依赖的package包/类
private void handleException(Throwable x, HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (x instanceof NestedServletException && x.getCause() != null) {
        x = x.getCause();
    }

    RESTController.ErrorCode code = (x instanceof ServletRequestBindingException) ? MISSING_PARAMETER : GENERIC;
    String msg = getErrorMessage(x);
    
    if (msg.contentEquals("EofException")) {
        LOG.warn("Error in REST API: broken Stream");
    }
    else
    {
        LOG.warn("Error in REST API: " + msg, x);
        RESTController.error(request, response, code, msg);
    }
    
}
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:19,代码来源:RESTFilter.java

示例3: checkAPIVersion

import net.sourceforge.subsonic.controller.RESTController; //导入依赖的package包/类
private RESTController.ErrorCode checkAPIVersion(String version) {
    Version serverVersion = new Version(jaxbWriter.getRestProtocolVersion());
    Version clientVersion = new Version(version);

    if (serverVersion.getMajor() > clientVersion.getMajor()) {
        return RESTController.ErrorCode.PROTOCOL_MISMATCH_CLIENT_TOO_OLD;
    } else if (serverVersion.getMajor() < clientVersion.getMajor()) {
        return RESTController.ErrorCode.PROTOCOL_MISMATCH_SERVER_TOO_OLD;
    } else if (serverVersion.getMinor() < clientVersion.getMinor()) {
        return RESTController.ErrorCode.PROTOCOL_MISMATCH_SERVER_TOO_OLD;
    }
    return null;
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:14,代码来源:RESTRequestParameterProcessingFilter.java

示例4: authenticate

import net.sourceforge.subsonic.controller.RESTController; //导入依赖的package包/类
private RESTController.ErrorCode authenticate(String username, String password, String salt, String token, Authentication previousAuth) {

        // Previously authenticated and username not overridden?
        if (username == null && previousAuth != null) {
            return null;
        }

        if (salt != null && token != null) {
            User user = securityService.getUserByName(username);
            if (user == null) {
                return RESTController.ErrorCode.NOT_AUTHENTICATED;
            }
            String expectedToken = DigestUtils.md5Hex(user.getPassword() + salt);
            if (!expectedToken.equals(token)) {
                return RESTController.ErrorCode.NOT_AUTHENTICATED;
            }

            password = user.getPassword();
        }

        if (password != null) {
            try {
                UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
                Authentication authResult = authenticationManager.authenticate(authRequest);
                SecurityContextHolder.getContext().setAuthentication(authResult);
                return null;
            } catch (AuthenticationException x) {
                return RESTController.ErrorCode.NOT_AUTHENTICATED;
            }
        }

        return RESTController.ErrorCode.MISSING_PARAMETER;
    }
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:34,代码来源:RESTRequestParameterProcessingFilter.java

示例5: checkLicense

import net.sourceforge.subsonic.controller.RESTController; //导入依赖的package包/类
private RESTController.ErrorCode checkLicense(String client) {
    LicenseInfo licenseInfo = settingsService.getLicenseInfo();
    if (licenseInfo.isLicenseOrTrialValid()) {
        return null;
    }
    LOG.info("REST access for client '" + client + "' has expired.");
    return RESTController.ErrorCode.NOT_LICENSED;
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:9,代码来源:RESTRequestParameterProcessingFilter.java

示例6: sendErrorXml

import net.sourceforge.subsonic.controller.RESTController; //导入依赖的package包/类
private void sendErrorXml(HttpServletRequest request, HttpServletResponse response, RESTController.ErrorCode errorCode) throws IOException {
    try {
        jaxbWriter.writeErrorResponse(request, response, errorCode, errorCode.getMessage());
    } catch (Exception e) {
        LOG.error("Failed to send error response.", e);
    }
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:8,代码来源:RESTRequestParameterProcessingFilter.java

示例7: handleException

import net.sourceforge.subsonic.controller.RESTController; //导入依赖的package包/类
private void handleException(Throwable x, HttpServletRequest request, HttpServletResponse response) {
    if (x instanceof NestedServletException && x.getCause() != null) {
        x = x.getCause();
    }

    RESTController.ErrorCode code = (x instanceof ServletRequestBindingException) ? MISSING_PARAMETER : GENERIC;
    String msg = getErrorMessage(x);
    LOG.warn("Error in REST API: " + msg, x);

    try {
        jaxbWriter.writeErrorResponse(request, response, code, msg);
    } catch (Exception e) {
        LOG.error("Failed to write error response.", e);
    }
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:16,代码来源:RESTFilter.java

示例8: checkAPIVersion

import net.sourceforge.subsonic.controller.RESTController; //导入依赖的package包/类
private RESTController.ErrorCode checkAPIVersion(String version) {
    Version serverVersion = new Version(StringUtil.getRESTProtocolVersion());
    Version clientVersion = new Version(version);

    if (serverVersion.getMajor() > clientVersion.getMajor()) {
        return RESTController.ErrorCode.PROTOCOL_MISMATCH_CLIENT_TOO_OLD;
    } else if (serverVersion.getMajor() < clientVersion.getMajor()) {
        return RESTController.ErrorCode.PROTOCOL_MISMATCH_SERVER_TOO_OLD;
    } else if (serverVersion.getMinor() < clientVersion.getMinor()) {
        return RESTController.ErrorCode.PROTOCOL_MISMATCH_SERVER_TOO_OLD;
    }
    return null;
}
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:14,代码来源:RESTRequestParameterProcessingFilter.java

示例9: sendErrorXml

import net.sourceforge.subsonic.controller.RESTController; //导入依赖的package包/类
private void sendErrorXml(HttpServletRequest request, HttpServletResponse response, RESTController.ErrorCode errorCode) throws IOException {
    String format = ServletRequestUtils.getStringParameter(request, "f", "xml");
    boolean json = "json".equals(format);
    boolean jsonp = "jsonp".equals(format);
    XMLBuilder builder;

    response.setCharacterEncoding(StringUtil.ENCODING_UTF8);

    if (json) {
        builder = XMLBuilder.createJSONBuilder();
        response.setContentType("application/json");
    } else if (jsonp) {
        builder = XMLBuilder.createJSONPBuilder(request.getParameter("callback"));
        response.setContentType("text/javascript");
    } else {
    	builder = XMLBuilder.createXMLBuilder();
        response.setContentType("text/xml");
    }

    builder.preamble(StringUtil.ENCODING_UTF8);
    builder.add("subsonic-response", false,
                new XMLBuilder.Attribute("xmlns", "http://subsonic.org/restapi"),
                new XMLBuilder.Attribute("status", "failed"),
                new XMLBuilder.Attribute("version", StringUtil.getRESTProtocolVersion()));

    builder.add("error", true,
                new XMLBuilder.Attribute("code", errorCode.getCode()),
                new XMLBuilder.Attribute("message", errorCode.getMessage()));
    builder.end();
    response.getWriter().print(builder);
}
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:32,代码来源:RESTRequestParameterProcessingFilter.java

示例10: sendErrorXml

import net.sourceforge.subsonic.controller.RESTController; //导入依赖的package包/类
private void sendErrorXml(HttpServletRequest request, HttpServletResponse response, RESTController.ErrorCode errorCode) throws IOException {
    String format = ServletRequestUtils.getStringParameter(request, "f", "xml");
    boolean json = "json".equals(format);
    boolean jsonp = "jsonp".equals(format);
    XMLBuilder builder;

    response.setCharacterEncoding(StringUtil.ENCODING_UTF8);

    if (json) {
        builder = XMLBuilder.createJSONBuilder();
        response.setContentType("application/json");
    } else if (jsonp) {
        builder = XMLBuilder.createJSONPBuilder(request.getParameter("callback"));
        response.setContentType("text/javascript");
    } else {
    	builder = XMLBuilder.createXMLBuilder();
        response.setContentType("text/xml");
    }

    builder.preamble(StringUtil.ENCODING_UTF8);
    builder.add("subsonic-response", false,
                new XMLBuilder.Attribute("xmlns", "http://madsonic.org/restapi"),
                new XMLBuilder.Attribute("status", "failed"),
	new XMLBuilder.Attribute("type", "madsonic"),					
                new XMLBuilder.Attribute("version", StringUtil.getRESTProtocolVersion()));

    builder.add("error", true,
                new XMLBuilder.Attribute("code", errorCode.getCode()),
                new XMLBuilder.Attribute("message", errorCode.getMessage()));
    builder.end();
    response.getWriter().print(builder);
}
 
开发者ID:MadMarty,项目名称:madsonic-server-5.0,代码行数:33,代码来源:RESTRequestParameterProcessingFilter.java

示例11: doFilter

import net.sourceforge.subsonic.controller.RESTController; //导入依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if (!(request instanceof HttpServletRequest)) {
        throw new ServletException("Can only process HttpServletRequest");
    }
    if (!(response instanceof HttpServletResponse)) {
        throw new ServletException("Can only process HttpServletResponse");
    }

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    String username = StringUtils.trimToNull(httpRequest.getParameter("u"));
    String password = decrypt(StringUtils.trimToNull(httpRequest.getParameter("p")));
    String salt = StringUtils.trimToNull(httpRequest.getParameter("s"));
    String token = StringUtils.trimToNull(httpRequest.getParameter("t"));
    String version = StringUtils.trimToNull(httpRequest.getParameter("v"));
    String client = StringUtils.trimToNull(httpRequest.getParameter("c"));

    RESTController.ErrorCode errorCode = null;

    // The username and credentials parameters are not required if the user
    // was previously authenticated, for example using Basic Auth.
    boolean passwordOrTokenPresent = password != null || (salt != null && token != null);
    Authentication previousAuth = SecurityContextHolder.getContext().getAuthentication();
    boolean missingCredentials = previousAuth == null && (username == null || !passwordOrTokenPresent);
    if (missingCredentials || version == null || client == null) {
        errorCode = RESTController.ErrorCode.MISSING_PARAMETER;
    }

    if (errorCode == null) {
        errorCode = checkAPIVersion(version);
    }

    if (errorCode == null) {
        errorCode = authenticate(username, password, salt, token, previousAuth);
    }

    if (errorCode == null) {
        errorCode = checkLicense(client);
    }

    if (errorCode == null) {
        chain.doFilter(request, response);
    } else {
        if (errorCode == RESTController.ErrorCode.NOT_AUTHENTICATED) {
            loginFailureLogger.log(request.getRemoteAddr(), username);
        }
        SecurityContextHolder.getContext().setAuthentication(null);
        sendErrorXml(httpRequest, httpResponse, errorCode);
    }
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:52,代码来源:RESTRequestParameterProcessingFilter.java

示例12: doFilter

import net.sourceforge.subsonic.controller.RESTController; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if (!(request instanceof HttpServletRequest)) {
        throw new ServletException("Can only process HttpServletRequest");
    }
    if (!(response instanceof HttpServletResponse)) {
        throw new ServletException("Can only process HttpServletResponse");
    }

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    String username = StringUtils.trimToNull(httpRequest.getParameter("u"));
    String password = decrypt(StringUtils.trimToNull(httpRequest.getParameter("p")));
    String version = StringUtils.trimToNull(httpRequest.getParameter("v"));
    String client = StringUtils.trimToNull(httpRequest.getParameter("c"));

    RESTController.ErrorCode errorCode = null;

    // The username and password parameters are not required if the user
    // was previously authenticated, for example using Basic Auth.
    Authentication previousAuth = SecurityContextHolder.getContext().getAuthentication();
    boolean missingCredentials = previousAuth == null && (username == null || password == null);
    if (missingCredentials || version == null || client == null) {
        errorCode = RESTController.ErrorCode.MISSING_PARAMETER;
    }

    if (errorCode == null) {
        errorCode = checkAPIVersion(version);
    }

    if (errorCode == null) {
        errorCode = authenticate(username, password, previousAuth);
    }

    if (errorCode == null) {
        chain.doFilter(request, response);
    } else {
        LOG.info("Authentication failed for user " + username);
        SecurityContextHolder.getContext().setAuthentication(null);
        sendErrorXml(httpRequest, httpResponse, errorCode);
    }
}
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:46,代码来源:RESTRequestParameterProcessingFilter.java


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