Skip to content

Commit

Permalink
[WFLY-9302] At JCA code, fix metadata class casts and add assertions …
Browse files Browse the repository at this point in the history
…at all points that elytron metadata is required
  • Loading branch information
fl4via committed Sep 6, 2017
1 parent 76cdeb6 commit 01dfa68
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
Expand Up @@ -43,7 +43,6 @@
import java.util.concurrent.ThreadFactory;

import org.jboss.as.connector.logging.ConnectorLogger;
import org.jboss.as.connector.metadata.api.common.SecurityMetadata;
import org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity;
import org.jboss.as.connector.metadata.deployment.ResourceAdapterDeployment;
import org.jboss.as.connector.security.CallbackImpl;
Expand All @@ -65,6 +64,7 @@
import org.jboss.as.naming.WritableServiceBasedNamingStore;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.naming.service.BinderService;
import org.jboss.jca.common.api.metadata.common.SecurityMetadata;
import org.jboss.jca.common.api.metadata.resourceadapter.Activation;
import org.jboss.jca.common.api.metadata.spec.ConfigProperty;
import org.jboss.jca.common.api.metadata.spec.Connector;
Expand Down Expand Up @@ -618,12 +618,12 @@ protected String registerResourceAdapterToResourceAdapterRepository(ResourceAdap

@Override
protected org.jboss.jca.core.spi.security.SubjectFactory getSubjectFactory(
org.jboss.jca.common.api.metadata.common.SecurityMetadata securityMetadata, final String jndiName) throws DeployException {
SecurityMetadata securityMetadata, final String jndiName) throws DeployException {
if (securityMetadata == null)
return null;
assert securityMetadata instanceof SecurityMetadata;
final String securityDomain = securityMetadata.resolveSecurityDomain();
if (((SecurityMetadata)securityMetadata).isElytronEnabled()) {
if (securityMetadata instanceof org.jboss.as.connector.metadata.api.common.SecurityMetadata &&
((org.jboss.as.connector.metadata.api.common.SecurityMetadata)securityMetadata).isElytronEnabled()) {
try {
return new ElytronSubjectFactory(null, new URI(jndiName));
} catch (URISyntaxException e) {
Expand Down
Expand Up @@ -460,6 +460,7 @@ protected org.jboss.jca.core.spi.security.SubjectFactory getSubjectFactory(
org.jboss.jca.common.api.metadata.common.Credential credential, final String jndiName) throws DeployException {
if (credential == null)
return null;
// safe assertion because all parsers create Credential
assert credential instanceof Credential;
final String securityDomain = credential.getSecurityDomain();
if (((Credential) credential).isElytronEnabled()) {
Expand Down
Expand Up @@ -174,6 +174,8 @@ private void handleDatasourceAttribute(final String attributeName, final Operati
if (dataSource.getSecurity() == null) {
return;
}
// this is a safe assert because DsXmlParser will always create a wildfly DsSecurity metadata
assert dataSource.getSecurity() instanceof DsSecurity;
if (((DsSecurity) dataSource.getSecurity()).isElytronEnabled()) {
return;
}
Expand All @@ -182,6 +184,8 @@ private void handleDatasourceAttribute(final String attributeName, final Operati
if (dataSource.getSecurity() == null) {
return;
}
// this is a safe assert because DsXmlParser will always create a wildfly DsSecurity metadata
assert dataSource.getSecurity() instanceof DsSecurity;
if (!((DsSecurity) dataSource.getSecurity()).isElytronEnabled()) {
return;
}
Expand All @@ -190,6 +194,8 @@ private void handleDatasourceAttribute(final String attributeName, final Operati
if (dataSource.getSecurity() == null) {
return;
}
// this is a safe assert because DsXmlParser will always create a wildfly DsSecurity metadata
assert dataSource.getSecurity() instanceof DsSecurity;
if (!((DsSecurity) dataSource.getSecurity()).isElytronEnabled()) {
return;
}
Expand Down
Expand Up @@ -245,6 +245,8 @@ else if (attributeName.equals(Constants.INTERLEAVING.getName())) {
if(dataSource.getRecovery().getCredential() == null) {
return;
}
// safe assertion because all parsers create jboss Credential
assert dataSource.getRecovery().getCredential() instanceof Credential;
if (((Credential) dataSource.getRecovery().getCredential()).isElytronEnabled()) {
return;
}
Expand All @@ -257,6 +259,8 @@ else if (attributeName.equals(Constants.INTERLEAVING.getName())) {
if(dataSource.getRecovery().getCredential() == null) {
return;
}
// safe assertion because all parsers create jboss Credential
assert dataSource.getRecovery().getCredential() instanceof Credential;
if (!((Credential) dataSource.getRecovery().getCredential()).isElytronEnabled()) {
return;
}
Expand All @@ -270,6 +274,8 @@ else if (attributeName.equals(Constants.INTERLEAVING.getName())) {
if(dataSource.getRecovery().getCredential() == null) {
return;
}
// safe assertion because all parsers create jboss Credential
assert dataSource.getRecovery().getCredential() instanceof Credential;
if (!((Credential) dataSource.getRecovery().getCredential()).isElytronEnabled()) {
return;
}
Expand Down Expand Up @@ -407,6 +413,8 @@ else if (attributeName.equals(Constants.INTERLEAVING.getName())) {
if (dataSource.getSecurity() == null) {
return;
}
// this is a safe assert because DsXmlParser will always create a wildfly DsSecurity metadata
assert dataSource.getSecurity() instanceof DsSecurity;
if (((DsSecurity) dataSource.getSecurity()).isElytronEnabled()) {
return;
}
Expand All @@ -415,6 +423,8 @@ else if (attributeName.equals(Constants.INTERLEAVING.getName())) {
if (dataSource.getSecurity() == null) {
return;
}
// this is a safe assert because DsXmlParser will always create a wildfly DsSecurity metadata
assert dataSource.getSecurity() instanceof DsSecurity;
if (!((DsSecurity) dataSource.getSecurity()).isElytronEnabled()) {
return;
}
Expand All @@ -423,6 +433,8 @@ else if (attributeName.equals(Constants.INTERLEAVING.getName())) {
if (dataSource.getSecurity() == null) {
return;
}
// this is a safe assert because DsXmlParser will always create a wildfly DsSecurity metadata
assert dataSource.getSecurity() instanceof DsSecurity;
if (!((DsSecurity) dataSource.getSecurity()).isElytronEnabled()) {
return;
}
Expand Down
Expand Up @@ -75,17 +75,17 @@

import java.util.Map;

import org.jboss.as.connector.metadata.api.common.Credential;
import org.jboss.as.connector.metadata.api.common.Security;
import org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity;
import org.jboss.as.connector.services.mdr.AS7MetadataRepository;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.registry.Resource;
import org.jboss.dmr.ModelNode;
import org.jboss.jca.common.api.metadata.common.Credential;
import org.jboss.jca.common.api.metadata.common.Extension;
import org.jboss.jca.common.api.metadata.common.Pool;
import org.jboss.jca.common.api.metadata.common.Recovery;
import org.jboss.jca.common.api.metadata.common.Security;
import org.jboss.jca.common.api.metadata.common.TimeOut;
import org.jboss.jca.common.api.metadata.common.Validation;
import org.jboss.jca.common.api.metadata.common.XaPool;
Expand Down Expand Up @@ -212,11 +212,12 @@ private void addConnectionDefinition(final Resource parent, ConnectionDefinition
setAttribute(model, NOTXSEPARATEPOOL, xaPool.isNoTxSeparatePool());
}
}
final Security security = (Security) connDef.getSecurity();
final Security security = connDef.getSecurity();
if (security != null) {
setAttribute(model, APPLICATION, security.isApplication());

if (security.isElytronEnabled()) {
if (security instanceof org.jboss.as.connector.metadata.api.common.Security &&
((org.jboss.as.connector.metadata.api.common.Security) security).isElytronEnabled()) {
setAttribute(model, ELYTRON_ENABLED, true);
setAttribute(model, AUTHENTICATION_CONTEXT, security.getSecurityDomain());
setAttribute(model, AUTHENTICATION_CONTEXT_AND_APPLICATION, security.getSecurityDomainAndApplication());
Expand Down Expand Up @@ -259,10 +260,11 @@ private void addConnectionDefinition(final Resource parent, ConnectionDefinition
}
}
}
final Credential recoveryCredential = (Credential) recovery.getCredential();
final Credential recoveryCredential = recovery.getCredential();
if (recoveryCredential != null) {
setAttribute(model, RECOVERY_PASSWORD, recoveryCredential.getPassword());
if (recoveryCredential.isElytronEnabled()) {
if (recoveryCredential instanceof org.jboss.as.connector.metadata.api.common.Credential &&
((org.jboss.as.connector.metadata.api.common.Credential) recoveryCredential).isElytronEnabled()) {
setAttribute(model, RECOVERY_ELYTRON_ENABLED, true);
setAttribute(model, RECOVERY_AUTHENTICATION_CONTEXT, recoveryCredential.getSecurityDomain());
} else {
Expand Down

0 comments on commit 01dfa68

Please sign in to comment.