Skip to content

Commit

Permalink
Issue890 (jakartaee#891)
Browse files Browse the repository at this point in the history
* Add bean defining annotation

* Update the Jakarta Authentication based classes with missing methods, jakartaee#890

Signed-off-by: Scott M Stark <starksm64@gmail.com>

* Fix the whitespace changes

Signed-off-by: Scott M Stark <starksm64@gmail.com>

* Fix more auth related compile errors

Signed-off-by: Scott M Stark <starksm64@gmail.com>

* More auth fixes

Signed-off-by: Scott M Stark <starksm64@gmail.com>

* Update the serverAuthModule.initialze call

Signed-off-by: Scott M Stark <starksm64@gmail.com>
  • Loading branch information
starksm64 committed Mar 14, 2022
1 parent eeb402d commit 1bf3cb4
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
import com.sun.ts.tests.ejb30.common.lite.EJBLiteClientBase;

import jakarta.annotation.Resource;
import jakarta.enterprise.context.ApplicationScoped;

/**
* This test directory contains an empty beans.xml that will be packaged in WAR
* as WEB-INF/beans.xml. This is to verify when CDI is enabled, the overriding
* of ManagedBean's lifecycle methods still works. The similar tests without
* beans.xml are in ../lifecycle.
*/
@ApplicationScoped
public class Client extends EJBLiteClientBase {

@Resource
Expand Down
13 changes: 7 additions & 6 deletions src/com/sun/ts/tests/jaspic/spi/common/CommonTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.sun.ts.tests.jaspic.spi.common;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
Expand Down Expand Up @@ -940,7 +941,7 @@ private boolean testPrecedenceRule4(AuthConfigFactory acf,
String layer2 = "layer4";
String context2 = "context 4";
String rId1 = null, rId2 = null;
Properties props;
Map<String,String> props;
String strDesc1 = "acp4";
String strDesc2 = "acp4b";

Expand Down Expand Up @@ -1031,7 +1032,7 @@ private boolean testPrecedenceRule3(AuthConfigFactory acf,
String APP_CTXT = "context3";
String rId = null;
String rId2 = null;
Properties props;
Map<String,String> props;
String strDesc1 = "acp3";
String strDesc2 = "acp3a";

Expand Down Expand Up @@ -1089,7 +1090,7 @@ private boolean testPrecedenceRule2(AuthConfigFactory acf,
TSAuthConfigProviderStandalone acp2, acp2a;
String rId = null;
String rId2 = null;
Properties props;
Map<String,String> props;
String strDesc1 = "acp2";
String strDesc2 = "acp2a";

Expand Down Expand Up @@ -1180,9 +1181,9 @@ private boolean testPrecedenceRule1(AuthConfigFactory acf, String regId,
* property to set the description when we are creating a new/persistent ACP
* registration.
*/
private Properties setDescriptionProp(String val) {
Properties props = new Properties();
props.setProperty(TSAuthConfigProviderStandalone.DESC_KEY, val);
private Map<String, String> setDescriptionProp(String val) {
HashMap<String,String> props = new HashMap<>();
props.put(TSAuthConfigProviderStandalone.DESC_KEY, val);
return props;
}

Expand Down
12 changes: 6 additions & 6 deletions src/com/sun/ts/tests/jaspic/spi/common/CommonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.io.Serializable;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import com.sun.ts.tests.jaspic.tssv.util.JASPICData;
Expand Down Expand Up @@ -102,7 +104,7 @@ public static AuthConfigFactory register(String logFileLocation,

printIt(
"Registering Provider " + pce.getProviderClassName() + " ...");
Properties newProps = getCleanACPProps(pce.getProperties());
Map<String,String> newProps = getCleanACPProps(pce.getProperties());
acf.registerConfigProvider(pce.getProviderClassName(), newProps,
pce.getMessageLayer(), pce.getApplicationContextId(),
pce.getRegistrationDescription());
Expand All @@ -129,20 +131,18 @@ public static AuthConfigFactory register(String logFileLocation,
return acf;
}

private static Properties getCleanACPProps(Properties origProps) {
private static Map<String,String> getCleanACPProps(Map<String,String> origProps) {

if (origProps == null) {
return null;
}

Properties props = new Properties();
HashMap<String,String> props = new HashMap<>();

// loop thru passed in props and remove anything that is
// not of type String since only Strings are allowed in our
// calls to registerConfigProvider()
Enumeration eProps = origProps.keys();
while (eProps.hasMoreElements()) {
String key = (String) eProps.nextElement();
for(String key : origProps.keySet()) {
if (key != null) {
Object val = origProps.get(key);
if ((val != null) && ((val instanceof java.lang.String))) {
Expand Down
52 changes: 52 additions & 0 deletions src/com/sun/ts/tests/jaspic/tssv/config/TSAuthConfigFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import jakarta.security.auth.message.AuthException;
import jakarta.security.auth.message.config.AuthConfigProvider;
import jakarta.security.auth.message.config.RegistrationListener;
import jakarta.security.auth.message.module.ServerAuthModule;

/**
*
Expand Down Expand Up @@ -577,6 +578,57 @@ public String registerConfigProvider(AuthConfigProvider provider,
return result;
}

/**
* Registers within the (in-memory) factory, an instance of a <code>ServerAuthModule</code> for a
* message layer and application context identifier as identified by a profile specific context object.
*
* <p>
* This will override any other modules that have already been registered, either via proprietary
* means or using the standard API. The <code>ServerAuthModule</code> is removed, via a call to
* <code>removeServerAuthModule</code> when the context associated with the profile specific context object ends.
*
* <p>
* Note that this method is a convenience method that can be used instead of <code>registerConfigProvider</code>,
* but should ultimately have the same effect. That is, the <code>layer</code> and <code>appContext</code> parameters
* are generated from the context object, and the <code>ServerAuthModule</code> is wrapped by an implementation
* specific <code>AuthConfigProvider</code>, which are then used to call <code>registerConfigProvider</code> or an
* internal method with the same effect. The returned registration ID is then associated with the profile specific
* context object, and also returned from this method.
*
* <p>
* A "profile specific context object" is for example the <code>ServletContext</code> in the
* Servlet Container Profile. The context associated with this <code>ServletContext</code> ends
* when for example the application corresponding to it is undeployed. Association of the
* registration ID with the <code>ServletContext</code> simply means calling the <code>setAttribute</code>
* method on the <code>ServletContext</code>, with the registration ID as value. (The name attribute has not been
* standardised in this version of the specification)
*
* @param serverAuthModule the <code>ServerAuthModule</code> instance to be registered
* @param context the profile specific context of the application for which the module is registered
* @return A String identifier assigned by the factory to the provider registration, and that may be used to remove the
* registration from the factory.
*/
public String registerServerAuthModule(ServerAuthModule serverAuthModule, Object context) {
logger.log(Level.INFO, "registerServerAuthModule() called for serverAuthModule " + serverAuthModule
+ " and context " + context);
return context.toString();
}

/**
* Remove the <code>ServerAuthModule</code> (and potentially encompassing wrappers/factories) that was previously registered via a call
* to <code>registerServerAuthModule</code>.
*
* <p>
* Note that this method is a convenience method that can be used instead of <code>removeRegistration</code>, but should ultimately
* have the same effect. That is calling <code>removeRegistration</code> with the return value from <code>registerServerAuthModule</code>
* must have the same effect in that the <code>ServerAuthModule</code> is removed.
*
* @param context the profile specific context of the application for which the module is removed.
*/
public void removeServerAuthModule(Object context) {
logger.log(Level.INFO, "removeServerAuthModule() called for context " + context);
}

/**
* Cause the factory to reprocess its persisent declarative representation of
* provider registrations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
Expand All @@ -36,6 +37,7 @@
import jakarta.security.auth.message.AuthException;
import jakarta.security.auth.message.config.AuthConfigProvider;
import jakarta.security.auth.message.config.RegistrationListener;
import jakarta.security.auth.message.module.ServerAuthModule;

/**
*
Expand Down Expand Up @@ -105,7 +107,7 @@ private void readProviderConfigurationXMLFile() {
pce = (ProviderConfigurationEntry) iterator.next();

if (pce != null) {
Properties newProps = getCleanACPProps(pce.getProperties());
Map<String,String> newProps = getCleanACPProps(pce.getProperties());
registerConfigProvider(pce.getProviderClassName(), newProps,
pce.getMessageLayer(), pce.getApplicationContextId(),
pce.getRegistrationDescription());
Expand All @@ -130,20 +132,18 @@ private void readProviderConfigurationXMLFile() {
* method. This method will 'clean' a Property map so that its props can be
* passed to the registerConfigProvider() method.
*/
private Properties getCleanACPProps(Properties origProps) {
private Map<String,String> getCleanACPProps(Map<String,String> origProps) {

if (origProps == null) {
return null;
}

Properties props = new Properties();
HashMap<String,String> props = new HashMap<>();

// loop thru passed in props and remove anything that is
// not of type String since only String type Props are allowed in our
// calls to registerConfigProvider()
Enumeration eProps = origProps.keys();
while (eProps.hasMoreElements()) {
String key = (String) eProps.nextElement();
for(String key : origProps.keySet()) {
if (key != null) {
Object val = origProps.get(key);
if ((val != null) && ((val instanceof java.lang.String))) {
Expand Down Expand Up @@ -507,7 +507,7 @@ public String registerConfigProvider(String className, Map properties,
* registration identifiers to registrations, and must never assign a
* previously used registration identifier to a registration whose message
* layer and or appContext identifier differ from the previous use.
*
*
* @param provider
* the AuthConfigProvider to be registered at the factory (or null).
* Calling this method with a null value for this parameter shall
Expand Down Expand Up @@ -591,6 +591,57 @@ public String registerConfigProvider(AuthConfigProvider provider,
return result;
}

/**
* Registers within the (in-memory) factory, an instance of a <code>ServerAuthModule</code> for a
* message layer and application context identifier as identified by a profile specific context object.
*
* <p>
* This will override any other modules that have already been registered, either via proprietary
* means or using the standard API. The <code>ServerAuthModule</code> is removed, via a call to
* <code>removeServerAuthModule</code> when the context associated with the profile specific context object ends.
*
* <p>
* Note that this method is a convenience method that can be used instead of <code>registerConfigProvider</code>,
* but should ultimately have the same effect. That is, the <code>layer</code> and <code>appContext</code> parameters
* are generated from the context object, and the <code>ServerAuthModule</code> is wrapped by an implementation
* specific <code>AuthConfigProvider</code>, which are then used to call <code>registerConfigProvider</code> or an
* internal method with the same effect. The returned registration ID is then associated with the profile specific
* context object, and also returned from this method.
*
* <p>
* A "profile specific context object" is for example the <code>ServletContext</code> in the
* Servlet Container Profile. The context associated with this <code>ServletContext</code> ends
* when for example the application corresponding to it is undeployed. Association of the
* registration ID with the <code>ServletContext</code> simply means calling the <code>setAttribute</code>
* method on the <code>ServletContext</code>, with the registration ID as value. (The name attribute has not been
* standardised in this version of the specification)
*
* @param serverAuthModule the <code>ServerAuthModule</code> instance to be registered
* @param context the profile specific context of the application for which the module is registered
* @return A String identifier assigned by the factory to the provider registration, and that may be used to remove the
* registration from the factory.
*/
public String registerServerAuthModule(ServerAuthModule serverAuthModule, Object context) {
logger.log(Level.INFO, "registerServerAuthModule() called for serverAuthModule " + serverAuthModule
+ " and context " + context);
return context.toString();
}

/**
* Remove the <code>ServerAuthModule</code> (and potentially encompassing wrappers/factories) that was previously registered via a call
* to <code>registerServerAuthModule</code>.
*
* <p>
* Note that this method is a convenience method that can be used instead of <code>removeRegistration</code>, but should ultimately
* have the same effect. That is calling <code>removeRegistration</code> with the return value from <code>registerServerAuthModule</code>
* must have the same effect in that the <code>ServerAuthModule</code> is removed.
*
* @param context the profile specific context of the application for which the module is removed.
*/
public void removeServerAuthModule(Object context) {
logger.log(Level.INFO, "removeServerAuthModule() called for context " + context);
}

/**
* Cause the factory to reprocess its persisent declarative representation of
* provider registrations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.sun.ts.tests.jaspic.tssv.util;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.w3c.dom.NamedNodeMap;
Expand All @@ -31,7 +33,7 @@ public class ProviderConfigurationEntry implements Serializable {

private String providerClassName = null;

private Properties properties = null;
private Map<String,String> properties = null;

private String messageLayer = null;

Expand Down Expand Up @@ -87,7 +89,7 @@ public ProviderConfigurationEntry(Node providerConfigEntryNode)
// <entry key="AuthStatus_SEND_SUCCESS">true</entry>
// <entry key="requestPolicy">USER_NAME_PASSWORD</entry>
// </properties>
private static Properties loadProperties(Node node) {
private static Map<String,String> loadProperties(Node node) {
Node topLevelChildNode = null;
String topLevelNodeName;
String key = null;
Expand All @@ -114,7 +116,9 @@ private static Properties loadProperties(Node node) {
}
}

return nodeProperties;
HashMap<String,String> map = new HashMap<>();
nodeProperties.stringPropertyNames().forEach((tmpkey) -> map.put(tmpkey, nodeProperties.getProperty(tmpkey)));
return map;
}

public String getProviderClassName() {
Expand All @@ -133,7 +137,7 @@ public String getRegistrationDescription() {
return registrationDescription;
}

public Properties getProperties() {
public Map<String, String> getProperties() {
return properties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public TestServerAuthContext(CallbackHandler handler,
ServerAuthModule serverAuthModule) throws AuthException {
this.serverAuthModule = serverAuthModule;
serverAuthModule.initialize(null, null, handler,
Collections.<String, String> emptyMap());
Collections.<String, Object> emptyMap());
}

@Override
Expand Down

0 comments on commit 1bf3cb4

Please sign in to comment.