Search in sources :

Example 1 with IAuthenticationManager

use of com.gitblit.manager.IAuthenticationManager in project gitblit by gitblit.

the class AuthenticationManagerTest method testContenairAuthenticateEmpty.

@Test
public void testContenairAuthenticateEmpty() throws Exception {
    settings.put(Keys.realm.container.autoCreateAccounts, "true");
    settings.put(Keys.realm.container.autoAccounts.displayName, "displayName");
    settings.put(Keys.realm.container.autoAccounts.emailAddress, "emailAddress");
    settings.put(Keys.realm.container.autoAccounts.adminRole, "notAdmin");
    DummyHttpServletRequest request = new DummyHttpServletRequest();
    IAuthenticationManager auth = newAuthenticationManager();
    UserModel user = auth.authenticate(request);
    assertFalse(user.canAdmin);
    assertEquals("sunnyjim", user.displayName);
    assertNull(user.emailAddress);
    assertNull(user.getPreferences().getLocale());
}
Also used : UserModel(com.gitblit.models.UserModel) IAuthenticationManager(com.gitblit.manager.IAuthenticationManager) Test(org.junit.Test)

Example 2 with IAuthenticationManager

use of com.gitblit.manager.IAuthenticationManager in project gitblit by gitblit.

the class AuthenticationManagerTest method testContenairAuthenticate.

@Test
public void testContenairAuthenticate() throws Exception {
    settings.put(Keys.realm.container.autoCreateAccounts, "true");
    settings.put(Keys.realm.container.autoAccounts.displayName, "displayName");
    settings.put(Keys.realm.container.autoAccounts.emailAddress, "emailAddress");
    settings.put(Keys.realm.container.autoAccounts.adminRole, "admin");
    settings.put(Keys.realm.container.autoAccounts.locale, "locale");
    DummyHttpServletRequest request = new DummyHttpServletRequest();
    request.sessionAttributes.put("displayName", "Sunny Jim");
    request.sessionAttributes.put("emailAddress", "Jim.Sunny@gitblit.com");
    request.sessionAttributes.put("locale", "it");
    IAuthenticationManager auth = newAuthenticationManager();
    UserModel user = auth.authenticate(request);
    assertTrue(user.canAdmin);
    assertEquals("Sunny Jim", user.displayName);
    assertEquals("Jim.Sunny@gitblit.com", user.emailAddress);
    assertEquals(Locale.ITALIAN, user.getPreferences().getLocale());
}
Also used : UserModel(com.gitblit.models.UserModel) IAuthenticationManager(com.gitblit.manager.IAuthenticationManager) Test(org.junit.Test)

Example 3 with IAuthenticationManager

use of com.gitblit.manager.IAuthenticationManager in project gitblit by gitblit.

the class AuthenticationManagerTest method testAuthenticate.

@Test
public void testAuthenticate() throws Exception {
    IAuthenticationManager auth = newAuthenticationManager();
    UserModel user = new UserModel("sunnyjim");
    user.password = "password";
    users.updateUserModel(user);
    assertNotNull(auth.authenticate(user.username, user.password.toCharArray(), null));
    user.disabled = true;
    users.updateUserModel(user);
    assertNull(auth.authenticate(user.username, user.password.toCharArray(), null));
    users.deleteUserModel(user);
}
Also used : UserModel(com.gitblit.models.UserModel) IAuthenticationManager(com.gitblit.manager.IAuthenticationManager) Test(org.junit.Test)

Example 4 with IAuthenticationManager

use of com.gitblit.manager.IAuthenticationManager in project gitblit by gitblit.

the class AuthenticationManagerTest method newAuthenticationManager.

