Search in sources :

Example 11 with UserQueryService

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"));
}
Also used : JSONObject(org.json.JSONObject) UserQueryService(org.b3log.solo.service.UserQueryService) InitService(org.b3log.solo.service.InitService) Test(org.testng.annotations.Test)

Example 12 with UserQueryService

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"));
}
Also used : JSONObject(org.json.JSONObject) UserQueryService(org.b3log.solo.service.UserQueryService) InitService(org.b3log.solo.service.InitService) Test(org.testng.annotations.Test)

Example 13 with UserQueryService

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"));
}
Also used : JSONObject(org.json.JSONObject) UserQueryService(org.b3log.solo.service.UserQueryService) InitService(org.b3log.solo.service.InitService) Test(org.testng.annotations.Test)

Example 14 with UserQueryService

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"));
}
Also used : JSONObject(org.json.JSONObject) UserQueryService(org.b3log.solo.service.UserQueryService) InitService(org.b3log.solo.service.InitService) Test(org.testng.annotations.Test)

Example 15 with UserQueryService

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JSONObject(org.json.JSONObject) HttpServletResponse(javax.servlet.http.HttpServletResponse) UserQueryService(org.b3log.solo.service.UserQueryService) IOException(java.io.IOException) UserMgmtService(org.b3log.solo.service.UserMgmtService) LatkeBeanManager(org.b3log.latke.ioc.LatkeBeanManager)

Aggregations

UserQueryService (org.b3log.solo.service.UserQueryService)15 JSONObject (org.json.JSONObject)14 InitService (org.b3log.solo.service.InitService)13 Test (org.testng.annotations.Test)13 IOException (java.io.IOException)2 LatkeBeanManager (org.b3log.latke.ioc.LatkeBeanManager)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 RequestReturnAdviceException (org.b3log.latke.servlet.advice.RequestReturnAdviceException)1 UserMgmtService (org.b3log.solo.service.UserMgmtService)1