use of org.apache.wicket.protocol.http.WebRequest in project gitblit by gitblit.
the class RepositoryUrlPanel method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest();
List<RepositoryUrl> repositoryUrls = app().services().getRepositoryUrls(req, user, repository);
// grab primary url from the top of the list
primaryUrl = repositoryUrls.size() == 0 ? null : repositoryUrls.get(0);
boolean canClone = primaryUrl != null && (!primaryUrl.hasPermission() || primaryUrl.permission.atLeast(AccessPermission.CLONE));
if (repositoryUrls.size() == 0 || !canClone) {
// no urls, nothing to show.
add(new Label("repositoryUrlPanel").setVisible(false));
add(new Label("applicationMenusPanel").setVisible(false));
add(new Label("repositoryIndicators").setVisible(false));
return;
}
// display primary url
add(createPrimaryUrlPanel("repositoryUrlPanel", repository, repositoryUrls));
if (onlyUrls) {
add(new Label("repositoryIndicators").setVisible(false));
} else {
add(createRepositoryIndicators(repository));
}
boolean allowAppLinks = app().settings().getBoolean(Keys.web.allowAppCloneLinks, true);
if (onlyUrls || !canClone || !allowAppLinks) {
// only display the url(s)
add(new Label("applicationMenusPanel").setVisible(false));
return;
}
// create the git client application menus
add(createApplicationMenus("applicationMenusPanel", user, repository, repositoryUrls));
}
use of org.apache.wicket.protocol.http.WebRequest in project gitblit by gitblit.
the class TicketPage method getRepositoryUrl.
/**
* Returns the primary repository url
*
* @param user
* @param repository
* @return the primary repository url
*/
protected RepositoryUrl getRepositoryUrl(UserModel user, RepositoryModel repository) {
HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest();
List<RepositoryUrl> urls = app().services().getRepositoryUrls(req, user, repository);
if (ArrayUtils.isEmpty(urls)) {
return null;
}
RepositoryUrl primary = urls.get(0);
return primary;
}
use of org.apache.wicket.protocol.http.WebRequest in project gitblit by gitblit.
the class RootPage method loginUser.
private void loginUser(UserModel user) {
if (user != null) {
HttpServletRequest request = ((WebRequest) getRequest()).getHttpServletRequest();
HttpServletResponse response = ((WebResponse) getResponse()).getHttpServletResponse();
// Set the user into the session
GitBlitWebSession session = GitBlitWebSession.get();
// issue 62: fix session fixation vulnerability
session.replaceSession();
session.setUser(user);
request = ((WebRequest) getRequest()).getHttpServletRequest();
response = ((WebResponse) getResponse()).getHttpServletResponse();
request.getSession().setAttribute(Constants.ATTRIB_AUTHTYPE, AuthenticationType.CREDENTIALS);
// Set Cookie
app().authentication().setCookie(request, response, user);
if (!session.continueRequest()) {
PageParameters params = getPageParameters();
if (params == null) {
// redirect to this page
redirectTo(getClass());
} else {
// Strip username and password and redirect to this page
params.remove("username");
params.remove("password");
redirectTo(getClass(), params);
}
}
}
}
use of org.apache.wicket.protocol.http.WebRequest in project gitblit by gitblit.
the class SessionPage method login.
private void login() {
GitBlitWebSession session = GitBlitWebSession.get();
HttpServletRequest request = ((WebRequest) getRequest()).getHttpServletRequest();
HttpServletResponse response = ((WebResponse) getResponse()).getHttpServletResponse();
// If using container/external servlet authentication, use request attribute
String authedUser = (String) request.getAttribute(Constants.ATTRIB_AUTHUSER);
// Default to trusting session authentication if not set in request by external processing
if (StringUtils.isEmpty(authedUser) && session.isLoggedIn()) {
authedUser = session.getUsername();
}
if (!StringUtils.isEmpty(authedUser)) {
// the old session entirely, without trusting any session values
if (!authedUser.equals(session.getUsername())) {
session.replaceSession();
}
if (!session.isSessionInvalidated()) {
// Refresh usermodel to pick up any changes to permissions or roles (issue-186)
UserModel user = app().users().getUserModel(authedUser);
if (user == null || user.disabled) {
// user was deleted/disabled during session
app().authentication().logout(request, response, user);
session.setUser(null);
session.invalidateNow();
return;
}
// validate cookie during session (issue-361)
if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, true)) {
String requestCookie = app().authentication().getCookie(request);
if (!StringUtils.isEmpty(requestCookie) && !StringUtils.isEmpty(user.cookie)) {
if (!requestCookie.equals(user.cookie)) {
// cookie was changed during our session
app().authentication().logout(request, response, user);
session.setUser(null);
session.invalidateNow();
return;
}
}
}
session.setUser(user);
session.continueRequest();
return;
}
}
// try to authenticate by servlet request
UserModel user = app().authentication().authenticate(request);
// Login the user
if (user != null) {
AuthenticationType authenticationType = (AuthenticationType) request.getAttribute(Constants.ATTRIB_AUTHTYPE);
// don't like
if (AuthenticationType.CONTAINER != authenticationType) {
session.replaceSession();
}
session.setUser(user);
// Set Cookie
app().authentication().setCookie(request, response, user);
session.continueRequest();
}
}
Aggregations