List of usage examples for org.springframework.http HttpMethod PATCH
HttpMethod PATCH
To view the source code for org.springframework.http HttpMethod PATCH.
Click Source Link
From source file:com.netflix.genie.web.security.SecurityUtils.java
/** * Build the common API HTTP security.//from ww w . j a v a 2s.com * * @param http The http security object to use * @param x509UserDetailsService The x509 authentication user details service to use * @param actuatorEndpoint The endpoint where the Spring Actuator sits * @throws Exception when there is a problem configuring HTTP errors */ public static void buildAPIHttpSecurity(@NotNull final HttpSecurity http, @NotNull final X509UserDetailsService x509UserDetailsService, @NotBlank final String actuatorEndpoint) throws Exception { // @formatter:off http // .regexMatcher("(/api/.*)|(" + actuatorEndpoint + ")/(?!health).*") .regexMatcher("(/api/.*)").authorizeRequests() .regexMatchers(HttpMethod.DELETE, APPLICATIONS_API_REGEX).hasRole(ADMIN_ROLE) .regexMatchers(HttpMethod.PATCH, APPLICATIONS_API_REGEX).hasRole(ADMIN_ROLE) .regexMatchers(HttpMethod.POST, APPLICATIONS_API_REGEX).hasRole(ADMIN_ROLE) .regexMatchers(HttpMethod.PUT, APPLICATIONS_API_REGEX).hasRole(ADMIN_ROLE) .regexMatchers(HttpMethod.DELETE, CLUSTERS_API_REGEX).hasRole(ADMIN_ROLE) .regexMatchers(HttpMethod.PATCH, CLUSTERS_API_REGEX).hasRole(ADMIN_ROLE) .regexMatchers(HttpMethod.POST, CLUSTERS_API_REGEX).hasRole(ADMIN_ROLE) .regexMatchers(HttpMethod.PUT, CLUSTERS_API_REGEX).hasRole(ADMIN_ROLE) .regexMatchers(HttpMethod.DELETE, COMMANDS_API_REGEX).hasRole(ADMIN_ROLE) .regexMatchers(HttpMethod.PATCH, COMMANDS_API_REGEX).hasRole(ADMIN_ROLE) .regexMatchers(HttpMethod.POST, COMMANDS_API_REGEX).hasRole(ADMIN_ROLE) .regexMatchers(HttpMethod.PUT, COMMANDS_API_REGEX).hasRole(ADMIN_ROLE).anyRequest() .hasRole(USER_ROLE).and().x509().authenticationUserDetailsService(x509UserDetailsService).and() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER) // .and() // .requiresChannel().anyRequest().requiresSecure() .and().requestCache().requestCache(new NullRequestCache()).and().csrf().disable(); // @formatter:on }
From source file:com.flipkart.poseidon.filters.RequestGzipFilter.java
@Override public void doFilter(final ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest servletRequest = (HttpServletRequest) request; HttpServletResponse servletResponse = (HttpServletResponse) response; boolean isGzipped = servletRequest.getHeader(HttpHeaders.CONTENT_ENCODING) != null && servletRequest.getHeader(HttpHeaders.CONTENT_ENCODING).contains("gzip"); boolean requestTypeSupported = HttpMethod.POST.toString().equals(servletRequest.getMethod()) || HttpMethod.PUT.toString().equals(servletRequest.getMethod()) || HttpMethod.PATCH.toString().equals(servletRequest.getMethod()); if (isGzipped && !requestTypeSupported) { throw new IllegalStateException(new StringBuilder().append(servletRequest.getMethod()) .append(" is not supports gzipped body of parameters.") .append(" Only POST requests are currently supported.").toString()); }/*from w ww . j a va 2 s . c o m*/ if (isGzipped) { servletRequest = new GzippedInputStreamWrapper(servletRequest); } chain.doFilter(servletRequest, servletResponse); }
From source file:org.zalando.github.spring.TeamsTemplateTest.java
@Test public void updateTeam() throws Exception { mockServer.expect(requestTo("https://api.github.com/teams/1")).andExpect(method(HttpMethod.PATCH)) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(//w w w .j a va2 s . com withSuccess(new ClassPathResource("getTeam.json", getClass()), MediaType.APPLICATION_JSON)); Team team = teamsTemplate.updateTeam(1, new TeamRequest("Justice League")); Assertions.assertThat(team).isNotNull(); Assertions.assertThat(team.getId()).isEqualTo(1); Assertions.assertThat(team.getName()).isEqualTo("Justice League"); }
From source file:example.company.SecurityConfiguration.java
/** * This section defines the security policy for the app. * <p>//from www . ja v a 2 s .com * <ul> * <li>BASIC authentication is supported (enough for this REST-based demo).</li> * <li>/employees is secured using URL security shown below.</li> * <li>CSRF headers are disabled since we are only testing the REST interface, not a web one.</li> * </ul> * NOTE: GET is not shown which defaults to permitted. * * @param http * @throws Exception * @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.web.builders.HttpSecurity) */ @Override protected void configure(HttpSecurity http) throws Exception { http.httpBasic().and().authorizeRequests().// antMatchers(HttpMethod.POST, "/employees").hasRole("ADMIN").// antMatchers(HttpMethod.PUT, "/employees/**").hasRole("ADMIN").// antMatchers(HttpMethod.PATCH, "/employees/**").hasRole("ADMIN").and().// csrf().disable(); }
From source file:com.expedia.seiso.SeisoWebSecurityConfig.java
@Override protected void configure(HttpSecurity http) throws Exception { // @formatter:off http// www .ja v a 2 s .c o m // TODO Would prefer to do this without sessions if possible. But see // https://spring.io/guides/tutorials/spring-security-and-angular-js/ // http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-sticky-sessions.html // .sessionManagement() // .sessionCreationPolicy(SessionCreationPolicy.STATELESS) // .and() .authorizeRequests().antMatchers(HttpMethod.GET, "/internal/**").permitAll() .antMatchers(HttpMethod.GET, "/api/**").permitAll().antMatchers(HttpMethod.POST, "/api/**") .hasAnyRole(Roles.USER, Roles.ADMIN).antMatchers(HttpMethod.PUT, "/api/**") .hasAnyRole(Roles.USER, Roles.ADMIN).antMatchers(HttpMethod.DELETE, "/api/**") .hasAnyRole(Roles.USER, Roles.ADMIN).antMatchers(HttpMethod.PATCH, "/api/**") .hasAnyRole(Roles.USER, Roles.ADMIN) // Admin console .antMatchers(HttpMethod.GET, "/admin").hasRole(Roles.ADMIN).antMatchers(HttpMethod.GET, "/admin/**") .hasRole(Roles.ADMIN) // Blacklist .anyRequest().denyAll() // .anyRequest().hasRole(Roles.USER) .and().httpBasic().authenticationEntryPoint(entryPoint()).and().exceptionHandling() .authenticationEntryPoint(entryPoint()).and() // FIXME Enable. See https://spring.io/guides/tutorials/spring-security-and-angular-js/ .csrf().disable(); // @formatter:on }
From source file:com.jiwhiz.rest.admin.UserRestControllerTest.java
@Test public void updateUserAccount_Lock_ShouldLockUserAccount() throws Exception { UserAccount user = getTestLoggedInUser(); user.setAccountLocked(false);//from w w w. jav a 2 s . co m when(userAccountRepositoryMock.findOne(USER_ID)).thenReturn(user); mockMvc.perform(request(HttpMethod.PATCH, API_ROOT + URL_ADMIN_USERS_USER, USER_USERNAME) .contentType(MediaType.APPLICATION_JSON).content("{ \"command\" : \"lock\"}")) .andExpect(status().isNoContent()); Assert.assertTrue(user.isAccountLocked()); }
From source file:org.zalando.github.spring.OrganizationTemplateTest.java
@Test public void patchOrganization() throws Exception { mockServer.expect(requestTo("https://api.github.com/orgs/zalando-stups")) .andExpect(method(HttpMethod.PATCH)).andExpect(content().contentType(MediaType.APPLICATION_JSON)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(/*from ww w .j a v a2 s . c om*/ withSuccess(new ClassPathResource("getOrga.json", getClass()), MediaType.APPLICATION_JSON)); OrganizationUpdate update = new OrganizationUpdate(); update.setBillingEmail("no-billing-for-open-source@gmail.com"); ExtOrganization orga = usersTemplate.updateOrganization(update, "zalando-stups"); Assertions.assertThat(orga).isNotNull(); Assertions.assertThat(orga.getName()).isEqualTo("zalando-stups"); Assertions.assertThat(orga.getLogin()).isEqualTo("zalando-stups"); }
From source file:com.jiwhiz.rest.admin.CommentRestControllerTest.java
@Test public void updateCommentPost_ShouldUpdateCommentPostAndReturn204() throws Exception { UserAccount user = getTestLoggedInUserWithAdminRole(); when(userAccountServiceMock.getCurrentUser()).thenReturn(user); CommentPost comment = getTestApprovedCommentPost(); when(commentPostRepositoryMock.findOne(COMMENT_ID)).thenReturn(comment); when(commentPostRepositoryMock.save(comment)).thenReturn(comment); Map<String, String> testUpdates = new HashMap<String, String>(); testUpdates.put("content", "Updated blog text..."); mockMvc.perform(request(HttpMethod.PATCH, API_ROOT + URL_ADMIN_COMMENTS_COMMENT, COMMENT_ID) .contentType(MediaType.APPLICATION_JSON).content(TestUtils.convertObjectToJsonBytes(testUpdates))) .andExpect(status().isNoContent()); }
From source file:cucumber.api.spring.test.web.servlet.MockMvcStepdefs.java
@When("^I perform a PATCH request on \"(.*?)\"$") public void i_perform_a_patch_request_on(String uri) throws Throwable { i_perform_a_request_on(HttpMethod.PATCH, uri); }
From source file:com.jiwhiz.rest.user.UserCommentRestControllerTest.java
@Test public void updateComment_ShouldReturnHttpStatusCode204() throws Exception { UserAccount user = getTestLoggedInUserWithAuthorRole(); CommentPost comment = getTestApprovedCommentPost(); when(userAccountServiceMock.getCurrentUser()).thenReturn(user); when(commentPostRepositoryMock.findOne(eq(COMMENT_ID))).thenReturn(comment); Map<String, String> testUpdates = new HashMap<String, String>(); testUpdates.put("content", "Updated blog text..."); mockMvc.perform(request(HttpMethod.PATCH, API_ROOT + URL_USER_COMMENTS_COMMENT, COMMENT_ID) .contentType(MediaType.APPLICATION_JSON).content(TestUtils.convertObjectToJsonBytes(testUpdates))) .andExpect(status().isNoContent()).andExpect(content().string("")); }