Skip to content

Commit

Permalink
WFLY-10172 Add support for JSR-375 EE Security
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Apr 12, 2018
1 parent aa1549c commit 8f303e3
Show file tree
Hide file tree
Showing 37 changed files with 1,062 additions and 44 deletions.
20 changes: 19 additions & 1 deletion component-matrix/pom.xml
Expand Up @@ -99,6 +99,7 @@
<version.javax.jws.jsr181-api>1.0-MR1</version.javax.jws.jsr181-api> <version.javax.jws.jsr181-api>1.0-MR1</version.javax.jws.jsr181-api>
<version.javax.mail>1.6.1</version.javax.mail> <version.javax.mail>1.6.1</version.javax.mail>
<version.javax.persistence>2.2</version.javax.persistence> <version.javax.persistence>2.2</version.javax.persistence>
<version.javax.security.enterprise>1.0</version.javax.security.enterprise>
<version.javax.validation>2.0.1.Final</version.javax.validation> <version.javax.validation>2.0.1.Final</version.javax.validation>
<version.jaxen>1.1.6</version.jaxen> <version.jaxen>1.1.6</version.jaxen>
<version.jboss.jaxbintros>1.0.2.GA</version.jboss.jaxbintros> <version.jboss.jaxbintros>1.0.2.GA</version.jboss.jaxbintros>
Expand Down Expand Up @@ -136,6 +137,7 @@
<version.org.glassfish.javax.enterprise.concurrent>1.0</version.org.glassfish.javax.enterprise.concurrent> <version.org.glassfish.javax.enterprise.concurrent>1.0</version.org.glassfish.javax.enterprise.concurrent>
<version.org.glassfish.javax.json>1.1.2</version.org.glassfish.javax.json> <version.org.glassfish.javax.json>1.1.2</version.org.glassfish.javax.json>
<version.org.glassfish.javax.json-1.0>1.0.4</version.org.glassfish.javax.json-1.0> <version.org.glassfish.javax.json-1.0>1.0.4</version.org.glassfish.javax.json-1.0>
<version.org.glassfish.soteria>1.0</version.org.glassfish.soteria>
<version.org.hibernate>5.1.13.Final</version.org.hibernate> <version.org.hibernate>5.1.13.Final</version.org.hibernate>
<version.org.hibernate.commons.annotations>5.0.2.Final</version.org.hibernate.commons.annotations> <version.org.hibernate.commons.annotations>5.0.2.Final</version.org.hibernate.commons.annotations>
<version.org.hibernate.search>5.5.8.Final</version.org.hibernate.search> <version.org.hibernate.search>5.5.8.Final</version.org.hibernate.search>
Expand Down Expand Up @@ -527,6 +529,12 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>


<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-ee-security</artifactId>
<version>${project.version}</version>
</dependency>

<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId> <artifactId>wildfly-ejb-client-bom</artifactId>
Expand Down Expand Up @@ -1193,6 +1201,12 @@
<version>${version.javax.persistence}</version> <version>${version.javax.persistence}</version>
</dependency> </dependency>


<dependency>
<groupId>javax.security.enterprise</groupId>
<artifactId>javax.security.enterprise-api</artifactId>
<version>${version.javax.security.enterprise}</version>
</dependency>

<dependency> <dependency>
<groupId>javax.validation</groupId> <groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId> <artifactId>validation-api</artifactId>
Expand Down Expand Up @@ -3376,7 +3390,11 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>

<dependency>
<groupId>org.glassfish.soteria</groupId>
<artifactId>javax.security.enterprise</artifactId>
<version>${version.org.glassfish.soteria}</version>
</dependency>
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId> <artifactId>hibernate-core</artifactId>
Expand Down
1 change: 1 addition & 0 deletions docs/src/main/asciidoc/Getting_Started_Guide.adoc
Expand Up @@ -138,6 +138,7 @@ will remain at Java EE7 level.
| Java API for JSON Processing | 1.0 | JSR-353 | 1.1 | https://jcp.org/en/jsr/detail?id=374[JSR-374] | Java API for JSON Processing | 1.0 | JSR-353 | 1.1 | https://jcp.org/en/jsr/detail?id=374[JSR-374]
| Java API for JSON Binding | - | - | 1.0 | https://jcp.org/en/jsr/detail?id=367[JSR-367] | Java API for JSON Binding | - | - | 1.0 | https://jcp.org/en/jsr/detail?id=367[JSR-367]
| Common Annotations for the Java Platform | 1.2 | JSR-250 | 1.3 | http://download.oracle.com/otndocs/jcp/common_annotations-1_3-mrel3-spec/[JSR-250] | Common Annotations for the Java Platform | 1.2 | JSR-250 | 1.3 | http://download.oracle.com/otndocs/jcp/common_annotations-1_3-mrel3-spec/[JSR-250]
| Java EE Security API | - | - | 1.0 | https://jcp.org/aboutJava/communityprocess/final/jsr375/index.html[JSR-375]
|======================================================================= |=======================================================================


