Commit ae4e39f0 authored by wmainlove@gmail.com's avatar wmainlove@gmail.com

用advice简化一些代码

parent 989c6df0
...@@ -26,10 +26,12 @@ import org.b3log.latke.model.Plugin; ...@@ -26,10 +26,12 @@ import org.b3log.latke.model.Plugin;
import org.b3log.latke.service.LangPropsService; import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.servlet.HTTPRequestContext; import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.HTTPRequestMethod; import org.b3log.latke.servlet.HTTPRequestMethod;
import org.b3log.latke.servlet.annotation.Before;
import org.b3log.latke.servlet.annotation.RequestProcessing; import org.b3log.latke.servlet.annotation.RequestProcessing;
import org.b3log.latke.servlet.annotation.RequestProcessor; import org.b3log.latke.servlet.annotation.RequestProcessor;
import org.b3log.latke.servlet.renderer.JSONRenderer; import org.b3log.latke.servlet.renderer.JSONRenderer;
import org.b3log.latke.util.Requests; import org.b3log.latke.util.Requests;
import org.b3log.solo.processor.console.common.ProcessAuthAdvice;
import org.b3log.solo.service.PluginMgmtService; import org.b3log.solo.service.PluginMgmtService;
import org.b3log.solo.service.PluginQueryService; import org.b3log.solo.service.PluginQueryService;
import org.b3log.solo.util.QueryResults; import org.b3log.solo.util.QueryResults;
...@@ -41,10 +43,12 @@ import org.json.JSONObject; ...@@ -41,10 +43,12 @@ import org.json.JSONObject;
* Plugin console request processing. * Plugin console request processing.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.1, Aug 9, 2012 * @author <a href="mailto:wmainlove@gmail.com">Love Yao</a>
* @version 1.1.0.0, Jan 17, 2013
* @since 0.4.0 * @since 0.4.0
*/ */
@RequestProcessor @RequestProcessor
@Before(adviceClass = ProcessAuthAdvice.class)
public final class PluginConsole { public final class PluginConsole {
/** /**
...@@ -93,10 +97,6 @@ public final class PluginConsole { ...@@ -93,10 +97,6 @@ public final class PluginConsole {
@RequestProcessing(value = "/console/plugin/status/", method = HTTPRequestMethod.PUT) @RequestProcessing(value = "/console/plugin/status/", method = HTTPRequestMethod.PUT)
public void setPluginStatus(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void setPluginStatus(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context)
throws Exception { throws Exception {
if (!userUtils.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
...@@ -150,10 +150,6 @@ public final class PluginConsole { ...@@ -150,10 +150,6 @@ public final class PluginConsole {
method = HTTPRequestMethod.GET) method = HTTPRequestMethod.GET)
public void getPlugins(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void getPlugins(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context)
throws Exception { throws Exception {
if (!userUtils.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
......
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
*
* 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.b3log.solo.processor.console.common;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.advice.BeforeRequestProcessAdvice;
import org.b3log.latke.servlet.advice.RequestProcessAdviceException;
import org.b3log.latke.servlet.advice.RequestReturnAdviceException;
import org.b3log.solo.util.Users;
/**
* the common auth check before advice for admin console.
*
* @author <a href="mailto:wmainlove@gmail.com">Love Yao</a>
* @version 1.0.0.0, Jan 17, 2013
*/
public class ProcessAuthAdvice extends BeforeRequestProcessAdvice {
/**
* User utilities.
*/
private Users userUtils = Users.getInstance();
@Override
public void doAdvice(final HTTPRequestContext context, final Map<String, Object> args) throws RequestProcessAdviceException {
if (!userUtils.isLoggedIn(context.getRequest(), context.getResponse())) {
try {
context.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);
} catch (final IOException e) {
throw new RuntimeException(e);
}
throw new RequestReturnAdviceException(null);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment