Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAYARA-3324 APPSERV-16 APPSERV-23 Allow Encryption of Web Session Data and SFSBs Stored in Hazelcast #4433

Merged
merged 14 commits into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2016-2018 Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2016-2020 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -39,13 +39,15 @@
*/
package fish.payara.ha.hazelcast.store;

import com.hazelcast.core.IMap;
import fish.payara.nucleus.hazelcast.HazelcastCore;
import java.io.Serializable;
import fish.payara.nucleus.store.ClusteredStore;
import org.glassfish.ha.store.api.BackingStore;
import org.glassfish.ha.store.api.BackingStoreException;
import org.glassfish.ha.store.api.BackingStoreFactory;

import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author steve
Expand All @@ -54,15 +56,14 @@ public class HazelcastBackingStore<K extends Serializable, V extends Serializabl
extends BackingStore<K, V> {

private final BackingStoreFactory factory;
private final HazelcastCore core;
private final String storeName;
private IMap<K, V> imap;
private String instanceName;
private ClusteredStore clusteredStore;

public HazelcastBackingStore(BackingStoreFactory factory, String storeName, HazelcastCore core) {
public HazelcastBackingStore(BackingStoreFactory factory, String storeName, ClusteredStore clusteredStore) {
this.factory = factory;
this.storeName = storeName;
this.core = core;
this.clusteredStore = clusteredStore;
}

@Override
Expand All @@ -73,40 +74,45 @@ public BackingStoreFactory getBackingStoreFactory() {
@Override
public V load(K k, String string) throws BackingStoreException {
init();
return imap.get(k);
try {
return (V) clusteredStore.get(storeName, k);
} catch (ClassCastException cce) {
Logger.getLogger(HazelcastBackingStore.class.getName()).log(Level.WARNING,
"ClassCastException when reading value from store", cce);
throw new BackingStoreException(cce.getMessage());
}
}

@Override
public String save(K k, V v, boolean bln) throws BackingStoreException {
init();
imap.set(k, v);
clusteredStore.set(storeName, k, v);

return instanceName;
}

@Override
public void remove(K k) throws BackingStoreException {
init();
imap.delete(k);
clusteredStore.remove(storeName, k);
}

@Override
public int size() throws BackingStoreException {
init();
return imap.size();
return clusteredStore.getMap(storeName).size();
}

private void init() throws BackingStoreException {
if(imap != null) {
if(instanceName != null) {
return;
}
if (!core.isEnabled()) {
throw new BackingStoreException("Hazelcast is NOT Enabled please enable Hazelcast");
if (clusteredStore == null) {
throw new BackingStoreException("Clustered Store not available, cannot use sessions yet", new IllegalStateException("Initializing"));
}
if(core.getInstance() == null) {
throw new BackingStoreException("Hazelcast not yet initialized, cannot use sessions yet", new IllegalStateException("Initializing"));
if (!clusteredStore.isEnabled()) {
throw new BackingStoreException("Hazelcast is not enabled, please enable Hazelcast");
}
imap = core.getInstance().getMap(storeName);
instanceName = core.getInstance().getLocalEndpoint().getUuid();
instanceName = clusteredStore.getInstanceId();
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
/*

DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

Copyright (c) 2016 Payara Foundation. All rights reserved.

The contents of this file are subject to the terms of the Common Development
and Distribution License("CDDL") (collectively, the "License"). You
may not use this file except in compliance with the License. You can
obtain a copy of the License at
https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
or packager/legal/LICENSE.txt. See the License for the specific
language governing permissions and limitations under the License.

When distributing the software, include this License Header Notice in each
file and include the License file at packager/legal/LICENSE.txt.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2016-2020 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.ha.hazelcast.store;

import fish.payara.nucleus.hazelcast.HazelcastCore;
import java.io.Serializable;
import javax.inject.Inject;

import fish.payara.nucleus.store.ClusteredStore;
import org.glassfish.ha.store.api.BackingStore;
import org.glassfish.ha.store.api.BackingStoreConfiguration;
import org.glassfish.ha.store.api.BackingStoreException;
Expand All @@ -36,9 +60,12 @@ public class HazelcastBackingStoreFactory implements BackingStoreFactory {
@Inject
HazelcastCore core;

@Inject
ClusteredStore clusteredStore;

@Override
public <K extends Serializable, V extends Serializable> BackingStore<K, V> createBackingStore(BackingStoreConfiguration<K, V> bsc) throws BackingStoreException {
return new HazelcastBackingStore<K, V>(this, bsc.getStoreName(), core);
return new HazelcastBackingStore<>(this, bsc.getStoreName(), clusteredStore);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ and Distribution License("CDDL") (collectively, the "License"). You
*/
package fish.payara.appserver.micro.services;

import fish.payara.appserver.micro.services.data.InstanceDescriptorImpl;
import fish.payara.micro.data.InstanceDescriptor;

import java.io.Serializable;

/**
Expand Down
33 changes: 33 additions & 0 deletions appserver/tests/payara-samples/samples/datagrid-encryption/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>fish.payara.samples</groupId>
<artifactId>payara-samples-profiled-tests</artifactId>
<version>5.201-SNAPSHOT</version>
</parent>

<artifactId>datagrid-encryption-parent</artifactId>
<packaging>pom</packaging>

<name>Payara Samples - Datagrid Encryption Parent</name>

<modules>
<module>sfsb-passivation</module>
</modules>

<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>fish.payara.samples</groupId>
<artifactId>test-utils</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>fish.payara.samples</groupId>
<artifactId>datagrid-encryption-parent</artifactId>
<version>5.201-SNAPSHOT</version>
</parent>

<artifactId>sfsb-passivation</artifactId>
<packaging>war</packaging>

<name>Payara Samples - Datagrid Encryption: Stateful Session Bean Passivation</name>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2020 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.samples.datagridencryption.sfsb;

import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

/**
* @author Andrew Pielage <andrew.pielage@payara.fish>
*/
@ApplicationPath("/")
@ApplicationScoped
public class ApplicationInit extends Application {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2020 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.samples.datagridencryption.sfsb;

import javax.ejb.Local;

/**
* @author Andrew Pielage <andrew.pielage@payara.fish>
*/
@Local
public interface TestEjb {

void addItem(String item);

void removeItem(String item);

String getItems();

}
Loading