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-2081 create a new roles allowed cdi annotation #2247

5 changes: 3 additions & 2 deletions api/payara-api/pom.xml
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-2017] Payara Foundation and/or its affiliates. All rights reserved.
Copyright (c) [2016-2018] 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 @@ -132,9 +132,10 @@
javax.enterprise.util
</Import-Package>
<Export-Package>
fish.payara.cdi.auth.roles,
fish.payara.cdi.jsr107.impl,
fish.payara.micro.cdi,
fish.payara.cluster,
fish.payara.micro.cdi,
fish.payara.nucleus.requesttracing.api,
fish.payara.notification.eventbus,
fish.payara.nucleus.notification.domain,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2018] 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.cdi.auth.roles;

/**
*
* @author Michael Ranaldo <michael@ranaldo.co.uk>
*/
public enum LogicalOperator {
OR,
AND
}
83 changes: 83 additions & 0 deletions api/payara-api/src/main/java/fish/payara/cdi/auth/roles/Roles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2017-2018] 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.cdi.auth.roles;

import static fish.payara.cdi.auth.roles.LogicalOperator.OR;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.enterprise.util.Nonbinding;
import javax.interceptor.InterceptorBinding;
import javax.validation.constraints.NotNull;

/**
* Defines a list of roles which a caller must be in to access either methods within an annotated class, or a singular
* annotated method. Roles defined on a method level will always add to or overrule those defined on a class level.
*
* @author Michael Ranaldo <michael@ranaldo.co.uk>
*/
@InterceptorBinding
@Target({TYPE, METHOD})
@Retention(RUNTIME)
public @interface Roles {

/**
* The roles which are allowed to access this method. Defaults to an empty string.
*
* @return A String array of permitted roles.
*/
@Nonbinding
@NotNull
String[] allowed() default "";

/**
* Whether accessing users must be in any one of the given roles (OR) or all given roles (AND). Uses the
* LogicalOperator enum defined in the same package (fish.payara.cdi.auth.roles.LogicalOperator).
*
* @return
* @default OR
*/
@Nonbinding
LogicalOperator semantics() default OR;
}
13 changes: 10 additions & 3 deletions appserver/featuresets/payara-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
holder.
-->

<!-- Portions Copyright [2016-2017] [Payara Foundation and/or its affiliates] -->
<!-- Portions Copyright [2016-2018] [Payara Foundation and/or its affiliates] -->

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -131,7 +131,7 @@
<version>${project.version}</version>
<type>zip</type>
</dependency>
<!-- hazelcast package -->
<!-- hazelcast package -->
<dependency>
<groupId>org.glassfish.main.packager</groupId>
<artifactId>hazelcast</artifactId>
Expand Down Expand Up @@ -200,7 +200,7 @@
<version>${project.version}</version>
<type>zip</type>
</dependency>
<dependency>
<dependency>
<groupId>org.glassfish.main.packager</groupId>
<artifactId>asadmin-recorder</artifactId>
<version>${project.version}</version>
Expand Down Expand Up @@ -254,6 +254,13 @@
<version>${project.version}</version>
<type>zip</type>
</dependency>
<!-- roles api -->
<dependency>
<groupId>org.glassfish.main.packager</groupId>
<artifactId>cdi-auth-roles</artifactId>
<version>${project.version}</version>
<type>zip</type>
</dependency>
</dependencies>

<profiles>
Expand Down
135 changes: 135 additions & 0 deletions appserver/packager/cdi-auth-roles/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

Copyright (c) [2017-2018] 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.
-->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.glassfish.main.packager</groupId>
<artifactId>packages</artifactId>
<version>4.1.2.181-SNAPSHOT</version>
</parent>
<artifactId>cdi-auth-roles</artifactId>
<name>Payara CDI Auth Roles Package</name>
<packaging>distribution-fragment</packaging>
<description>This pom describes how to assemble the Payara CDI Auth Roles package</description>

<properties>
<temp.dir>${project.build.directory}/dependency</temp.dir>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>process-step1</id>
</execution>
<execution>
<id>process-step2</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>process-step3</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>ips</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>process-step4</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.glassfish.build</groupId>
<artifactId>glassfishbuild-maven-plugin</artifactId>
<executions>
<execution>
<id>process-step5</id>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>fish.payara.appserver</groupId>
<artifactId>cdi-auth-roles</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!--
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

Copyright (c) [2017-2018] 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.
-->
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

<id>stage-package</id>
<formats>
<format>dir</format>
</formats>

<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${temp.dir}/nucleus</directory>
<outputDirectory>${install.dir.name}/glassfish</outputDirectory>
</fileSet>
<fileSet>
<directory>${temp.dir}</directory>
<excludes>
<exclude>nucleus/**</exclude>
<exclude>pkg_proto.py</exclude>
</excludes>
<outputDirectory>${install.dir.name}</outputDirectory>
</fileSet>
</fileSets>
</assembly>
Loading