use of com.gitblit.models.TeamModel in project gitblit by gitblit.
the class LdapAuthenticationTest method syncNotUpdateUsersAndGroupsAdminProperty.
@Test
public void syncNotUpdateUsersAndGroupsAdminProperty() throws Exception {
settings.put(Keys.realm.ldap.synchronize, "true");
settings.put(Keys.realm.ldap.maintainTeams, "false");
ldap.sync();
UserModel user = userManager.getUserModel("UserOne");
assertNotNull(user);
assertTrue(user.canAdmin);
assertTrue(user.canAdmin());
user = userManager.getUserModel("UserTwo");
assertNotNull(user);
assertFalse(user.canAdmin);
assertTrue(user.canAdmin());
user = userManager.getUserModel("UserThree");
assertNotNull(user);
assertFalse(user.canAdmin);
assertFalse(user.canAdmin());
user = userManager.getUserModel("UserFour");
assertNotNull(user);
assertFalse(user.canAdmin);
assertFalse(user.canAdmin());
TeamModel team = userManager.getTeamModel("Git_Admins");
assertNotNull(team);
assertFalse(team.canAdmin);
team = userManager.getTeamModel("Git Admins");
assertNotNull(team);
assertTrue(team.canAdmin);
team = userManager.getTeamModel("Git_Users");
assertNotNull(team);
assertFalse(team.canAdmin);
}
use of com.gitblit.models.TeamModel in project gitblit by gitblit.
the class EditUserDialog method initialize.
private void initialize(int protocolVersion, UserModel anUser) {
usernameField = new JTextField(anUser.username == null ? "" : anUser.username, 25);
passwordField = new JPasswordField(anUser.password == null ? "" : anUser.password, 25);
confirmPasswordField = new JPasswordField(anUser.password == null ? "" : anUser.password, 25);
displayNameField = new JTextField(anUser.displayName == null ? "" : anUser.displayName, 25);
emailAddressField = new JTextField(anUser.emailAddress == null ? "" : anUser.emailAddress, 25);
canAdminCheckbox = new JCheckBox(Translation.get("gb.canAdminDescription"), anUser.canAdmin);
canForkCheckbox = new JCheckBox(Translation.get("gb.canForkDescription"), anUser.canFork);
canCreateCheckbox = new JCheckBox(Translation.get("gb.canCreateDescription"), anUser.canCreate);
notFederatedCheckbox = new JCheckBox(Translation.get("gb.excludeFromFederationDescription"), anUser.excludeFromFederation);
disabledCheckbox = new JCheckBox(Translation.get("gb.disableUserDescription"), anUser.disabled);
organizationalUnitField = new JTextField(anUser.organizationalUnit == null ? "" : anUser.organizationalUnit, 25);
organizationField = new JTextField(anUser.organization == null ? "" : anUser.organization, 25);
localityField = new JTextField(anUser.locality == null ? "" : anUser.locality, 25);
stateProvinceField = new JTextField(anUser.stateProvince == null ? "" : anUser.stateProvince, 25);
countryCodeField = new JTextField(anUser.countryCode == null ? "" : anUser.countryCode, 15);
// credentials are optionally controlled by 3rd-party authentication
usernameField.setEnabled(anUser.isLocalAccount());
passwordField.setEnabled(anUser.isLocalAccount());
confirmPasswordField.setEnabled(anUser.isLocalAccount());
JPanel fieldsPanel = new JPanel(new GridLayout(0, 1));
fieldsPanel.add(newFieldPanel(Translation.get("gb.username"), usernameField));
fieldsPanel.add(newFieldPanel(Translation.get("gb.password"), passwordField));
fieldsPanel.add(newFieldPanel(Translation.get("gb.confirmPassword"), confirmPasswordField));
fieldsPanel.add(newFieldPanel(Translation.get("gb.displayName"), displayNameField));
fieldsPanel.add(newFieldPanel(Translation.get("gb.emailAddress"), emailAddressField));
fieldsPanel.add(newFieldPanel(Translation.get("gb.canAdmin"), canAdminCheckbox));
fieldsPanel.add(newFieldPanel(Translation.get("gb.canFork"), canForkCheckbox));
fieldsPanel.add(newFieldPanel(Translation.get("gb.canCreate"), canCreateCheckbox));
fieldsPanel.add(newFieldPanel(Translation.get("gb.excludeFromFederation"), notFederatedCheckbox));
fieldsPanel.add(newFieldPanel(Translation.get("gb.disableUser"), disabledCheckbox));
JPanel attributesPanel = new JPanel(new GridLayout(0, 1, 5, 2));
attributesPanel.add(newFieldPanel(Translation.get("gb.organizationalUnit") + " (OU)", organizationalUnitField));
attributesPanel.add(newFieldPanel(Translation.get("gb.organization") + " (O)", organizationField));
attributesPanel.add(newFieldPanel(Translation.get("gb.locality") + " (L)", localityField));
attributesPanel.add(newFieldPanel(Translation.get("gb.stateProvince") + " (ST)", stateProvinceField));
attributesPanel.add(newFieldPanel(Translation.get("gb.countryCode") + " (C)", countryCodeField));
final Insets _insets = new Insets(5, 5, 5, 5);
repositoryPalette = new RegistrantPermissionsPanel(RegistrantType.REPOSITORY);
teamsPalette = new JPalette<TeamModel>();
JPanel fieldsPanelTop = new JPanel(new BorderLayout());
fieldsPanelTop.add(fieldsPanel, BorderLayout.NORTH);
JPanel attributesPanelTop = new JPanel(new BorderLayout());
attributesPanelTop.add(attributesPanel, BorderLayout.NORTH);
JPanel repositoriesPanel = new JPanel(new BorderLayout()) {
private static final long serialVersionUID = 1L;
@Override
public Insets getInsets() {
return _insets;
}
};
repositoriesPanel.add(repositoryPalette, BorderLayout.CENTER);
JPanel teamsPanel = new JPanel(new BorderLayout()) {
private static final long serialVersionUID = 1L;
@Override
public Insets getInsets() {
return _insets;
}
};
teamsPanel.add(teamsPalette, BorderLayout.CENTER);
JTabbedPane panel = new JTabbedPane(JTabbedPane.TOP);
panel.addTab(Translation.get("gb.general"), fieldsPanelTop);
panel.addTab(Translation.get("gb.attributes"), attributesPanelTop);
if (protocolVersion > 1) {
panel.addTab(Translation.get("gb.teamMemberships"), teamsPanel);
}
panel.addTab(Translation.get("gb.restrictedRepositories"), repositoriesPanel);
JButton createButton = new JButton(Translation.get("gb.save"));
createButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
if (validateFields()) {
canceled = false;
setVisible(false);
}
}
});
JButton cancelButton = new JButton(Translation.get("gb.cancel"));
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
canceled = true;
setVisible(false);
}
});
JPanel controls = new JPanel();
controls.add(cancelButton);
controls.add(createButton);
JPanel centerPanel = new JPanel(new BorderLayout(5, 5)) {
private static final long serialVersionUID = 1L;
@Override
public Insets getInsets() {
return _insets;
}
};
centerPanel.add(panel, BorderLayout.CENTER);
centerPanel.add(controls, BorderLayout.SOUTH);
getContentPane().setLayout(new BorderLayout(5, 5));
getContentPane().add(centerPanel, BorderLayout.CENTER);
pack();
}
use of com.gitblit.models.TeamModel in project gitblit by gitblit.
the class ConfigUserService method updateTeamModels.
/**
* Updates/writes all specified team objects.
*
* @param models a list of team models
* @return true if update is successful
* @since 1.2.0
*/
@Override
public synchronized boolean updateTeamModels(Collection<TeamModel> models) {
try {
read();
for (TeamModel team : models) {
teams.put(team.name.toLowerCase(), team);
}
write();
return true;
} catch (Throwable t) {
logger.error(MessageFormat.format("Failed to update team {0} models!", models.size()), t);
}
return false;
}
use of com.gitblit.models.TeamModel in project gitblit by gitblit.
the class ConfigUserService method updateTeamModel.
/**
* Updates/writes and replaces a complete team object keyed by teamname.
* This method allows for renaming a team.
*
* @param teamname
* the old teamname
* @param model
* the team object to use for teamname
* @return true if update is successful
* @since 0.8.0
*/
@Override
public synchronized boolean updateTeamModel(String teamname, TeamModel model) {
TeamModel original = null;
try {
read();
original = teams.remove(teamname.toLowerCase());
teams.put(model.name.toLowerCase(), model);
write();
return true;
} catch (Throwable t) {
if (original != null) {
// restore original team
teams.put(original.name.toLowerCase(), original);
} else {
// drop attempted add
teams.remove(model.name.toLowerCase());
}
logger.error(MessageFormat.format("Failed to update team model {0}!", model.name), t);
}
return false;
}
use of com.gitblit.models.TeamModel in project gitblit by gitblit.
the class ConfigUserService method read.
/**
* Reads the realm file and rebuilds the in-memory lookup tables.
*/
protected synchronized void read() {
if (realmFile.exists() && (forceReload || (realmFile.lastModified() != lastModified))) {
forceReload = false;
lastModified = realmFile.lastModified();
users.clear();
cookies.clear();
teams.clear();
try {
StoredConfig config = new FileBasedConfig(realmFile, FS.detect());
config.load();
Set<String> usernames = config.getSubsections(USER);
for (String username : usernames) {
UserModel user = new UserModel(username.toLowerCase());
user.password = config.getString(USER, username, PASSWORD);
user.displayName = config.getString(USER, username, DISPLAYNAME);
user.emailAddress = config.getString(USER, username, EMAILADDRESS);
user.accountType = AccountType.fromString(config.getString(USER, username, ACCOUNTTYPE));
user.disabled = config.getBoolean(USER, username, DISABLED, false);
user.organizationalUnit = config.getString(USER, username, ORGANIZATIONALUNIT);
user.organization = config.getString(USER, username, ORGANIZATION);
user.locality = config.getString(USER, username, LOCALITY);
user.stateProvince = config.getString(USER, username, STATEPROVINCE);
user.countryCode = config.getString(USER, username, COUNTRYCODE);
user.cookie = config.getString(USER, username, COOKIE);
if (StringUtils.isEmpty(user.cookie) && !StringUtils.isEmpty(user.password)) {
user.cookie = user.createCookie();
}
// preferences
user.getPreferences().setLocale(config.getString(USER, username, LOCALE));
user.getPreferences().setEmailMeOnMyTicketChanges(config.getBoolean(USER, username, EMAILONMYTICKETCHANGES, true));
user.getPreferences().setTransport(Transport.fromString(config.getString(USER, username, TRANSPORT)));
// user roles
Set<String> roles = new HashSet<String>(Arrays.asList(config.getStringList(USER, username, ROLE)));
user.canAdmin = roles.contains(Role.ADMIN.getRole());
user.canFork = roles.contains(Role.FORK.getRole());
user.canCreate = roles.contains(Role.CREATE.getRole());
user.excludeFromFederation = roles.contains(Role.NOT_FEDERATED.getRole());
// repository memberships
if (!user.canAdmin) {
// non-admin, read permissions
Set<String> repositories = new HashSet<String>(Arrays.asList(config.getStringList(USER, username, REPOSITORY)));
for (String repository : repositories) {
user.addRepositoryPermission(repository);
}
}
// starred repositories
Set<String> starred = new HashSet<String>(Arrays.asList(config.getStringList(USER, username, STARRED)));
for (String repository : starred) {
UserRepositoryPreferences prefs = user.getPreferences().getRepositoryPreferences(repository);
prefs.starred = true;
}
// update cache
users.put(user.username, user);
if (!StringUtils.isEmpty(user.cookie)) {
cookies.put(user.cookie, user);
}
}
// load the teams
Set<String> teamnames = config.getSubsections(TEAM);
for (String teamname : teamnames) {
TeamModel team = new TeamModel(teamname);
Set<String> roles = new HashSet<String>(Arrays.asList(config.getStringList(TEAM, teamname, ROLE)));
team.canAdmin = roles.contains(Role.ADMIN.getRole());
team.canFork = roles.contains(Role.FORK.getRole());
team.canCreate = roles.contains(Role.CREATE.getRole());
team.accountType = AccountType.fromString(config.getString(TEAM, teamname, ACCOUNTTYPE));
if (!team.canAdmin) {
// non-admin team, read permissions
team.addRepositoryPermissions(Arrays.asList(config.getStringList(TEAM, teamname, REPOSITORY)));
}
team.addUsers(Arrays.asList(config.getStringList(TEAM, teamname, USER)));
team.addMailingLists(Arrays.asList(config.getStringList(TEAM, teamname, MAILINGLIST)));
team.preReceiveScripts.addAll(Arrays.asList(config.getStringList(TEAM, teamname, PRERECEIVE)));
team.postReceiveScripts.addAll(Arrays.asList(config.getStringList(TEAM, teamname, POSTRECEIVE)));
teams.put(team.name.toLowerCase(), team);
// set the teams on the users
for (String user : team.users) {
UserModel model = users.get(user);
if (model != null) {
model.teams.add(team);
}
}
}
} catch (Exception e) {
logger.error(MessageFormat.format("Failed to read {0}", realmFile), e);
}
}
}
Aggregations