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-1183 default web service realm configuration #1760

Merged
merged 2 commits into from
Jul 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016] [Payara Foundation and/or its affiliates]
// Portions Copyright [2016-2017] [Payara Foundation and/or its affiliates]

package com.sun.enterprise.deployment.xml;

Expand Down Expand Up @@ -108,6 +108,7 @@ public interface RuntimeTagNames extends TagNames {
public static final String EJB_NAME = "ejb-name";
public static final String EJB20_CMP = "ejb20-cmp";
public static final String EJBS = "enterprise-beans";
public static final String WEBSERVICE_DEFAULT_LOGIN_CONFIG = "webservice-default-login-config";
public static final String FIELD = "field";

public static final String GROUP = "group";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
only if the new code is made subject to such option by the copyright
holder.

Portions Copyright [2016] [C2B2 Consulting Limited and/or its affiliates]
Portions Copyright [2016-2017] [Payara Foundation and/or its affiliates]
-->

<!--
Expand All @@ -65,7 +65,7 @@ System unique object id. Automatically generated and updated at deployment/redep
This is the root element describing all the runtime of an ejb-jar in the application.
-->
<!ELEMENT enterprise-beans (name?, unique-id?, ejb*, pm-descriptors?, cmp-resource?,
message-destination*, webservice-description*, property*)>
message-destination*, webservice-description*, property*, webservice-default-login-config?)>

<!--
This is the element describing runtime bindings for a single ejb.
Expand Down Expand Up @@ -1194,3 +1194,9 @@ Syntax for supplying properties as name value pairs
value CDATA #REQUIRED>

<!ELEMENT description (#PCDATA)>

<!--
Optional Default authentication configuration for an EJB web service endpoint.
The individual bean's configuration takes precedence, but this is the default
-->
<!ELEMENT webservice-default-login-config ( auth-method, realm? )>
2 changes: 1 addition & 1 deletion appserver/ejb/ejb-container/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
holder.

-->
<!-- Portions Copyright [2016] [Payara Foundation] -->
<!-- // Portions Copyright [2016-2017] [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>
<parent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2016-2017] 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 org.glassfish.ejb.deployment.node.runtime;

import com.sun.enterprise.deployment.EjbBundleDescriptor;
import com.sun.enterprise.deployment.WebService;
import com.sun.enterprise.deployment.WebServiceEndpoint;
import com.sun.enterprise.deployment.node.XMLElement;
import com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode;
import com.sun.enterprise.deployment.xml.RuntimeTagNames;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Adds default login configuration to all Web Service EJB nodes
*
* @author lprimak
*/
public class DefaultWebServiceLoginConfigNode extends RuntimeDescriptorNode {
@Override
protected Map getDispatchTable() {
@SuppressWarnings("unchecked")
Map<String, String> table = super.getDispatchTable();
table.put(RuntimeTagNames.AUTH_METHOD, "setAuthMethod");
table.put(RuntimeTagNames.REALM, "setRealm");
return table;
}

@Override
public Object getDescriptor() {
return this;
}

@Override
public boolean endElement(XMLElement element) {
log.log(Level.FINEST, "End Element: {0}", element.getQName());
if (authMethod != null && element.getQName().equals(RuntimeTagNames.WEBSERVICE_DEFAULT_LOGIN_CONFIG)) {
EjbBundleDescriptor descriptor = (EjbBundleDescriptor) getParentNode().getDescriptor();
for (WebService wsDesc : descriptor.getWebServices().getWebServices()) {
for (WebServiceEndpoint endpoint : wsDesc.getEndpoints()) {
if (!endpoint.hasAuthMethod()) {
log.log(Level.FINE, "Default Login for Web Service Endpoint: {0}, Method {1}, Realm {2}",
new Object[]{ endpoint.getName(), authMethod, realm});
endpoint.setAuthMethod(authMethod);
endpoint.setRealm(realm);
}
}
}
}
return super.endElement(element);
}

public void setRealm(String realm) {
log.log(Level.FINEST, "Global Setting Realm: {0}", realm);
this.realm = realm;
}

public void setAuthMethod(String authMethod) {
log.log(Level.FINEST, "Global Setting Auth Method: {0}", authMethod);
this.authMethod = authMethod;
}

private String realm;
private String authMethod;
private static final Logger log = Logger.getLogger(DefaultWebServiceLoginConfigNode.class.getName());
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016] [C2B2 Consulting Limited and/or its affiliates]
// Portions Copyright [2016-2017] [Payara Foundation and/or its affiliates]

package org.glassfish.ejb.deployment.node.runtime;

Expand Down Expand Up @@ -81,6 +81,8 @@ public EjbBundleRuntimeNode(EjbBundleDescriptorImpl descriptor) {
EnterpriseBeansRuntimeNode.class);
registerElementHandler(new XMLElement(RuntimeTagNames.PROPERTY),
ResourcePropertyNode.class);
registerElementHandler(new XMLElement(RuntimeTagNames.WEBSERVICE_DEFAULT_LOGIN_CONFIG),
DefaultWebServiceLoginConfigNode.class);
}

public EjbBundleRuntimeNode() {
Expand Down