use of org.b3log.solo.service.UserQueryService in project solo by b3log.
the class BlogProcessorTestCase method init.
/**
* Init.
*
* @throws Exception exception
*/
@Test
public void init() throws Exception {
final InitService initService = getInitService();
final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
requestJSONObject.put(User.USER_NAME, "Admin");
requestJSONObject.put(User.USER_PASSWORD, "pass");
initService.init(requestJSONObject);
final UserQueryService userQueryService = getUserQueryService();
Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
}
use of org.b3log.solo.service.UserQueryService in project solo by b3log.
the class FeedProcessorTestCase method init.
/**
* Init.
*
* @throws Exception exception
*/
@Test
public void init() throws Exception {
final InitService initService = getInitService();
final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
requestJSONObject.put(User.USER_NAME, "Admin");
requestJSONObject.put(User.USER_PASSWORD, "pass");
initService.init(requestJSONObject);
final UserQueryService userQueryService = getUserQueryService();
Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
}
use of org.b3log.solo.service.UserQueryService in project solo by b3log.
the class MetaWeblogAPITestCase method init.
/**
* Init.
*
* @throws Exception exception
*/
@Test
public void init() throws Exception {
final InitService initService = getInitService();
final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
requestJSONObject.put(User.USER_NAME, "Admin");
requestJSONObject.put(User.USER_PASSWORD, "pass");
initService.init(requestJSONObject);
final UserQueryService userQueryService = getUserQueryService();
Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
}
use of org.b3log.solo.service.UserQueryService in project solo by b3log.
the class PageProcessorTestCase method init.
/**
* Init.
*
* @throws Exception exception
*/
@Test
public void init() throws Exception {
final InitService initService = getInitService();
final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
requestJSONObject.put(User.USER_NAME, "Admin");
requestJSONObject.put(User.USER_PASSWORD, "pass");
initService.init(requestJSONObject);
final UserQueryService userQueryService = getUserQueryService();
Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
}
use of org.b3log.solo.service.UserQueryService in project solo by b3log.
the class AuthFilter method doFilter.
/**
* If the specified request is NOT made by an authenticated user, sends
* error 403.
*
* @param request the specified request
* @param response the specified response
* @param chain filter chain
* @throws IOException io exception
* @throws ServletException servlet exception
*/
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
final HttpServletResponse httpServletResponse = (HttpServletResponse) response;
final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
final UserMgmtService userMgmtService = beanManager.getReference(UserMgmtService.class);
final UserQueryService userQueryService = beanManager.getReference(UserQueryService.class);
try {
userMgmtService.tryLogInWithCookie(httpServletRequest, httpServletResponse);
final JSONObject currentUser = userQueryService.getCurrentUser(httpServletRequest);
if (null == currentUser) {
LOGGER.warn("The request has been forbidden");
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final String userRole = currentUser.optString(User.USER_ROLE);
if (Role.VISITOR_ROLE.equals(userRole)) {
LOGGER.warn("The request [Visitor] has been forbidden");
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
chain.doFilter(request, response);
} catch (final IOException e) {
LOGGER.log(Level.ERROR, "Auth filter failed", e);
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
Aggregations