/* * Copyright 2006-2008 Sxip Identity Corporation */ package org.openid4java.message.sreg; import org.openid4java.message.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Base class for the Simple Registration implementation. *

* Encapsulates: *

* * Considering that: * * * Support for Simple Registration is implemented as follows: * * * @see Message MessageExtension * @author Marius Scurtescu, Johnny Bufu */ public class SRegMessage implements MessageExtension, MessageExtensionFactory { private static Log _log = LogFactory.getLog(SRegMessage.class); private static final boolean DEBUG = _log.isDebugEnabled(); /** * The Simple Registration Type URI. */ public static final String OPENID_NS_SREG = "http://openid.net/sreg/1.0"; public static final String OPENID_NS_SREG11 = "http://openid.net/extensions/sreg/1.1"; /** * The Simple Registration extension-specific parameters. *

* The openid. prefix is not part of the parameter names */ protected ParameterList _parameters; private String _typeUri = OPENID_NS_SREG; /** * Constructs an empty (no parameters) Simple Registration extension. */ public SRegMessage() { _parameters = new ParameterList(); if (DEBUG) _log.debug("Created empty SRegMessage."); } /** * Constructs an Simple Registration extension with a specified list of * parameters. *

* The parameter names in the list should not contain the * openid.. */ public SRegMessage(ParameterList params) { _parameters = params; if (DEBUG) _log.debug("Created SRegMessage from parameter list:\n" + params); } /** * Gets the Type URI that identifies the Simple Registration extension. */ public String getTypeUri() { return _typeUri; } /** * Sets the SREG type URI. Hack to support both SREG 1.0 and 1.1, * until 1.1 spec gets fixed. */ public void setTypeUri(String typeUri) { _typeUri = typeUri; } /** * Gets ParameterList containing the Simple Registration extension-specific * parameters. *

* The openid. prefix is not part of the parameter names, * as it is handled internally by the Message class. *

* The openid.ns. parameter is also handled by * the Message class. * * @see Message */ public ParameterList getParameters() { return _parameters; } /** * Gets a the value of the parameter with the specified name. * * @param name The name of the parameter, * without the openid. prefix. * @return The parameter value, or null if not found. */ public String getParameterValue(String name) { return _parameters.getParameterValue(name); } /** * Sets the extension's parameters to the supplied list. *

* The parameter names in the list should not contain the * openid. prefix. */ public void setParameters(ParameterList params) { _parameters = params; } /** * Encodes a string value according to the conventions for supporting * multiple values for a parameter (commas and backslashes are escaped). * * @param value String value to be encoded. * @return The encoded value. */ public String multivalEncode(String value) { return value.replaceAll("\\\\", "\\\\\\\\").replaceAll(",","\\\\,"); } /** * Decodes a string value according to the conventions for supporting * multiple values for a parameter (commas and backslashes are escaped). * * @param value String value to be decoded. * @return The dencoded value. */ public String multivalDecode(String value) { return value.replaceAll("\\\\,", ",").replaceAll("\\\\\\\\","\\\\"); } /** * Simple Registration doesn't implement authentication services. * * @return false */ public boolean providesIdentifier() { return false; } /** * Simple registration parameters are REQUIRED to be signed. * * @return true */ public boolean signRequired() { return true; } /** * Instantiates the apropriate Simple Registration object * (request / response) for the supplied parameter list. * * @param parameterList The Simple Registration specific parameters * (without the openid. prefix) * extracted from the openid message. * @param isRequest Indicates whether the parameters were * extracted from an OpenID request (true), * or from an OpenID response. * @return MessageExtension implementation for * the supplied extension parameters. * @throws MessageException If a Simple Registration object could not be * instantiated from the supplied parameter list. */ public MessageExtension getExtension( ParameterList parameterList, boolean isRequest) throws MessageException { if ( parameterList.hasParameter("required") || parameterList.hasParameter("optional")) return SRegRequest.createSRegRequest(parameterList); else return SRegResponse.createSRegResponse(parameterList); } }