-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#56 problem with websocket and csrf prevention
- revert changes - a conditional csrf listener is needed
- Loading branch information
1 parent
5484b1e
commit 3c4ab13
Showing
2 changed files
with
61 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 58 additions & 58 deletions
116
...t/spring/boot/starter/configuration/extensions/core/csrf/CsrfAttacksPreventionConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,58 @@ | ||
package com.giffing.wicket.spring.boot.starter.configuration.extensions.core.csrf; | ||
|
||
import org.apache.wicket.protocol.http.CsrfPreventionRequestCycleListener; | ||
import org.apache.wicket.protocol.http.WebApplication; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
|
||
import com.giffing.wicket.spring.boot.context.extensions.ApplicationInitExtension; | ||
import com.giffing.wicket.spring.boot.context.extensions.WicketApplicationInitConfiguration; | ||
import com.giffing.wicket.spring.boot.context.extensions.boot.actuator.WicketAutoConfig; | ||
import com.giffing.wicket.spring.boot.context.extensions.boot.actuator.WicketEndpointRepository; | ||
|
||
|
||
/** | ||
* Enables CSRF protection if the following condition matches. | ||
* | ||
* 1. The {@link CsrfPreventionRequestCycleListener} class is in the classpath. | ||
* | ||
* 2. The property {@link CsrfAttacksPreventionProperties#PROPERTY_PREFIX}.enabled has to be true (default = true) | ||
* | ||
* The protection should be enabled by default cause the {@link CsrfPreventionRequestCycleListener} is located | ||
* in Wickets core project. | ||
* | ||
* @author Marc Giffing | ||
* | ||
*/ | ||
@ApplicationInitExtension | ||
@ConditionalOnProperty(prefix = CsrfAttacksPreventionProperties.PROPERTY_PREFIX, value = "enabled", matchIfMissing = true) | ||
@ConditionalOnClass(value = org.apache.wicket.protocol.http.CsrfPreventionRequestCycleListener.class) | ||
@EnableConfigurationProperties({ CsrfAttacksPreventionProperties.class }) | ||
public class CsrfAttacksPreventionConfig implements WicketApplicationInitConfiguration{ | ||
|
||
@Autowired | ||
private CsrfAttacksPreventionProperties props; | ||
|
||
@Autowired | ||
private WicketEndpointRepository wicketEndpointRepository; | ||
|
||
@Override | ||
public void init(WebApplication webApplication) { | ||
CsrfPreventionRequestCycleListener listener = new CsrfPreventionRequestCycleListener(); | ||
listener.setConflictingOriginAction(props.getConflictingOriginAction()); | ||
listener.setErrorCode(props.getErrorCode()); | ||
listener.setErrorMessage(props.getErrorMessage()); | ||
listener.setNoOriginAction(props.getNoOriginAction()); | ||
for (String acceptedOrigin : props.getAcceptedOrigins()) { | ||
listener.addAcceptedOrigin(acceptedOrigin); | ||
} | ||
webApplication.getRequestCycleListeners().add(listener); | ||
|
||
wicketEndpointRepository.add(new WicketAutoConfig.Builder(this.getClass()) | ||
.withDetail("properties", props) | ||
.build()); | ||
} | ||
|
||
} | ||
package com.giffing.wicket.spring.boot.starter.configuration.extensions.core.csrf; | ||
|
||
import org.apache.wicket.protocol.http.CsrfPreventionRequestCycleListener; | ||
import org.apache.wicket.protocol.http.WebApplication; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
|
||
import com.giffing.wicket.spring.boot.context.extensions.ApplicationInitExtension; | ||
import com.giffing.wicket.spring.boot.context.extensions.WicketApplicationInitConfiguration; | ||
import com.giffing.wicket.spring.boot.context.extensions.boot.actuator.WicketAutoConfig; | ||
import com.giffing.wicket.spring.boot.context.extensions.boot.actuator.WicketEndpointRepository; | ||
|
||
|
||
/** | ||
* Enables CSRF protection if the following condition matches. | ||
* | ||
* 1. The {@link CsrfPreventionRequestCycleListener} class is in the classpath. | ||
* | ||
* 2. The property {@link CsrfAttacksPreventionProperties#PROPERTY_PREFIX}.enabled has to be true (default = true) | ||
* | ||
* The protection should be enabled by default cause the {@link CsrfPreventionRequestCycleListener} is located | ||
* in Wickets core project. | ||
* | ||
* @author Marc Giffing | ||
* | ||
*/ | ||
@ApplicationInitExtension | ||
@ConditionalOnProperty(prefix = CsrfAttacksPreventionProperties.PROPERTY_PREFIX, value = "enabled", matchIfMissing = true) | ||
@ConditionalOnClass(value = org.apache.wicket.protocol.http.CsrfPreventionRequestCycleListener.class) | ||
@EnableConfigurationProperties({ CsrfAttacksPreventionProperties.class }) | ||
public class CsrfAttacksPreventionConfig implements WicketApplicationInitConfiguration{ | ||
|
||
@Autowired | ||
private CsrfAttacksPreventionProperties props; | ||
|
||
@Autowired | ||
private WicketEndpointRepository wicketEndpointRepository; | ||
|
||
@Override | ||
public void init(WebApplication webApplication) { | ||
CsrfPreventionRequestCycleListener listener = new CsrfPreventionRequestCycleListener(); | ||
listener.setConflictingOriginAction(props.getConflictingOriginAction()); | ||
listener.setErrorCode(props.getErrorCode()); | ||
listener.setErrorMessage(props.getErrorMessage()); | ||
listener.setNoOriginAction(props.getNoOriginAction()); | ||
for (String acceptedOrigin : props.getAcceptedOrigins()) { | ||
listener.addAcceptedOrigin(acceptedOrigin); | ||
} | ||
webApplication.getRequestCycleListeners().add(listener); | ||
|
||
wicketEndpointRepository.add(new WicketAutoConfig.Builder(this.getClass()) | ||
.withDetail("properties", props) | ||
.build()); | ||
} | ||
|
||
} |