[[download]] [[download]]
Expand Down
110 changes: 110 additions & 0 deletions ee-security/pom.xml
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2010, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<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>org.wildfly</groupId>
<artifactId>wildfly-parent</artifactId>
<!--
Maintain separation between the artifact id and the version to help prevent
merge conflicts between commits changing the GA and those changing the V.
-->
<version>13.0.0.Alpha1-SNAPSHOT</version>
</parent>

<artifactId>wildfly-ee-security</artifactId>

<name>WildFly: Java EE Security</name>

<dependencies>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-ee</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-weld</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>

<dependency>
<groupId>org.glassfish.soteria</groupId>
<artifactId>javax.security.enterprise</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
<!-- This is a compile-time dependency of this project, but is not needed at compile or runtime by other
projects that depend on this project.-->
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
<!-- This is a compile-time dependency of this project, but is not needed at compile or runtime by other
projects that depend on this project.-->
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jboss.msc</groupId>
<artifactId>jboss-msc</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-subsystem-test</artifactId>
<type>pom</type>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2018 Red Hat, inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.wildfly.extension.eesecurity;

import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.jandex.DotName;

class EESecurityAnnotationProcessor implements DeploymentUnitProcessor {

static final AttachmentKey<Boolean> SECURITY_PRESENT = AttachmentKey.create(Boolean.class);

static final DotName[] ANNOTATIONS = {
DotName.createSimple("javax.security.enterprise.authentication.mechanism.http.BasicAuthenticationMechanismDefinition"),
DotName.createSimple("javax.security.enterprise.authentication.mechanism.http.CustomFormAuthenticationMechanismDefinition"),
DotName.createSimple("javax.security.enterprise.authentication.mechanism.http.FormAuthenticationMechanismDefinition"),
DotName.createSimple("javax.security.enterprise.identitystore.DatabaseIdentityStoreDefinition"),
DotName.createSimple("javax.security.enterprise.identitystore.LdapIdentityStoreDefinition")
};

static final DotName[] INTERFACES = {
DotName.createSimple("javax.security.enterprise.authentication.mechanism.http.HttpAuthenticationMechanism"),
DotName.createSimple("javax.security.enterprise.identitystore.IdentityStoreHandler"),
DotName.createSimple("javax.security.enterprise.identitystore.IdentityStore"),
DotName.createSimple("javax.security.enterprise.identitystore.RememberMeIdentityStore")
};

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
for (DotName annotation : ANNOTATIONS) {
if (!index.getAnnotations(annotation).isEmpty()) {
markAsEESecurity(deploymentUnit);
return;
}
}
for (DotName annotation : INTERFACES) {
if (!index.getAllKnownImplementors(annotation).isEmpty()) {
markAsEESecurity(deploymentUnit);
return;
}
}

}

private void markAsEESecurity(DeploymentUnit deploymentUnit) {
DeploymentUnit top = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
top.putAttachment(SECURITY_PRESENT, true);
}

@Override
public void undeploy(DeploymentUnit context) {

}
}
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2018 Red Hat, inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.wildfly.extension.eesecurity;

import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.module.ModuleDependency;
import org.jboss.as.server.deployment.module.ModuleSpecification;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleIdentifier;
import org.jboss.modules.ModuleLoader;

class EESecurityDependencyProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

final DeploymentUnit unit = phaseContext.getDeploymentUnit();
final DeploymentUnit top = unit.getParent() == null ? unit : unit.getParent();
final ModuleLoader moduleLoader = Module.getBootModuleLoader();

final ModuleSpecification moduleSpec = unit.getAttachment(Attachments.MODULE_SPECIFICATION);
moduleSpec.addSystemDependency(new ModuleDependency(moduleLoader, ModuleIdentifier.fromString("javax.security.enterprise.api"), false, false, true, false));

Boolean securityPresent = top.getAttachment(EESecurityAnnotationProcessor.SECURITY_PRESENT);
if(securityPresent != null && securityPresent) {
moduleSpec.addSystemDependency(new ModuleDependency(moduleLoader, ModuleIdentifier.fromString("org.glassfish.soteria"), false, false, true, false));
}

}

@Override
public void undeploy(DeploymentUnit deploymentUnit) {

}
}

0 comments on commit 8f303e3

Please sign in to comment.