本文整理汇总了Java中org.kohsuke.stapler.HttpResponses.redirectTo方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponses.redirectTo方法的具体用法?Java HttpResponses.redirectTo怎么用?Java HttpResponses.redirectTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kohsuke.stapler.HttpResponses
的用法示例。
在下文中一共展示了HttpResponses.redirectTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFinishLogin
import org.kohsuke.stapler.HttpResponses; //导入方法依赖的package包/类
public HttpResponse doFinishLogin(StaplerRequest request, StaplerResponse rsp) throws IOException {
String code = request.getParameter("code");
if (code == null || code.trim().length() == 0) {
Log.info("doFinishLogin: missing code.");
return HttpResponses.redirectToContextRoot();
}
String content = postForAccessToken(code);
String accessToken = extractToken(content);
updateOfflineAccessTokenForUser(accessToken);
request.getSession().setAttribute("access_token", accessToken);
String newProjectSetupUrl = getJenkinsRootUrl() + "/" + GithubReposController.URL;
return HttpResponses.redirectTo(newProjectSetupUrl);
}
示例2: doFinishLogin
import org.kohsuke.stapler.HttpResponses; //导入方法依赖的package包/类
public HttpResponse doFinishLogin(StaplerRequest request) throws IOException {
String code = request.getParameter("code");
if (StringUtils.isBlank(code)) {
LOGGER.log(Level.SEVERE, "doFinishLogin() code = null");
return HttpResponses.redirectToContextRoot();
}
DeepinToken token = new DeepinOAuthApiService(clientID, clientSecret).getTokenByAuthorizationCode(code);
if (!token.accessToken.isEmpty()) {
DeepinAuthenticationToken auth = new DeepinAuthenticationToken(token, clientID, clientSecret);
SecurityContextHolder.getContext().setAuthentication(auth);
User u = User.current();
u.setFullName(auth.getName());
} else {
LOGGER.log(Level.SEVERE, "doFinishLogin() accessToken = null");
}
// redirect to referer
String referer = (String) request.getSession().getAttribute(REFERER_ATTRIBUTE);
if (referer != null) {
return HttpResponses.redirectTo(referer);
} else {
return HttpResponses.redirectToContextRoot();
}
}
示例3: doFinishLogin
import org.kohsuke.stapler.HttpResponses; //导入方法依赖的package包/类
/**
* This is where the user comes back to at the end of the OpenID redirect
* ping-pong.
*
* @throws HttpFailure
* @throws VerificationException
*/
public HttpResponse doFinishLogin(StaplerRequest request) {
String redirect = redirectUrl(request);
try {
AccessTokenResponse tokenResponse = ServerRequest.invokeAccessCodeToToken(getKeycloakDeployment(),
request.getParameter("code"), redirect, null);
String tokenString = tokenResponse.getToken();
String idTokenString = tokenResponse.getIdToken();
String refreashToken = tokenResponse.getRefreshToken();
AccessToken token = AdapterRSATokenVerifier.verifyToken(tokenString, getKeycloakDeployment());
if (idTokenString != null) {
JWSInput input = new JWSInput(idTokenString);
IDToken idToken = input.readJsonContent(IDToken.class);
SecurityContextHolder.getContext()
.setAuthentication(new KeycloakAuthentication(idToken, token, refreashToken));
User currentUser = User.current();
if (currentUser != null) {
currentUser.setFullName(idToken.getPreferredUsername());
if (!currentUser.getProperty(Mailer.UserProperty.class).hasExplicitlyConfiguredAddress()) {
currentUser.addProperty(new Mailer.UserProperty(idToken.getEmail()));
}
}
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Authentication Exception ", e);
}
String referer = (String) request.getSession().getAttribute(REFERER_ATTRIBUTE);
if (referer != null) {
return HttpResponses.redirectTo(referer);
}
return HttpResponses.redirectToContextRoot();
}