Commit abeb6053 authored by Liang Ding's avatar Liang Ding

🎨 #12527

parent b1ebbbda
......@@ -21,9 +21,10 @@ import org.b3log.latke.ioc.LatkeBeanManager;
import org.b3log.latke.ioc.Lifecycle;
import org.b3log.latke.ioc.inject.Named;
import org.b3log.latke.ioc.inject.Singleton;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.advice.BeforeRequestProcessAdvice;
import org.b3log.latke.servlet.advice.RequestProcessAdviceException;
import org.b3log.solo.service.UserQueryService;
import javax.servlet.http.HttpServletResponse;
......@@ -35,22 +36,27 @@ import java.util.Map;
*
* @author <a href="mailto:wmainlove@gmail.com">Love Yao</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.1.0, Sep 5, 2017
* @version 1.0.1.1, Sep 25, 2018
*/
@Named
@Singleton
public class ProcessAuthAdvice extends BeforeRequestProcessAdvice {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(ProcessAuthAdvice.class);
@Override
public void doAdvice(final HTTPRequestContext context, final Map<String, Object> args) throws RequestProcessAdviceException {
public void doAdvice(final HTTPRequestContext context, final Map<String, Object> args) {
final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
final UserQueryService userQueryService = beanManager.getReference(UserQueryService.class);
if (!userQueryService.isLoggedIn(context.getRequest(), context.getResponse())) {
if (!userQueryService.isAdminLoggedIn(context.getRequest())) {
try {
context.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);
} catch (final IOException e) {
throw new RuntimeException(e);
LOGGER.log(Level.ERROR, "Response sends error failed", e);
}
}
}
......
<#--
Solo - A small and beautiful blogging system written in Java.
Copyright (c) 2010-2018, b3log.org & hacpai.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<#include "../macro-common-page.ftl">
<@commonPage "401 Unauthorized!">
<h2>401 Unauthorized!</h2>
<img class="img-error" src="${staticServePath}/images/403.png" alt="401" title="401 Unauthorized!" />
<div class="a-error">
Please <a href="${loginURL}">Login</a> or return to <a href="${servePath}">Index</a>.
</div>
</@commonPage>
......@@ -21,10 +21,8 @@
<@commonPage "403 Forbidden!">
<h2>403 Forbidden!</h2>
<img class="img-error" src="${staticServePath}/images/403.png" alt="403: forbidden" title="403: forbidden" />
<img class="img-error" src="${staticServePath}/images/403.png" alt="403" title="403 Forbidden!" />
<div class="a-error">
Please
<a href="${loginURL}">Login</a>.
Return to <a href="${servePath}">Index</a> or <a href="https://hacpai.com">HacPai</a>.
Please <a href="${loginURL}">Login</a> or return to <a href="${servePath}">Index</a>.
</div>
</@commonPage>
......@@ -23,6 +23,6 @@
<h2>404 Not Found!</h2>
<img class="img-error" src="${staticServePath}/images/404.gif" title="404" alt="404 Not Found!"/>
<div class="a-error">
Return to <a href="${servePath}">Index</a> or <a href="https://hacpai.com">HacPai</a>.
Please <a href="${loginURL}">Login</a> or return to <a href="${servePath}">Index</a>.
</div>
</@commonPage>
\ No newline at end of file
......@@ -21,10 +21,8 @@
<@commonPage "500 Internal Server Error!">
<h2>500 Internal Server Error!</h2>
<img class="img-error" src="${staticServePath}/images/500.png" title="500: internal error" alt="500: internal error" />
<img class="img-error" src="${staticServePath}/images/500.png" title="500" alt="500 Internal Server Error!"/>
<div class="a-error">
Please
<a href="https://github.com/b3log/solo/issues/new">report</a>.
Return to <a href="${servePath}">Index</a> or <a href="https://hacpai.com">HacPai</a>.
Please <a href="https://github.com/b3log/solo/issues/new">report</a> it or return to <a href="${servePath}">Index</a>.
</div>
</@commonPage>
\ No newline at end of file
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