IAuthenticationManager newAuthenticationManager() {
    XssFilter xssFilter = new AllowXssFilter();
    RuntimeManager runtime = new RuntimeManager(getSettings(), xssFilter, GitBlitSuite.BASEFOLDER).start();
    users = new UserManager(runtime, null).start();
    final Map<String, UserModel> virtualUsers = new HashMap<String, UserModel>();
    users.setUserService(new IUserService() {

        @Override
        public void setup(IRuntimeManager runtimeManager) {
        }

        @Override
        public String getCookie(UserModel model) {
            return null;
        }

        @Override
        public UserModel getUserModel(char[] cookie) {
            return null;
        }

        @Override
        public UserModel getUserModel(String username) {
            return virtualUsers.get(username);
        }

        @Override
        public boolean updateUserModel(UserModel model) {
            virtualUsers.put(model.username, model);
            return true;
        }

        @Override
        public boolean updateUserModels(Collection<UserModel> models) {
            return false;
        }

        @Override
        public boolean updateUserModel(String username, UserModel model) {
            virtualUsers.put(username, model);
            return true;
        }

        @Override
        public boolean deleteUserModel(UserModel model) {
            return false;
        }

        @Override
        public boolean deleteUser(String username) {
            return false;
        }

        @Override
        public List<String> getAllUsernames() {
            return null;
        }

        @Override
        public List<UserModel> getAllUsers() {
            return null;
        }

        @Override
        public List<String> getAllTeamNames() {
            return null;
        }

        @Override
        public List<TeamModel> getAllTeams() {
            return null;
        }

        @Override
        public List<String> getTeamNamesForRepositoryRole(String role) {
            return null;
        }

        @Override
        public TeamModel getTeamModel(String teamname) {
            return null;
        }

        @Override
        public boolean updateTeamModel(TeamModel model) {
            return false;
        }

        @Override
        public boolean updateTeamModels(Collection<TeamModel> models) {
            return false;
        }

        @Override
        public boolean updateTeamModel(String teamname, TeamModel model) {
            return false;
        }

        @Override
        public boolean deleteTeamModel(TeamModel model) {
            return false;
        }

        @Override
        public boolean deleteTeam(String teamname) {
            return false;
        }

        @Override
        public List<String> getUsernamesForRepositoryRole(String role) {
            return null;
        }

        @Override
        public boolean renameRepositoryRole(String oldRole, String newRole) {
            return false;
        }

        @Override
        public boolean deleteRepositoryRole(String role) {
            return false;
        }
    });
    AuthenticationManager auth = new AuthenticationManager(runtime, users).start();
    return auth;
}
Also used : HashMap(java.util.HashMap) IRuntimeManager(com.gitblit.manager.IRuntimeManager) RuntimeManager(com.gitblit.manager.RuntimeManager) UserModel(com.gitblit.models.UserModel) IRuntimeManager(com.gitblit.manager.IRuntimeManager) AuthenticationManager(com.gitblit.manager.AuthenticationManager) IAuthenticationManager(com.gitblit.manager.IAuthenticationManager) TeamModel(com.gitblit.models.TeamModel) UserManager(com.gitblit.manager.UserManager) IUserService(com.gitblit.IUserService) AllowXssFilter(com.gitblit.utils.XssFilter.AllowXssFilter) XssFilter(com.gitblit.utils.XssFilter) AllowXssFilter(com.gitblit.utils.XssFilter.AllowXssFilter) List(java.util.List)

Aggregations

IAuthenticationManager (com.gitblit.manager.IAuthenticationManager)4 UserModel (com.gitblit.models.UserModel)4 Test (org.junit.Test)3 IUserService (com.gitblit.IUserService)1 AuthenticationManager (com.gitblit.manager.AuthenticationManager)1 IRuntimeManager (com.gitblit.manager.IRuntimeManager)1 RuntimeManager (com.gitblit.manager.RuntimeManager)1 UserManager (com.gitblit.manager.UserManager)1 TeamModel (com.gitblit.models.TeamModel)1 XssFilter (com.gitblit.utils.XssFilter)1 AllowXssFilter (com.gitblit.utils.XssFilter.AllowXssFilter)1 HashMap (java.util.HashMap)1 List (java.util.List)1