Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
if this fixes the "java.lang.SecurityException: class XXX signer info…
…rmation does not match signer information of other classes in the same package" I'll flip shit.
- Loading branch information
Showing
13 changed files
with
892 additions
and
9 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
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
122 changes: 122 additions & 0 deletions
122
src/main/java/net/doubledoordev/d3core/permissions/Group.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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright (c) 2014, | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* Neither the name of the {organization} nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* | ||
*/ | ||
|
||
package net.doubledoordev.d3core.permissions; | ||
|
||
import java.util.HashSet; | ||
|
||
/** | ||
* Permission system stuff | ||
* | ||
* @author Dries007 | ||
*/ | ||
public class Group | ||
{ | ||
private HashSet<Node> nodes = new HashSet<>(); | ||
private String name; | ||
private String parent; | ||
|
||
public Group() | ||
{ | ||
} | ||
|
||
public Group(String name) | ||
{ | ||
this.name = name; | ||
} | ||
|
||
public Group(String name, String parent) | ||
{ | ||
this.name = name; | ||
this.parent = parent; | ||
} | ||
|
||
public String getName() | ||
{ | ||
return name; | ||
} | ||
|
||
public String getParent() | ||
{ | ||
return parent; | ||
} | ||
|
||
public void setParent(String parent) | ||
{ | ||
this.parent = parent; | ||
} | ||
|
||
public boolean hasPermissionFor(Node requestNode) | ||
{ | ||
if (parent != null && PermissionsDB.INSTANCE.getGroup(parent).hasPermissionFor(requestNode)) return true; | ||
for (Node hadNode : nodes) if (hadNode.matches(requestNode)) return true; | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
int result = nodes.hashCode(); | ||
result = 31 * result + name.hashCode(); | ||
result = 31 * result + parent.hashCode(); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
Group group = (Group) o; | ||
|
||
return name.equals(group.name) && nodes.equals(group.nodes) && parent.equals(group.parent); | ||
|
||
} | ||
|
||
public void addNode(String nodeString) | ||
{ | ||
nodes.add(new Node(nodeString)); | ||
} | ||
|
||
public boolean removeNode(String nodeString) | ||
{ | ||
return nodes.remove(new Node(nodeString)); | ||
} | ||
|
||
public HashSet<String> getNodes() | ||
{ | ||
HashSet<String> strings = new HashSet<>(); | ||
for (Node node : nodes) strings.add(node.toString()); | ||
return strings; | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
src/main/java/net/doubledoordev/d3core/permissions/Node.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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright (c) 2014, | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* Neither the name of the {organization} nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* | ||
*/ | ||
|
||
package net.doubledoordev.d3core.permissions; | ||
|
||
import com.google.gson.*; | ||
import net.doubledoordev.d3core.util.CoreConstants; | ||
import org.apache.commons.lang3.ArrayUtils; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.Arrays; | ||
|
||
import static net.doubledoordev.d3core.util.CoreConstants.JOINER_DOT; | ||
|
||
/** | ||
* Permission system stuff | ||
* | ||
* @author Dries007 | ||
*/ | ||
public class Node | ||
{ | ||
final String[] parts; | ||
|
||
public Node(String parts) | ||
{ | ||
this.parts = parts.toLowerCase().split("\\."); | ||
} | ||
|
||
public Node(String... parts) | ||
{ | ||
for (int i = 0; i < parts.length; i++) | ||
{ | ||
parts[i] = parts[i].toLowerCase(); | ||
} | ||
this.parts = parts; | ||
} | ||
|
||
public boolean matches(Node requestNode) | ||
{ | ||
if (this.equals(requestNode)) return true; | ||
for (int i = 0; i < this.parts.length && i < requestNode.parts.length; i++) | ||
{ | ||
if (this.parts[i].equals("*")) return true; | ||
if (!this.parts[i].equals(requestNode.parts[i])) return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return Arrays.hashCode(parts); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
Node node = (Node) o; | ||
|
||
return Arrays.equals(parts, node.parts); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return JOINER_DOT.join(parts); | ||
} | ||
|
||
public Node append(String... extras) | ||
{ | ||
return new Node(ArrayUtils.addAll(parts, extras)); | ||
} | ||
|
||
public static class JsonHelper implements JsonSerializer<Node>, JsonDeserializer<Node> | ||
{ | ||
@Override | ||
public Node deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException | ||
{ | ||
return new Node((String) context.deserialize(json, String.class)); | ||
} | ||
|
||
@Override | ||
public JsonElement serialize(Node src, Type typeOfSrc, JsonSerializationContext context) | ||
{ | ||
return context.serialize(src.toString()); | ||
} | ||
} | ||
} |
Oops, something went wrong.