Search in sources :

Example 26 with ServiceResult

use of org.apache.openmeetings.db.dto.basic.ServiceResult in project openmeetings by apache.

the class TestUserService method invalidLoginTest.

@Test
public void invalidLoginTest() {
    ServiceResult r = loginNoCheck("invalid-user", "bad pass");
    assertNotNull("Valid ServiceResult should be returned", r);
    assertEquals("Login should NOT be successful", Type.ERROR.name(), r.getType());
}
Also used : ServiceResult(org.apache.openmeetings.db.dto.basic.ServiceResult) Test(org.junit.Test)

Example 27 with ServiceResult

use of org.apache.openmeetings.db.dto.basic.ServiceResult in project openmeetings by apache.

the class TestUserService method hashTest.

@Test
public void hashTest() throws OmException {
    ServiceResult r = login();
    ServiceResult r1 = getHash(r.getMessage(), false);
    assertEquals("OM Call should be successful", Type.SUCCESS.name(), r1.getType());
    // to ensure WebSession is attached
    ensureApplication(-1L);
    WebSession ws = WebSession.get();
    assertTrue(ws.signIn(adminUsername, userpass, User.Type.user, null));
    Long userId0 = WebSession.getUserId();
    ws.checkHashes(StringValue.valueOf(r1.getMessage()), StringValue.valueOf(""));
    assertTrue("Login via secure hash should be successful", ws.isSignedIn());
    Long userId1 = WebSession.getUserId();
    Assert.assertNotEquals(userId0, userId1);
}
Also used : ServiceResult(org.apache.openmeetings.db.dto.basic.ServiceResult) WebSession(org.apache.openmeetings.web.app.WebSession) Test(org.junit.Test)

Example 28 with ServiceResult

use of org.apache.openmeetings.db.dto.basic.ServiceResult in project openmeetings by apache.

the class FileWebService method delete.

/**
 * deletes files or folders based on it id
 *
 * @param sid
 *            The SID of the User. This SID must be marked as logged in
 * @param id
 *            the id of the file or folder
 * @return {@link ServiceResult} with result type
 */
@DELETE
@Path("/{id}")
public ServiceResult delete(@QueryParam("sid") @WebParam(name = "sid") String sid, @PathParam("id") @WebParam(name = "id") Long id) {
    FileItem f = fileDao.get(id);
    return performCall(sid, sd -> {
        Long userId = sd.getUserId();
        Set<Right> rights = getRights(userId);
        return AuthLevelUtil.hasWebServiceLevel(rights) || (AuthLevelUtil.hasUserLevel(rights) && userId.equals(f.getOwnerId()));
    }, sd -> {
        if (f == null) {
            return new ServiceResult("Bad id", Type.ERROR);
        }
        fileDao.delete(f);
        return new ServiceResult("Deleted", Type.SUCCESS);
    });
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) ServiceResult(org.apache.openmeetings.db.dto.basic.ServiceResult) Right(org.apache.openmeetings.db.entity.user.User.Right) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 29 with ServiceResult

use of org.apache.openmeetings.db.dto.basic.ServiceResult in project openmeetings by apache.

the class FileWebService method deleteExternal.

/**
 * deletes a file by its external Id and type
 *
 * @param sid
 *            The SID of the User. This SID must be marked as logged in
 * @param externalId
 *            the od of the file or folder
 * @param externalType
 *            the externalType
 * @return {@link ServiceResult} with result type
 */
@DELETE
@Path("/{externaltype}/{externalid}")
public ServiceResult deleteExternal(@WebParam(name = "sid") @QueryParam("sid") String sid, @WebParam(name = "externaltype") @PathParam("externaltype") String externalType, @WebParam(name = "externalid") @PathParam("externalid") String externalId) {
    return performCall(sid, User.Right.Soap, sd -> {
        FileItem f = fileDao.get(externalId, externalType);
        fileDao.delete(f);
        return new ServiceResult("Deleted", Type.SUCCESS);
    });
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) ServiceResult(org.apache.openmeetings.db.dto.basic.ServiceResult) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 30 with ServiceResult

use of org.apache.openmeetings.db.dto.basic.ServiceResult in project openmeetings by apache.

the class GroupWebService method removeUser.

/**
 * Remove user from a certain group
 *
 * @param sid
 *            The SID from getSession
 * @param userid
 *            the user id
 * @param id
 *            the group id
 * @return {@link ServiceResult} with result type, and id of the user added, or error id in case of the error as text
 */
@DELETE
@Path("/{id}/users/{userid}")
public ServiceResult removeUser(@QueryParam("sid") @WebParam(name = "sid") String sid, @PathParam("id") @WebParam(name = "id") Long id, @PathParam("userid") @WebParam(name = "userid") Long userid) {
    return performCall(sid, User.Right.Soap, sd -> {
        if (groupUserDao.isUserInGroup(id, userid)) {
            User u = userDao.get(userid);
            for (Iterator<GroupUser> iter = u.getGroupUsers().iterator(); iter.hasNext(); ) {
                GroupUser gu = iter.next();
                if (id.equals(gu.getGroup().getId())) {
                    iter.remove();
                }
            }
            userDao.update(u, sd.getUserId());
        }
        return new ServiceResult(String.valueOf(userid), Type.SUCCESS);
    });
}
Also used : User(org.apache.openmeetings.db.entity.user.User) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) ServiceResult(org.apache.openmeetings.db.dto.basic.ServiceResult) GroupUser(org.apache.openmeetings.db.entity.user.GroupUser) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

ServiceResult (org.apache.openmeetings.db.dto.basic.ServiceResult)37 Test (org.junit.Test)18 Path (javax.ws.rs.Path)12 User (org.apache.openmeetings.db.entity.user.User)8 Response (javax.ws.rs.core.Response)7 WebMethod (javax.jws.WebMethod)5 POST (javax.ws.rs.POST)5 Room (org.apache.openmeetings.db.entity.room.Room)5 GroupUser (org.apache.openmeetings.db.entity.user.GroupUser)5 DELETE (javax.ws.rs.DELETE)4 Form (javax.ws.rs.core.Form)4 AbstractJUnitDefaults.getUser (org.apache.openmeetings.AbstractJUnitDefaults.getUser)4 GET (javax.ws.rs.GET)3 AbstractJUnitDefaults.createUser (org.apache.openmeetings.AbstractJUnitDefaults.createUser)3 GroupDao (org.apache.openmeetings.db.dao.user.GroupDao)3 RoomDTO (org.apache.openmeetings.db.dto.room.RoomDTO)3 Locale (java.util.Locale)2 AppointmentDTO (org.apache.openmeetings.db.dto.calendar.AppointmentDTO)2 UserDTO (org.apache.openmeetings.db.dto.user.UserDTO)2 FileItem (org.apache.openmeetings.db.entity.file.FileItem)2