Search in sources :

Example 46 with UserModel

use of com.gitblit.models.UserModel in project gitblit by gitblit.

the class FilestoreServlet method doPost.

/**
	 * Handles batch upload request (metadata)
	 *
	 * @param request
	 * @param response
	 * @throws javax.servlet.ServletException
	 * @throws java.io.IOException
	 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    UrlInfo info = getInfoFromRequest(request);
    if (info == null) {
        sendError(response, HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    //Post is for batch operations so no oid should be defined
    if (info.oid != null) {
        sendError(response, HttpServletResponse.SC_BAD_REQUEST);
        return;
    }
    IGitLFS.Batch batch = deserialize(request, response, IGitLFS.Batch.class);
    if (batch == null) {
        sendError(response, HttpServletResponse.SC_BAD_REQUEST);
        return;
    }
    UserModel user = getUserOrAnonymous(request);
    IGitLFS.BatchResponse batchResponse = new IGitLFS.BatchResponse();
    if (batch.operation.equalsIgnoreCase("upload")) {
        for (IGitLFS.Request item : batch.objects) {
            Status state = gitblit.addObject(item.oid, item.size, user, info.repository);
            batchResponse.objects.add(getResponseForUpload(info.baseUrl, item.oid, item.size, user.getName(), info.repository.name, state));
        }
    } else if (batch.operation.equalsIgnoreCase("download")) {
        for (IGitLFS.Request item : batch.objects) {
            Status state = gitblit.downloadBlob(item.oid, user, info.repository, null);
            batchResponse.objects.add(getResponseForDownload(info.baseUrl, item.oid, item.size, user.getName(), info.repository.name, state));
        }
    } else {
        sendError(response, HttpServletResponse.SC_NOT_IMPLEMENTED);
        return;
    }
    response.setStatus(HttpServletResponse.SC_OK);
    serialize(response, batchResponse);
}
Also used : UserModel(com.gitblit.models.UserModel) Status(com.gitblit.models.FilestoreModel.Status) HttpServletRequest(javax.servlet.http.HttpServletRequest)

Example 47 with UserModel

use of com.gitblit.models.UserModel in project gitblit by gitblit.

the class FilestoreServlet method doGet.

/**
	 * Handles a download
	 * Treated as hypermedia request if accept header contains Git-LFS MIME
	 * otherwise treated as a download of the blob
	 * @param request
	 * @param response
	 * @throws javax.servlet.ServletException
	 * @throws java.io.IOException
	 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    UrlInfo info = getInfoFromRequest(request);
    if (info == null || info.oid == null) {
        sendError(response, HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    UserModel user = getUserOrAnonymous(request);
    FilestoreModel model = gitblit.getObject(info.oid, user, info.repository);
    long size = FilestoreManager.UNDEFINED_SIZE;
    boolean isMetaRequest = AccessRestrictionFilter.hasContentInRequestHeader(request, "Accept", GIT_LFS_META_MIME);
    FilestoreModel.Status status = Status.Unavailable;
    if (model != null) {
        size = model.getSize();
        status = model.getStatus();
    }
    if (!isMetaRequest) {
        status = gitblit.downloadBlob(info.oid, user, info.repository, response.getOutputStream());
        logger.info(MessageFormat.format("FILESTORE-AUDIT {0}:{4} {1} {2}@{3}", "GET", info.oid, user.getName(), info.repository.name, status.toString()));
    }
    if (status == Status.Error_Unexpected_Stream_End) {
        return;
    }
    IGitLFS.Response responseObject = getResponseForDownload(info.baseUrl, info.oid, size, user.getName(), info.repository.name, status);
    if (responseObject.error == null) {
        response.setStatus(responseObject.successCode);
        if (isMetaRequest) {
            serialize(response, responseObject);
        }
    } else {
        response.setStatus(responseObject.error.code);
        if (isMetaRequest) {
            serialize(response, responseObject.error);
        }
    }
}
Also used : UserModel(com.gitblit.models.UserModel) FilestoreModel(com.gitblit.models.FilestoreModel) Status(com.gitblit.models.FilestoreModel.Status)

Example 48 with UserModel

use of com.gitblit.models.UserModel in project gitblit by gitblit.

the class HtpasswdAuthenticationTest method testChangeHtpasswdFileNotExisting.

@Test
public void testChangeHtpasswdFileNotExisting() {
    UserModel user;
    // User default set up.
    user = htpasswd.authenticate("md5", "password".toCharArray());
    assertNotNull(user);
    assertEquals("md5", user.username);
    user = htpasswd.authenticate("sha", "password".toCharArray());
    assertNotNull(user);
    assertEquals("sha", user.username);
    user = htpasswd.authenticate("blueone", "GoBlue!".toCharArray());
    assertNull(user);
    user = htpasswd.authenticate("bluetwo", "YayBlue!".toCharArray());
    assertNull(user);
    // Switch to different htpasswd file that doesn't exist.
    // Currently we stop working with old users upon this change.
    getSettings(RESOURCE_DIR + "no-such-file", null, null);
    user = htpasswd.authenticate("md5", "password".toCharArray());
    assertNull(user);
    user = htpasswd.authenticate("sha", "password".toCharArray());
    assertNull(user);
    user = htpasswd.authenticate("blueone", "GoBlue!".toCharArray());
    assertNull(user);
    user = htpasswd.authenticate("bluetwo", "YayBlue!".toCharArray());
    assertNull(user);
}
Also used : UserModel(com.gitblit.models.UserModel) Test(org.junit.Test)

Example 49 with UserModel

use of com.gitblit.models.UserModel in project gitblit by gitblit.

the class HtpasswdAuthenticationTest method testAuthenticateDenied.

@Test
public void testAuthenticateDenied() {
    UserModel user = null;
    MS.put(KEY_SUPPORT_PLAINTEXT_PWD, "true");
    user = htpasswd.authenticate("user1", "".toCharArray());
    assertNull("User 'user1' falsely authenticated.", user);
    user = htpasswd.authenticate("user1", "pass2".toCharArray());
    assertNull("User 'user1' falsely authenticated.", user);
    user = htpasswd.authenticate("user2", "lalala".toCharArray());
    assertNull("User 'user2' falsely authenticated.", user);
    user = htpasswd.authenticate("user3", "disabled".toCharArray());
    assertNull("User 'user3' falsely authenticated.", user);
    user = htpasswd.authenticate("user4", "disabled".toCharArray());
    assertNull("User 'user4' falsely authenticated.", user);
    user = htpasswd.authenticate("plain", "text".toCharArray());
    assertNull("User 'plain' falsely authenticated.", user);
    user = htpasswd.authenticate("plain", "password".toCharArray());
    assertNull("User 'plain' falsely authenticated.", user);
    MS.put(KEY_SUPPORT_PLAINTEXT_PWD, "false");
    user = htpasswd.authenticate("crypt", "".toCharArray());
    assertNull("User 'cyrpt' falsely authenticated.", user);
    user = htpasswd.authenticate("crypt", "passwd".toCharArray());
    assertNull("User 'crypt' falsely authenticated.", user);
    user = htpasswd.authenticate("md5", "".toCharArray());
    assertNull("User 'md5' falsely authenticated.", user);
    user = htpasswd.authenticate("md5", "pwd".toCharArray());
    assertNull("User 'md5' falsely authenticated.", user);
    user = htpasswd.authenticate("sha", "".toCharArray());
    assertNull("User 'sha' falsely authenticated.", user);
    user = htpasswd.authenticate("sha", "letmein".toCharArray());
    assertNull("User 'sha' falsely authenticated.", user);
    user = htpasswd.authenticate("  tabbed", "frontAndBack".toCharArray());
    assertNull("User 'tabbed' falsely authenticated.", user);
    user = htpasswd.authenticate("    leading", "whitespace".toCharArray());
    assertNull("User 'leading' falsely authenticated.", user);
}
Also used : UserModel(com.gitblit.models.UserModel) Test(org.junit.Test)

Example 50 with UserModel

use of com.gitblit.models.UserModel in project gitblit by gitblit.

the class Issue0259Test method testFile.

/**
	 * Test the provided users.conf file for expected access permissions.
	 *
	 * @throws Exception
	 */
