[JAVA] Avoid serializing pages with Wicket

Avoid serializing pages with Wicket

environment

wicket 7(.10)

I don't want to serialize

When handling data with a high security level such as payment pages and personal information registration pages (** Even if encrypted **) You may not want the data to be saved (should).

--In order to comply with PCI-DSS, the security code cannot be stored anywhere as data including logs.

VoidPageManagerProvider

--Override Wicket serialization behavior --Hit after searching. Thank you for the wisdom of our predecessors. ――It seems that you have to make a little more settings at each page level, here application level settings

Page manager provider

VoidPageManagerProvider.java


public class VoidPageManagerProvider extends DefaultPageManagerProvider {

	protected IPageManagerContext 	pageManagerContext;
	protected IPageManager			pageManager;

	/**
	 * @param application
	 */
	public VoidPageManagerProvider(Application application) {
		super(application);

		pageManagerContext = new DefaultPageManagerContext();

		IDataStore dataStore = newDataStore();
		IPageStore pageStore = newPageStore(dataStore);
		pageManager = new VoidPageStoreManager(application.getName(), pageStore, pageManagerContext);
	}

	@Override
	public IPageManager get(IPageManagerContext pageManagerContext) {

		return pageManager;
	}

	@Override
	public IPageStore newPageStore(IDataStore dataStore) {

		return new VoidPageStore();
	}

	@Override
	public IDataStore newDataStore() {

		return new VoidDataStore();
	}
}
Page store

VoidPageStore.java


public class VoidPageStore implements IPageStore {

	/**
	 * constructor
	 */
	public VoidPageStore() {
	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IPageStore#destroy()
	 */
	@Override
	public void destroy() {

	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IPageStore#getPage(java.lang.String, int)
	 * @param sessionId
	 * @param pageId
	 * @return
	 */
	@Override
	public IManageablePage getPage(String sessionId, int pageId) {
		// nothing
		return null;
	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IPageStore#removePage(java.lang.String, int)
	 * @param sessionId
	 * @param pageId
	 */
	@Override
	public void removePage(String sessionId, int pageId) {

	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IPageStore#storePage(java.lang.String, org.apache.wicket.page.IManageablePage)
	 * @param sessionId
	 * @param page
	 */
	@Override
	public void storePage(String sessionId, IManageablePage page) {

	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IPageStore#unbind(java.lang.String)
	 * @param sessionId
	 */
	@Override
	public void unbind(String sessionId) {

	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IPageStore#prepareForSerialization(java.lang.String, java.io.Serializable)
	 * @param sessionId
	 * @param page
	 * @return
	 */
	@Override
	public Serializable prepareForSerialization(String sessionId, Serializable page) {

		return null;
	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IPageStore#restoreAfterSerialization(java.io.Serializable)
	 * @param serializable
	 * @return
	 */
	@Override
	public Object restoreAfterSerialization(Serializable serializable) {

		return null;
	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IPageStore#convertToPage(java.lang.Object)
	 * @param page
	 * @return
	 */
	@Override
	public IManageablePage convertToPage(Object page) {

		return null;
	}

}
Data store

VoidDataStore.java


public class VoidDataStore implements IDataStore {

	/**
	 * constructor
	 */
	public VoidDataStore() {
	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IDataStore#getData(java.lang.String, int)
	 * @param sessionId
	 * @param id
	 * @return
	 */
	@Override
	public byte[] getData(String sessionId, int id) {

		// nothing
		return null;
	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IDataStore#removeData(java.lang.String, int)
	 * @param sessionId
	 * @param id
	 */
	@Override
	public void removeData(String sessionId, int id) {

	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IDataStore#removeData(java.lang.String)
	 * @param sessionId
	 */
	@Override
	public void removeData(String sessionId) {

	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IDataStore#storeData(java.lang.String, int, byte[])
	 * @param sessionId
	 * @param id
	 * @param data
	 */
	@Override
	public void storeData(String sessionId, int id, byte[] data) {

	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IDataStore#destroy()
	 */
	@Override
	public void destroy() {

	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IDataStore#isReplicated()
	 * @return
	 */
	@Override
	public boolean isReplicated() {
		return true;
	}

	/* (Non-Javadoc)
	 * @see org.apache.wicket.pageStore.IDataStore#canBeAsynchronous()
	 * @return
	 */
	@Override
	public boolean canBeAsynchronous() {
		return true;
	}

}
Page store manager

VoidPageStoreManager.java


public class VoidPageStoreManager extends PageStoreManager {

	/**
	 * @param applicationName
	 * @param pageStore
	 * @param context
	 */
	public VoidPageStoreManager(String applicationName, IPageStore pageStore, IPageManagerContext context) {
		super(applicationName, pageStore, context);
	}

	@Override
	public boolean supportsVersioning() {
		return false;
	}
}

Call from application

Call in init ()

WicketApplication.java


		// page manager
		setPageManagerProvider(new VoidPageManagerProvider(this));

No more errors without implements Serializable

Recommended Posts

Avoid serializing pages with Wicket
Avoid UnsupportedEncodingException with Charset.forName
FileUpload with Rest on Apache Wicket