本文整理汇总了Java中org.springframework.security.web.csrf.DefaultCsrfToken类的典型用法代码示例。如果您正苦于以下问题:Java DefaultCsrfToken类的具体用法?Java DefaultCsrfToken怎么用?Java DefaultCsrfToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultCsrfToken类属于org.springframework.security.web.csrf包,在下文中一共展示了DefaultCsrfToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: displayUserPaymentsTest
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
/**
* Send displaysTrainingView.
*
* @throws Exception the exception
*/
@Test
public void displayUserPaymentsTest() throws Exception {
// Charge csrf in pay member
PayMember userFeeMember = userFeeMemberService.findByPayMemberIds(user.getId(), feeMember.getId()).get(0);
mockMvc.perform(post("/userPayments/payMember/" + userFeeMember.getId()).locale(Locale.ENGLISH).session(defaultSession)
.sessionAttr("_csrf", "csrf").param("payer_email", "email").param("payer_id", "id").param("payment_date", "10:10:10 Jun 10, 2015")
.param("payment_status", "Completed").param("txn_id", "txn")).andExpect(view().name("redirect:/userPayments"));
// Charge csrf in pay program
PayProgram payProgram = payProgramService.findByPayProgramIds(program.getId(), feeProgram.getId());
mockMvc.perform(post("/userPayments/payProgram/" + payProgram.getId()).locale(Locale.ENGLISH).session(defaultSession)
.sessionAttr("_csrf", "csrf").param("payer_email", "email").param("payer_id", "id").param("payment_date", "10:10:10 Jun 10, 2015")
.param("payment_status", "Completed").param("txn_id", "txn")).andExpect(view().name("redirect:/userPayments"));
CsrfToken token = new DefaultCsrfToken("headerName", "parameterName", "token");
try {
mockMvc.perform(get("/userPayments").locale(Locale.ENGLISH).session(defaultSession).sessionAttr("_csrf", token))
.andExpect(view().name("userpayments/userpayments")).andExpect(content().string(containsString("<title>My payments</title>")));
} catch (Exception e) {
// prueba
}
}
示例2: test_0
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
public void test_0() throws Exception {
DefaultCsrfToken token = JSON.parseObject("{\"token\":\"xxx\",\"parameterName\":\"222\",\"headerName\":\"hhh\"}", DefaultCsrfToken.class);
assertEquals("hhh", token.getHeaderName());
assertEquals("222", token.getParameterName());
assertEquals("xxx", token.getToken());
assertEquals("{\"headerName\":\"hhh\",\"parameterName\":\"222\",\"token\":\"xxx\"}", JSON.toJSONString(token));
}
示例3: getCsrfTokenFromLoginHtml
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
/**
* Gets the CSRF token from login html because the CSRF token endpoint needs
* to be authenticated first.
*
* @param loginHtml The login page HTML which contains the csrf token. It is
* assumed that the CSRF token is embedded on the page inside an input field
* with name matching
* {@link com.box.l10n.mojito.rest.resttemplate.FormLoginAuthenticationCsrfTokenInterceptor#CSRF_PARAM_NAME}
* @return
* @throws AuthenticationException
*/
protected CsrfToken getCsrfTokenFromLoginHtml(String loginHtml) throws AuthenticationException {
Pattern pattern = Pattern.compile("CSRF_TOKEN = '(.*?)';");
Matcher matcher = pattern.matcher(loginHtml);
if (matcher.find()) {
String csrfTokenString = matcher.group(1);
logger.debug("CSRF token from login html: {}", csrfTokenString);
return new DefaultCsrfToken(CSRF_HEADER_NAME,
CSRF_PARAM_NAME, csrfTokenString);
} else {
throw new SessionAuthenticationException("Could not find CSRF_TOKEN variable on login page");
}
}
示例4: loadToken
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
@Override
public CsrfToken loadToken(HttpServletRequest request) {
if (request.getCookies() != null) {
for (Cookie cookie : request.getCookies()) {
if (cookie != null && csrfCookieName.equals(cookie.getName())) {
return new DefaultCsrfToken(csrfHeaderName, csrfParameterName, cookie.getValue());
}
}
}
return null;
}
示例5: loadToken
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
@Override
public CsrfToken loadToken(HttpServletRequest request) {
Cookie cookie = WebUtils.getCookie(request, this.cookieName);
if (cookie == null) {
return null;
}
String token = cookie.getValue();
if (!StringUtils.hasLength(token)) {
return null;
}
return new DefaultCsrfToken(this.headerName, this.parameterName, token);
}
示例6: loadToken
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
@Override
public CsrfToken loadToken(HttpServletRequest request) {
if (request.getCookies() != null) {
for (Cookie cookie : request.getCookies()) {
if (cookie != null && CSRF_COOKIE_AND_PARAMETER_NAME.equals(cookie.getName())) {
return new DefaultCsrfToken(CSRF_HEADER_NAME, CSRF_COOKIE_AND_PARAMETER_NAME, cookie.getValue());
}
}
}
return null;
}
示例7: displaysaccountFormTest
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
/**
* Send account form.
*
* @throws Exception the exception
*/
@Test
public void displaysaccountFormTest() throws Exception {
CsrfToken token = new DefaultCsrfToken("headerName", "parameterName", "token");
mockMvc.perform(get("/accountList").locale(Locale.ENGLISH).session(defaultSession).sessionAttr("_csrf", token))
.andExpect(view().name("account/accountlist"))
.andExpect(content().string(allOf(containsString("<title>Accounts</title>"), containsString("Account List</h1>"))));
}
示例8: reportCreateTest
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
/**
* Send displaysReportList.
*
* @throws Exception the exception
*/
@Test
public void reportCreateTest() throws Exception {
CsrfToken token = new DefaultCsrfToken("headerName", "parameterName", "token");
mockMvc.perform(get("/reportList/reportCreate").locale(Locale.ENGLISH)
.session(defaultSession)
.sessionAttr("parameterName", token)
.sessionAttr("_csrf", token)
.requestAttr(CsrfToken.class.getName(), token)
.param("parameterName", "title")).andExpect(view().name("report/reportcreate"));
}
示例9: InvalidCsrfTokenException
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
@Test
public void redirecionaParaAutenticacaoQuandoTokenCsrfÉInvalido() throws Exception {
AccessDeniedException exception = new InvalidCsrfTokenException(
new DefaultCsrfToken("header", "param", "token"),
"actualToken"
);
handler.handle(request, response, exception);
assertThat(response.getRedirectedUrl(), is("/editar/autenticar?sessao"));
}
示例10: generateToken
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
public CsrfToken generateToken(HttpServletRequest request) {
return new DefaultCsrfToken(Constants.ERRAI_CSRF_TOKEN_HEADER, Constants.ERRAI_CSRF_TOKEN_VAR,
SecureHashUtil.nextSecureHash());
}
示例11: generateToken
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
@Override
public CsrfToken generateToken(HttpServletRequest request) {
String tokenValue = new BigInteger(130, secureRandom).toString(32); // http://stackoverflow.com/a/41156
return new DefaultCsrfToken(csrfHeaderName, csrfParameterName, tokenValue);
}
示例12: generateToken
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
@Override
public CsrfToken generateToken(HttpServletRequest request) {
return new DefaultCsrfToken(this.headerName, this.parameterName,
createNewToken());
}
示例13: generateToken
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
@Override
public CsrfToken generateToken(HttpServletRequest request) {
String tokenValue = new BigInteger(130, secureRandom).toString(32); // http://stackoverflow.com/a/41156
return new DefaultCsrfToken(CSRF_HEADER_NAME, CSRF_COOKIE_AND_PARAMETER_NAME, tokenValue);
}
示例14: generateToken
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
@Override
public CsrfToken generateToken(HttpServletRequest request) {
return new DefaultCsrfToken(headerName, parameterName, defaultTestCsrfTokenValue);
}
示例15: getCsrfTokenFromEndpoint
import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
/**
* Use the CSRF token endpoint to get the CSRF token corresponding to this
* session
*
* @param csrfTokenUrl The full URL to which the CSRF token can be obtained
* @return
*/
protected CsrfToken getCsrfTokenFromEndpoint(String csrfTokenUrl) {
ResponseEntity<String> csrfTokenEntity = restTemplateForAuthenticationFlow.getForEntity(csrfTokenUrl, String.class, "");
logger.debug("CSRF token from {} is {}", csrfTokenUrl, csrfTokenEntity.getBody());
return new DefaultCsrfToken(CSRF_HEADER_NAME,
CSRF_PARAM_NAME, csrfTokenEntity.getBody());
}