| | |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import javax.inject.Inject; |
| | | import javax.servlet.http.Cookie; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | import com.gitblit.Constants; |
| | | import com.gitblit.Constants.AccountType; |
| | | import com.gitblit.Constants.AuthenticationType; |
| | | import com.gitblit.Constants.Role; |
| | | import com.gitblit.IStoredSettings; |
| | | import com.gitblit.Keys; |
| | | import com.gitblit.auth.AuthenticationProvider; |
| | |
| | | import com.gitblit.utils.StringUtils; |
| | | import com.gitblit.utils.X509Utils.X509Metadata; |
| | | import com.gitblit.wicket.GitBlitWebSession; |
| | | import com.google.inject.Inject; |
| | | import com.google.inject.Singleton; |
| | | |
| | | /** |
| | | * The authentication manager handles user login & logout. |
| | |
| | | * @author James Moger |
| | | * |
| | | */ |
| | | @Singleton |
| | | public class AuthenticationManager implements IAuthenticationManager { |
| | | |
| | | private final Logger logger = LoggerFactory.getLogger(getClass()); |
| | |
| | | * @param user |
| | | */ |
| | | @Override |
| | | @Deprecated |
| | | public void setCookie(HttpServletResponse response, UserModel user) { |
| | | setCookie(null, response, user); |
| | | } |
| | | |
| | | /** |
| | | * Sets a cookie for the specified user. |
| | | * |
| | | * @param request |
| | | * @param response |
| | | * @param user |
| | | */ |
| | | @Override |
| | | public void setCookie(HttpServletRequest request, HttpServletResponse response, UserModel user) { |
| | | if (settings.getBoolean(Keys.web.allowCookieAuthentication, true)) { |
| | | GitBlitWebSession session = GitBlitWebSession.get(); |
| | | boolean standardLogin = session.authenticationType.isStandard(); |
| | |
| | | userCookie.setMaxAge((int) TimeUnit.DAYS.toSeconds(7)); |
| | | } |
| | | } |
| | | userCookie.setPath("/"); |
| | | String path = "/"; |
| | | if (request != null) { |
| | | if (!StringUtils.isEmpty(request.getContextPath())) { |
| | | path = request.getContextPath(); |
| | | } |
| | | } |
| | | userCookie.setPath(path); |
| | | response.addCookie(userCookie); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * Logout a user. |
| | | * |
| | | * @param response |
| | | * @param user |
| | | */ |
| | | @Override |
| | | @Deprecated |
| | | public void logout(HttpServletResponse response, UserModel user) { |
| | | setCookie(response, null); |
| | | setCookie(null, response, null); |
| | | } |
| | | |
| | | /** |
| | | * Logout a user. |
| | | * |
| | | * @param request |
| | | * @param response |
| | | * @param user |
| | | */ |
| | | @Override |
| | | public void logout(HttpServletRequest request, HttpServletResponse response, UserModel user) { |
| | | setCookie(request, response, null); |
| | | } |
| | | |
| | | /** |
| | |
| | | return (team != null && team.isLocalTeam()) || findProvider(team).supportsTeamMembershipChanges(); |
| | | } |
| | | |
| | | /** |
| | | * Returns true if the user's role can be changed. |
| | | * |
| | | * @param user |
| | | * @return true if the user's role can be changed |
| | | */ |
| | | @Override |
| | | public boolean supportsRoleChanges(UserModel user, Role role) { |
| | | return (user != null && user.isLocalAccount()) || findProvider(user).supportsRoleChanges(user, role); |
| | | } |
| | | |
| | | /** |
| | | * Returns true if the team's role can be changed. |
| | | * |
| | | * @param user |
| | | * @return true if the team's role can be changed |
| | | */ |
| | | @Override |
| | | public boolean supportsRoleChanges(TeamModel team, Role role) { |
| | | return (team != null && team.isLocalTeam()) || findProvider(team).supportsRoleChanges(team, role); |
| | | } |
| | | |
| | | protected AuthenticationProvider findProvider(UserModel user) { |
| | | for (AuthenticationProvider provider : authenticationProviders) { |
| | | if (provider.getAccountType().equals(user.accountType)) { |