Java 类org.springframework.security.web.csrf.DefaultCsrfToken 实例源码

项目:members_cuacfm    文件:UserPaymentsTest.java   
/**
 * 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
    }
}
项目:GitHub    文件:DefaultSavedRequestTest.java   
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));
}
项目:mojito    文件:FormLoginAuthenticationCsrfTokenInterceptor.java   
/**
 * 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");
    }
}
项目:spring-security-stateless    文件:CookieCsrfTokenRepository.java   
@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;
}
项目:wonderjameeee    文件:BackendCookieCsrfTokenRepository.java   
@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);
}
项目:citizenship-appointment-server    文件:CookieBasedCsrfTokenRepository.java   
@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;
}
项目:members_cuacfm    文件:AccountListControllerTest.java   
/**
 * 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>"))));
}
项目:members_cuacfm    文件:ReportListControllerTest.java   
/**
* 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"));
}
项目:editor-de-servicos    文件:CustomAccessDeniedHandlerTest.java   
@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"));
}
项目:errai-spring-server    文件:ErraiCsrfTokenRepository.java   
public CsrfToken generateToken(HttpServletRequest request) {
    return new DefaultCsrfToken(Constants.ERRAI_CSRF_TOKEN_HEADER, Constants.ERRAI_CSRF_TOKEN_VAR,
            SecureHashUtil.nextSecureHash());
}
项目:spring-security-stateless    文件:CookieCsrfTokenRepository.java   
@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);
}
项目:wonderjameeee    文件:BackendCookieCsrfTokenRepository.java   
@Override
public CsrfToken generateToken(HttpServletRequest request) {
    return new DefaultCsrfToken(this.headerName, this.parameterName,
            createNewToken());
}
项目:citizenship-appointment-server    文件:CookieBasedCsrfTokenRepository.java   
@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);
}
项目:appverse-server    文件:TestCsrfTokenRepository.java   
@Override
public CsrfToken generateToken(HttpServletRequest request) {
    return new DefaultCsrfToken(headerName, parameterName, defaultTestCsrfTokenValue);
}
项目:mojito    文件:FormLoginAuthenticationCsrfTokenInterceptor.java   
/**
 * 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());
}
项目:para    文件:CachedCsrfTokenRepository.java   
/**
 * Generates a CSRF token string.
 * @param request HTTP request
 * @return a new token
 */
public CsrfToken generateToken(HttpServletRequest request) {
    return new DefaultCsrfToken(headerName, parameterName, Utils.generateSecurityToken());
}