File was renamed from src/main/java/com/gitblit/WindowsUserService.java |
| | |
| | | * See the License for the specific language governing permissions and
|
| | | * limitations under the License.
|
| | | */
|
| | | package com.gitblit;
|
| | | package com.gitblit.auth; |
| | |
|
| | | import java.io.File;
|
| | | import java.util.Set;
|
| | | import java.util.TreeSet;
|
| | |
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | import waffle.windows.auth.IWindowsAccount;
|
| | | import waffle.windows.auth.IWindowsAuthProvider;
|
| | |
| | | import waffle.windows.auth.IWindowsIdentity;
|
| | | import waffle.windows.auth.impl.WindowsAuthProviderImpl;
|
| | |
|
| | | import com.gitblit.Constants; |
| | | import com.gitblit.Constants.AccountType;
|
| | | import com.gitblit.manager.IRuntimeManager;
|
| | | import com.gitblit.Keys; |
| | | import com.gitblit.auth.AuthenticationProvider.UsernamePasswordAuthenticationProvider; |
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.ArrayUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.sun.jna.platform.win32.Win32Exception;
|
| | |
|
| | | /**
|
| | | * Implementation of a Windows user service.
|
| | | * Implementation of a Windows authentication provider. |
| | | *
|
| | | * @author James Moger
|
| | | */
|
| | | public class WindowsUserService extends GitblitUserService {
|
| | |
|
| | | private final Logger logger = LoggerFactory.getLogger(WindowsUserService.class);
|
| | |
|
| | | private IStoredSettings settings;
|
| | | public class WindowsAuthProvider extends UsernamePasswordAuthenticationProvider { |
| | |
|
| | | private IWindowsAuthProvider waffle;
|
| | |
|
| | | public WindowsUserService() {
|
| | | super();
|
| | | public WindowsAuthProvider() { |
| | | super("windows"); |
| | | }
|
| | |
|
| | | @Override
|
| | | public void setup(IRuntimeManager runtimeManager) {
|
| | | this.settings = runtimeManager.getSettings();
|
| | |
|
| | | String file = settings.getString(Keys.realm.windows.backingUserService, "${baseFolder}/users.conf");
|
| | | File realmFile = runtimeManager.getFileOrFolder(file);
|
| | |
|
| | | serviceImpl = createUserService(realmFile);
|
| | | logger.info("Windows User Service backed by " + serviceImpl.toString());
|
| | | public void setup() { |
| | |
|
| | | waffle = new WindowsAuthProviderImpl();
|
| | | IWindowsComputer computer = waffle.getCurrentComputer();
|
| | | logger.info("Windows Authentication Provider"); |
| | | logger.info(" name = " + computer.getComputerName());
|
| | | logger.info(" status = " + describeJoinStatus(computer.getJoinStatus()));
|
| | | logger.info(" memberOf = " + computer.getMemberOf());
|
| | |
| | |
|
| | | @Override
|
| | | public UserModel authenticate(String username, char[] password) {
|
| | | if (isLocalAccount(username)) {
|
| | | // local account, bypass Windows authentication
|
| | | return super.authenticate(username, password);
|
| | | }
|
| | |
|
| | | String defaultDomain = settings.getString(Keys.realm.windows.defaultDomain, null);
|
| | | if (StringUtils.isEmpty(defaultDomain)) {
|
| | | // ensure that default domain is null
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | UserModel user = getUserModel(username);
|
| | | UserModel user = userManager.getUserModel(username); |
| | | if (user == null) // create user object for new authenticated user
|
| | | user = new UserModel(username.toLowerCase());
|
| | |
|
| | |
| | | // TODO consider mapping Windows groups to teams
|
| | |
|
| | | // push the changes to the backing user service
|
| | | super.updateUserModel(user);
|
| | |
|
| | | updateUser(user); |
| | |
|
| | | // cleanup resources
|
| | | identity.dispose();
|