当前位置: 首页>>代码示例>>Java>>正文


Java DefaultCsrfToken类代码示例

本文整理汇总了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
	}
}
 
开发者ID:pablogrela,项目名称:members_cuacfm,代码行数:29,代码来源:UserPaymentsTest.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:DefaultSavedRequestTest.java

示例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");
    }
}
 
开发者ID:box,项目名称:mojito,代码行数:26,代码来源:FormLoginAuthenticationCsrfTokenInterceptor.java

示例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;
}
 
开发者ID:AusDTO,项目名称:spring-security-stateless,代码行数:12,代码来源:CookieCsrfTokenRepository.java

示例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);
}
 
开发者ID:lordoftheflies,项目名称:wonderjameeee,代码行数:13,代码来源:BackendCookieCsrfTokenRepository.java

示例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;
}
 
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:12,代码来源:CookieBasedCsrfTokenRepository.java

示例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>"))));
}
 
开发者ID:pablogrela,项目名称:members_cuacfm,代码行数:13,代码来源:AccountListControllerTest.java

示例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"));
}
 
开发者ID:pablogrela,项目名称:members_cuacfm,代码行数:16,代码来源:ReportListControllerTest.java

示例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"));
}
 
开发者ID:servicosgovbr,项目名称:editor-de-servicos,代码行数:12,代码来源:CustomAccessDeniedHandlerTest.java

示例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());
}
 
开发者ID:expansel,项目名称:errai-spring-server,代码行数:5,代码来源:ErraiCsrfTokenRepository.java

示例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);
}
 
开发者ID:AusDTO,项目名称:spring-security-stateless,代码行数:6,代码来源:CookieCsrfTokenRepository.java

示例12: generateToken

import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
@Override
public CsrfToken generateToken(HttpServletRequest request) {
    return new DefaultCsrfToken(this.headerName, this.parameterName,
            createNewToken());
}
 
开发者ID:lordoftheflies,项目名称:wonderjameeee,代码行数:6,代码来源:BackendCookieCsrfTokenRepository.java

示例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);
}
 
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:6,代码来源:CookieBasedCsrfTokenRepository.java

示例14: generateToken

import org.springframework.security.web.csrf.DefaultCsrfToken; //导入依赖的package包/类
@Override
public CsrfToken generateToken(HttpServletRequest request) {
	return new DefaultCsrfToken(headerName, parameterName, defaultTestCsrfTokenValue);
}
 
开发者ID:Appverse,项目名称:appverse-server,代码行数:5,代码来源:TestCsrfTokenRepository.java

示例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());
}
 
开发者ID:box,项目名称:mojito,代码行数:14,代码来源:FormLoginAuthenticationCsrfTokenInterceptor.java


注:本文中的org.springframework.security.web.csrf.DefaultCsrfToken类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。