Example usage for javax.xml.registry Connection getCredentials

List of usage examples for javax.xml.registry Connection getCredentials

Introduction

In this page you can find the example usage for javax.xml.registry Connection getCredentials.

Prototype

public Set getCredentials() throws JAXRException;

Source Link

Document

Gets the credentials associated with this client.

Usage

From source file:it.cnr.icar.eric.client.xml.registry.util.JAXRUtility.java

/**
 * This method is used to add special rim:Slot to the RegistryRequestType
 * object to indicate that the server should create a secure session.
 *
 * @param req/*from   w  ww.  ja va2  s. c om*/
 *   The RegistryRequestType to which the rim:Slot will be added
 * @param connection
 *   A javax.registry.Connection implementation.  This method will use this
 *   class to determine if a secure session should be created:
 *   If the connection's credential set is empty, do not create session.
 *   Empty credentials means the user has not authenticated. Thus, the
 *   user defaults to RegistryGuest and secure session is not needed.
 */
public static void addCreateSessionSlot(RegistryRequestType req, Connection connection) throws JAXBException {

    // check if there are credentials.  If not, there is no need for a
    // secure session as the UserType is RegistryGuest
    boolean isEmpty = true;
    try {
        isEmpty = connection.getCredentials().isEmpty();
    } catch (JAXRException ex) {
        log.error(JAXRResourceBundle.getInstance()
                .getString("message.CouldNotGetCredentialsFromConnectionObjectPresumeCorruptedCredentials"));
    }

    // This property allows the user to control whether or not to use
    // secure sessions.  Default is 'true'.
    String createSecureSession = ProviderProperties.getInstance()
            .getProperty("jaxr-ebxml.security.createSecureSession", "true");
    if ((!isEmpty) && createSecureSession.equalsIgnoreCase("true")) {
        HashMap<String, String> slotMap = new HashMap<String, String>();
        slotMap.put("urn:javax:xml:registry:connection:createHttpSession", "true");
        BindingUtility.getInstance().addSlotsToRequest(req, slotMap);
    }
}