Search in sources :

Example 26 with UserModel

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

the class PermissionsTest method testTeamMember_NONE_NONE.

/**
	 * NONE_NONE = NO access restriction, NO access permission
	 */
@Test
public void testTeamMember_NONE_NONE() throws Exception {
    RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.NONE;
    TeamModel team = new TeamModel("test");
    UserModel user = new UserModel("test");
    user.teams.add(team);
    assertTrue("team member CAN NOT view!", user.canView(repository));
    assertTrue("team member CAN NOT clone!", user.canClone(repository));
    assertTrue("team member CAN NOT push!", user.canPush(repository));
    assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
    assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
    assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
    assertEquals("team member has wrong permission!", AccessPermission.REWIND, user.getRepositoryPermission(repository).permission);
}
Also used : UserModel(com.gitblit.models.UserModel) TeamModel(com.gitblit.models.TeamModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 27 with UserModel

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

the class PermissionsTest method testTeamMember_NONE_CLONE.

/**
	 * NONE_CLONE = NO access restriction, CLONE access permission
	 * (not useful scenario)
	 */
@Test
public void testTeamMember_NONE_CLONE() throws Exception {
    RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.NONE;
    TeamModel team = new TeamModel("test");
    team.setRepositoryPermission(repository.name, AccessPermission.CLONE);
    UserModel user = new UserModel("test");
    user.teams.add(team);
    assertTrue("team member CAN NOT view!", user.canView(repository));
    assertTrue("team member CAN NOT clone!", user.canClone(repository));
    assertTrue("team member CAN NOT push!", user.canPush(repository));
    assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
    assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
    assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
    assertEquals("team member has wrong permission!", AccessPermission.REWIND, user.getRepositoryPermission(repository).permission);
}
Also used : UserModel(com.gitblit.models.UserModel) TeamModel(com.gitblit.models.TeamModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 28 with UserModel

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

the class PermissionsTest method testTeamMember_VIEW_NONE.

/**
	 * VIEW_NONE = VIEW access restriction, NO access permission
	 */
@Test
public void testTeamMember_VIEW_NONE() throws Exception {
    RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.VIEW;
    TeamModel team = new TeamModel("test");
    UserModel user = new UserModel("test");
    user.teams.add(team);
    assertFalse("team member CAN view!", user.canView(repository));
    assertFalse("team member CAN clone!", user.canClone(repository));
    assertFalse("team member CAN push!", user.canPush(repository));
    assertFalse("team member CAN create ref!", user.canCreateRef(repository));
    assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
    assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
    assertEquals("team member has wrong permission!", AccessPermission.NONE, user.getRepositoryPermission(repository).permission);
}
Also used : UserModel(com.gitblit.models.UserModel) TeamModel(com.gitblit.models.TeamModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 29 with UserModel

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

the class PermissionsTest method testNamed_VIEW_CLONE.

/**
	 * VIEW_CLONE = VIEW access restriction, CLONE access permission
	 */
@Test
public void testNamed_VIEW_CLONE() throws Exception {
    RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.VIEW;
    UserModel user = new UserModel("test");
    user.setRepositoryPermission(repository.name, AccessPermission.CLONE);
    assertTrue("named CAN NOT view!", user.canView(repository));
    assertTrue("named CAN NOT clone!", user.canClone(repository));
    assertFalse("named CAN push!", user.canPush(repository));
    assertFalse("named CAN create ref!", user.canCreateRef(repository));
    assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
    assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
    assertEquals("named has wrong permission!", AccessPermission.CLONE, user.getRepositoryPermission(repository).permission);
    repository.allowForks = false;
    user.canFork = false;
    assertFalse("named CAN fork!", user.canFork(repository));
    user.canFork = true;
    assertFalse("named CAN fork!", user.canFork(repository));
    repository.allowForks = true;
    assertTrue("named CAN NOT fork!", user.canFork(repository));
}
Also used : UserModel(com.gitblit.models.UserModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 30 with UserModel

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

the class RepositoryResolver method isExportOk.

/**
	 * Check if this repository can be served by the requested client connection.
	 */
@Override
protected boolean isExportOk(X req, String repositoryName, Repository db) throws IOException {
    RepositoryModel model = gitblit.getRepositoryModel(repositoryName);
    UserModel user = UserModel.ANONYMOUS;
    String scheme = null;
    String origin = null;
    if (req instanceof GitDaemonClient) {
        // git daemon request
        // this is an anonymous/unauthenticated protocol
        GitDaemonClient client = (GitDaemonClient) req;
        scheme = "git";
        origin = client.getRemoteAddress().toString();
    } else if (req instanceof HttpServletRequest) {
        // http/https request
        HttpServletRequest client = (HttpServletRequest) req;
        scheme = client.getScheme();
        origin = client.getRemoteAddr();
        user = gitblit.authenticate(client);
        if (user == null) {
            user = UserModel.ANONYMOUS;
        }
    } else if (req instanceof SshDaemonClient) {
        // ssh is always authenticated
        SshDaemonClient client = (SshDaemonClient) req;
        user = client.getUser();
    }
    if (user.canClone(model)) {
        // user can access this git repo
        logger.debug(MessageFormat.format("{0}:// access of {1} by {2} from {3} PERMITTED", scheme, repositoryName, user.username, origin));
        return true;
    }
    // user can not access this git repo
    logger.warn(MessageFormat.format("{0}:// access of {1} by {2} from {3} DENIED", scheme, repositoryName, user.username, origin));
    return false;
}
Also used : UserModel(com.gitblit.models.UserModel) HttpServletRequest(javax.servlet.http.HttpServletRequest) RepositoryModel(com.gitblit.models.RepositoryModel) SshDaemonClient(com.gitblit.transport.ssh.SshDaemonClient) GitDaemonClient(com.gitblit.transport.git.GitDaemonClient)

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