@Test
public void testFile() throws Exception {
    File realmFile = new File("src/test/resources/issue0259.conf");
    ConfigUserService service = new ConfigUserService(realmFile);
    RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW);
    RepositoryModel projects_test = repo("projects/test.git", AccessRestrictionType.VIEW);
    UserModel a = service.getUserModel("a");
    UserModel b = service.getUserModel("b");
    UserModel c = service.getUserModel("c");
    // assert RWD or RW+ for projects/test.git
    assertEquals(AccessPermission.DELETE, a.getRepositoryPermission(projects_test).permission);
    assertEquals(AccessPermission.DELETE, b.getRepositoryPermission(projects_test).permission);
    assertEquals(AccessPermission.REWIND, c.getRepositoryPermission(projects_test).permission);
    assertTrue(a.canPush(projects_test));
    assertTrue(b.canPush(projects_test));
    assertTrue(c.canPush(projects_test));
    assertTrue(a.canDeleteRef(projects_test));
    assertTrue(b.canDeleteRef(projects_test));
    assertTrue(c.canDeleteRef(projects_test));
    assertFalse(a.canRewindRef(projects_test));
    assertFalse(b.canRewindRef(projects_test));
    assertTrue(c.canRewindRef(projects_test));
    // assert R for test.git
    assertEquals(AccessPermission.CLONE, a.getRepositoryPermission(test).permission);
    assertEquals(AccessPermission.CLONE, b.getRepositoryPermission(test).permission);
    assertEquals(AccessPermission.REWIND, c.getRepositoryPermission(test).permission);
    assertTrue(a.canClone(test));
    assertTrue(b.canClone(test));
    assertFalse(a.canPush(test));
    assertFalse(b.canPush(test));
    assertTrue(c.canPush(test));
}
Also used : UserModel(com.gitblit.models.UserModel) ConfigUserService(com.gitblit.ConfigUserService) RepositoryModel(com.gitblit.models.RepositoryModel) File(java.io.File) Test(org.junit.Test)

Aggregations

UserModel (com.gitblit.models.UserModel)230 Test (org.junit.Test)127 RepositoryModel (com.gitblit.models.RepositoryModel)116 Date (java.util.Date)88 TeamModel (com.gitblit.models.TeamModel)58 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)16 File (java.io.File)15 HashMap (java.util.HashMap)11 Label (org.apache.wicket.markup.html.basic.Label)10 RevCommit (org.eclipse.jgit.revwalk.RevCommit)10 Repository (org.eclipse.jgit.lib.Repository)9 HashSet (java.util.HashSet)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 ProjectModel (com.gitblit.models.ProjectModel)7 Map (java.util.Map)7 GitBlitException (com.gitblit.GitBlitException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 List (java.util.List)6 Fragment (org.apache.wicket.markup.html.panel.Fragment)5