/** * @param authHeader * @param qnameAuthHeader * @param soapHeader * @return SOAPHeaderElement */ private SOAPHeaderElement ProcessAuthHeader( AuthHeader authHeader, QName qnameAuthHeader, SOAPHeader soapHeader) { SOAPHeaderElement headerElement; try { /* * Create the authentication header element */ headerElement = soapHeader.addHeaderElement(qnameAuthHeader); /* * Check if Identifier is specified */ if (authHeader.getIdentifier() != null) { /* * Create Identifier element */ QName qName = new QName( qnameAuthHeader.getNamespaceURI(), AuthHeader.STR_Identifier, qnameAuthHeader.getPrefix()); SOAPElement element = soapFactory.createElement(qName); element.addTextNode(authHeader.getIdentifier()); headerElement.addChildElement(element); } /* * Check if PassKey is specified */ if (authHeader.getPasskey() != null) { /* * Create PassKey element */ QName qName = new QName( qnameAuthHeader.getNamespaceURI(), AuthHeader.STR_Passkey, qnameAuthHeader.getPrefix()); SOAPElement element = soapFactory.createElement(qName); element.addTextNode(authHeader.getPasskey()); headerElement.addChildElement(element); } } catch (SOAPException ex) { headerElement = null; } return headerElement; }
/** * @param authHeader * @return String */ private String Authenticate(AuthHeader authHeader) { String sbName = null; /* * Check if logging authentication information */ LabManagement labManagement = this.labServerBean.getLabManagement(); if (labManagement.isLogAuthentication() == true) { if (authHeader == null) { Logfile.Write(STRLOG_AuthHeaderNull); } else { Logfile.Write( String.format( STRLOG_IdentifierPasskey_arg2, authHeader.getIdentifier(), authHeader.getPasskey())); } } try { /* * Check when authenticating that AuthHeader and ServiceBroker Guid are specified */ if (authHeader == null) { if (labManagement.isAuthenticating() == true) { throw new NullPointerException(String.format(STRERR_NotSpecified_arg, STRERR_AuthHeader)); } /* * Probably using WebService tester, set name to localhost */ return LabConsts.STR_SbNameLocalHost; } if (authHeader.getIdentifier() == null) { throw new NullPointerException( String.format(STRERR_NotSpecified_arg, STRERR_ServiceBrokerGuid)); } /* * Check if the ServiceBrokerInfo for this ServiceBroker Guid exists */ ServiceBrokerInfo serviceBrokerInfo = labManagement.getMapServiceBrokerInfo().get(authHeader.getIdentifier()); if (serviceBrokerInfo == null) { throw new NullPointerException(String.format(STRERR_Invalid_arg, STRERR_ServiceBrokerGuid)); } /* * Verify the passkey */ if (authHeader.getPasskey() == null) { throw new NullPointerException(String.format(STRERR_NotSpecified_arg, STRERR_Passkey)); } if (authHeader.getPasskey().equalsIgnoreCase(serviceBrokerInfo.getOutPasskey()) == false) { throw new IllegalArgumentException(String.format(STRERR_Invalid_arg, STRERR_Passkey)); } /* * Check that the ServiceBroker is permitted access */ if (serviceBrokerInfo.isPermitted() == false) { throw new RuntimeException(STRERR_AccessNotPermitted); } /* * Successfully authenticated */ sbName = serviceBrokerInfo.getName(); } catch (Exception ex) { String message = String.format(STRERR_AccessDenied_arg, ex.getMessage()); Logfile.WriteError(message); throw new RuntimeException(message); } return sbName; }