Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2011, Red Hat Middleware LLC, 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.
  */
 package org.jboss.as.webservices.tomcat;
 
 import static org.jboss.as.webservices.WSMessages.MESSAGES;
 
 import java.util.List;
 import java.util.Set;
 
 import  org.jboss.metadata.ear.jboss.JBossAppMetaData;
 import  org.jboss.metadata.ear.spec.EarMetaData;
 import  org.jboss.metadata.javaee.spec.SecurityRoleMetaData;
 import  org.jboss.metadata.javaee.spec.SecurityRolesMetaData;
Creates web app security meta data for EJB deployment.

Author(s):
Richard Opalka
Thomas Diesler
 
 abstract class AbstractSecurityMetaDataAccessorEJB implements SecurityMetaDataAccessorEJB {

    

Parameters:
dep webservice deployment
Returns:
security domain associated with EJB 3 deployment
See also:
org.jboss.webservices.integration.tomcat.AbstractSecurityMetaDataAccessorEJB.getSecurityDomain(Deployment)
 
     public String getSecurityDomain(final Deployment dep) {
         String securityDomain = null;
 
         for (final EJBEndpoint ejbEndpoint : getEjbEndpoints(dep)) {
             String nextSecurityDomain = ejbEndpoint.getSecurityDomain();
             if(nextSecurityDomain.isEmpty()) {
                 nextSecurityDomain = null;
             }
             securityDomain = getDomain(securityDomainnextSecurityDomain);
         }
 
         if (securityDomain == null) {
             final DeploymentUnit unit = WSHelper.getRequiredAttachment(depDeploymentUnit.class);
             if (unit.getParent() != null) {
                 final EarMetaData jbossAppMD = unit.getParent().getAttachment(.);
                 return jbossAppMD instanceof JBossAppMetaData ? ((JBossAppMetaData)jbossAppMD).getSecurityDomain() : null;
             }
         }
 
         return securityDomain;
     }
 
     public SecurityRolesMetaData getSecurityRoles(final Deployment dep) {
         final SecurityRolesMetaData securityRolesMD = new SecurityRolesMetaData();
 
         Set<StringfirstEndpointDeclaredSecurityRoles = null;
         for (final EJBEndpoint ejbEndpoint : getEjbEndpoints(dep)) {
             final Set<StringdeclaredSecurityRoles = ejbEndpoint.getDeclaredSecurityRoles();
             if (firstEndpointDeclaredSecurityRoles == null) {
                 firstEndpointDeclaredSecurityRoles = declaredSecurityRoles;
             } else if (!firstEndpointDeclaredSecurityRoles.equals(declaredSecurityRoles)) {
             }
             //union of declared security roles from all endpoints...
             for (final String roleName : declaredSecurityRoles) {
                 final SecurityRoleMetaData securityRoleMD = new SecurityRoleMetaData();
                 securityRoleMD.setRoleName(roleName);
                 securityRolesMD.add(securityRoleMD);
             }
         }
 
         return securityRolesMD;
    }
    protected abstract List<EJBEndpointgetEjbEndpoints(final Deployment dep);

    

Parameters:
endpoint EJB webservice endpoint
Returns:
authentication method or null if not specified
See also:
org.jboss.webservices.integration.tomcat.SecurityMetaDataAccessorEJB.getAuthMethod(Endpoint)
    public String getAuthMethod(final Endpoint endpoint) {
        final EJBSecurityMetaData ejbSecurityMD = this.getEjbSecurityMetaData(endpoint);
        final boolean hasEjbSecurityMD = ejbSecurityMD != null;
        return hasEjbSecurityMD ? ejbSecurityMD.getAuthMethod() : null;
    }

    

Parameters:
endpoint EJB webservice endpoint
Returns:
whether WSDL access have to be secured
See also:
org.jboss.webservices.integration.tomcat.SecurityMetaDataAccessorEJB.isSecureWsdlAccess(Endpoint)
    public boolean isSecureWsdlAccess(final Endpoint endpoint) {
        final EJBSecurityMetaData ejbSecurityMD = this.getEjbSecurityMetaData(endpoint);
        final boolean hasEjbSecurityMD = ejbSecurityMD != null;
        return hasEjbSecurityMD ? ejbSecurityMD.getSecureWSDLAccess() : false;
    }

    

Parameters:
endpoint EJB webservice endpoint
Returns:
transport guarantee or null if not specified
See also:
org.jboss.webservices.integration.tomcat.SecurityMetaDataAccessorEJB.getTransportGuarantee(Endpoint)
    public String getTransportGuarantee(final Endpoint endpoint) {
        final EJBSecurityMetaData ejbSecurityMD = this.getEjbSecurityMetaData(endpoint);
        final boolean hasEjbSecurityMD = ejbSecurityMD != null;
        return hasEjbSecurityMD ? ejbSecurityMD.getTransportGuarantee() : null;
    }
    public String getRealmName(final Endpoint endpoint) {
        final EJBSecurityMetaData ejbSecurityMD = this.getEjbSecurityMetaData(endpoint);
        final boolean hasEjbSecurityMD = ejbSecurityMD != null;
        return hasEjbSecurityMD ? ejbSecurityMD.getRealmName() : null;
    }
    
Gets EJB security meta data if associated with EJB endpoint.

Parameters:
endpoint EJB webservice endpoint
Returns:
EJB security meta data or null
    private EJBSecurityMetaData getEjbSecurityMetaData(final Endpoint endpoint) {
        final String ejbName = endpoint.getShortName();
        final Deployment dep = endpoint.getService().getDeployment();
        final EJBArchiveMetaData ejbArchiveMD = WSHelper.getOptionalAttachment(depEJBArchiveMetaData.class);
        final EJBMetaData ejbMD = ejbArchiveMD != null ? ejbArchiveMD.getBeanByEjbName(ejbName) : null;
        return ejbMD != null ? ejbMD.getSecurityMetaData() : null;
    }

    
Returns security domain value. This method checks domain is the same for every EJB 3 endpoint.

Parameters:
oldSecurityDomain our security domain
nextSecurityDomain next security domain
Returns:
security domain value
Throws:
IllegalStateException if domains have different values
    private String getDomain(final String oldSecurityDomainfinal String nextSecurityDomain) {
        if (nextSecurityDomain == null) {
            return oldSecurityDomain;
        }
        if (oldSecurityDomain == null) {
            return nextSecurityDomain;
        }
        ensureSameDomains(oldSecurityDomainnextSecurityDomain);
        return oldSecurityDomain;
    }

    
This method ensures both passed domains contain the same value.

Parameters:
oldSecurityDomain our security domain
newSecurityDomain next security domain
Throws:
IllegalStateException if domains have different values
    private void ensureSameDomains(final String oldSecurityDomainfinal String newSecurityDomain) {
        final boolean domainsDiffer = !oldSecurityDomain.equals(newSecurityDomain);
        if (domainsDiffer)
            throw .multipleSecurityDomainsDetected(oldSecurityDomainnewSecurityDomain);
    }
New to GrepCode? Check out our FAQ X