use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class AuthenticationProvider method updateUser.
protected void updateUser(UserModel userModel) {
final UserModel userLocalDB = userManager.getUserModel(userModel.getName());
// Establish the checksum of the current version of the user
final BigInteger userCurrentCheck = DeepCopier.checksum(userModel);
// Establish the checksum of the stored version of the user
final BigInteger userLocalDBcheck = DeepCopier.checksum(userLocalDB);
// Compare the checksums
if (!userCurrentCheck.equals(userLocalDBcheck)) {
// If mismatch, save the new instance.
userManager.updateUserModel(userModel);
}
}
use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class HtpasswdAuthProvider method authenticate.
/**
* Authenticate a user based on a username and password.
*
* If the account is determined to be a local account, authentication
* will be done against the locally stored password.
* Otherwise, the configured htpasswd file is read. All current output options
* of htpasswd are supported: clear text, crypt(), Apache MD5 and unsalted SHA-1.
*
* @param username
* @param password
* @return a user object or null
*/
@Override
public UserModel authenticate(String username, char[] password) {
read();
String storedPwd = htUsers.get(username);
if (storedPwd != null) {
boolean authenticated = false;
final String passwd = new String(password);
// test Apache MD5 variant encrypted password
if (storedPwd.startsWith("$apr1$")) {
if (storedPwd.equals(Md5Crypt.apr1Crypt(passwd, storedPwd))) {
logger.debug("Apache MD5 encoded password matched for user '" + username + "'");
authenticated = true;
}
} else // test unsalted SHA password
if (storedPwd.startsWith("{SHA}")) {
String passwd64 = Base64.encodeBase64String(DigestUtils.sha1(passwd));
if (storedPwd.substring("{SHA}".length()).equals(passwd64)) {
logger.debug("Unsalted SHA-1 encoded password matched for user '" + username + "'");
authenticated = true;
}
} else // test libc crypt() encoded password
if (supportCryptPwd() && storedPwd.equals(Crypt.crypt(passwd, storedPwd))) {
logger.debug("Libc crypt encoded password matched for user '" + username + "'");
authenticated = true;
} else // test clear text
if (supportPlaintextPwd() && storedPwd.equals(passwd)) {
logger.debug("Clear text password matched for user '" + username + "'");
authenticated = true;
}
if (authenticated) {
logger.debug("Htpasswd authenticated: " + username);
UserModel curr = userManager.getUserModel(username);
UserModel user;
if (curr == null) {
// create user object for new authenticated user
user = new UserModel(username);
} else {
user = curr;
}
// create a user cookie
setCookie(user);
// Set user attributes, hide password from backing user service.
user.password = Constants.EXTERNAL_ACCOUNT;
user.accountType = getAccountType();
// Push the looked up values to backing file
updateUser(user);
return user;
}
}
return null;
}
use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class LdapAuthProvider method sync.
public synchronized void sync() {
final boolean enabled = settings.getBoolean(Keys.realm.ldap.synchronize, false);
if (enabled) {
logger.info("Synchronizing with LDAP @ " + settings.getRequiredString(Keys.realm.ldap.server));
final boolean deleteRemovedLdapUsers = settings.getBoolean(Keys.realm.ldap.removeDeletedUsers, true);
LdapConnection ldapConnection = new LdapConnection(settings);
if (ldapConnection.connect()) {
if (ldapConnection.bind() == null) {
ldapConnection.close();
logger.error("Cannot synchronize with LDAP.");
return;
}
try {
String uidAttribute = settings.getString(Keys.realm.ldap.uid, "uid");
String accountBase = ldapConnection.getAccountBase();
String accountPattern = ldapConnection.getAccountPattern();
accountPattern = StringUtils.replace(accountPattern, "${username}", "*");
SearchResult result = doSearch(ldapConnection, accountBase, accountPattern);
if (result != null && result.getEntryCount() > 0) {
final Map<String, UserModel> ldapUsers = new HashMap<String, UserModel>();
for (SearchResultEntry loggingInUser : result.getSearchEntries()) {
Attribute uid = loggingInUser.getAttribute(uidAttribute);
if (uid == null) {
logger.error("Can not synchronize with LDAP, missing \"{}\" attribute", uidAttribute);
continue;
}
final String username = uid.getValue();
logger.debug("LDAP synchronizing: " + username);
UserModel user = userManager.getUserModel(username);
if (user == null) {
user = new UserModel(username);
}
if (!supportsTeamMembershipChanges()) {
getTeamsFromLdap(ldapConnection, username, loggingInUser, user);
}
// Get User Attributes
setUserAttributes(user, loggingInUser);
// store in map
ldapUsers.put(username.toLowerCase(), user);
}
if (deleteRemovedLdapUsers) {
logger.debug("detecting removed LDAP users...");
for (UserModel userModel : userManager.getAllUsers()) {
if (AccountType.LDAP == userModel.accountType) {
if (!ldapUsers.containsKey(userModel.username)) {
logger.info("deleting removed LDAP user " + userModel.username + " from user service");
userManager.deleteUser(userModel.username);
}
}
}
}
userManager.updateUserModels(ldapUsers.values());
if (!supportsTeamMembershipChanges()) {
final Map<String, TeamModel> userTeams = new HashMap<String, TeamModel>();
for (UserModel user : ldapUsers.values()) {
for (TeamModel userTeam : user.teams) {
// Is this an administrative team?
setAdminAttribute(userTeam);
userTeams.put(userTeam.name, userTeam);
}
}
userManager.updateTeamModels(userTeams.values());
}
}
if (!supportsTeamMembershipChanges()) {
getEmptyTeamsFromLdap(ldapConnection);
}
} finally {
ldapConnection.close();
}
}
}
}
use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class SalesforceAuthProvider method authenticate.
@Override
public UserModel authenticate(String username, char[] password) {
ConnectorConfig config = new ConnectorConfig();
config.setUsername(username);
config.setPassword(new String(password));
try {
PartnerConnection connection = Connector.newConnection(config);
GetUserInfoResult info = connection.getUserInfo();
String org = settings.getString(Keys.realm.salesforce.orgId, "0").trim();
if (!org.equals("0")) {
if (!org.equals(info.getOrganizationId())) {
logger.warn("Access attempted by user of an invalid org: " + info.getUserName() + ", org: " + info.getOrganizationName() + "(" + info.getOrganizationId() + ")");
return null;
}
}
logger.info("Authenticated user " + info.getUserName() + " using org " + info.getOrganizationName() + "(" + info.getOrganizationId() + ")");
String simpleUsername = getSimpleUsername(info);
UserModel user = null;
synchronized (this) {
user = userManager.getUserModel(simpleUsername);
if (user == null) {
user = new UserModel(simpleUsername);
}
setCookie(user);
setUserAttributes(user, info);
updateUser(user);
}
return user;
} catch (ConnectionException e) {
logger.error("Failed to authenticate", e);
}
return null;
}
use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class RpcTests method findUser.
private UserModel findUser(String name) throws IOException {
List<UserModel> users = RpcUtils.getUsers(url, account, password.toCharArray());
UserModel retrievedUser = null;
for (UserModel model : users) {
if (model.username.equalsIgnoreCase(name)) {
retrievedUser = model;
break;
}
}
return retrievedUser;
}
Aggregations