use of com.sun.identity.liberty.ws.security.SecurityAssertion in project OpenAM by OpenRock.
the class MessageProcessor method secureRequest.
/**
* Secures the request by getting the credential from the discovery
* service.
*
* @param offering Resource Offering of the discovery service.
* @param credentials List of credentials that are required to access
* the discovery service.
* @param serviceType Service Type that the discovery service should
* need to look for.
* @param soapMessage SOAPMessage that needs to be secured.
* @param sharedData Any shared data that may be used between the request
* and the response.
* @return SOAPMessage Secured SOAP Message.
* @throws SOAPBindingException for any failure.
*/
public SOAPMessage secureRequest(ResourceOffering offering, List credentials, String serviceType, SOAPMessage soapMessage, Map sharedData) throws SOAPBindingException {
Utils.debug.message("MessageProcessor.secureRequest:Init");
try {
SOAPHeader header = addCorrelationHeader(soapMessage, null);
QueryResponse discoResponse = getWebserviceOffering(offering, credentials, serviceType);
if (Utils.debug.messageEnabled()) {
Utils.debug.message("MessageProcessor.secureRequest: " + "Discovery Response: " + discoResponse.toString());
}
ResourceOffering serviceOffering = (ResourceOffering) discoResponse.getResourceOffering().get(0);
List creds = discoResponse.getCredentials();
String securityProfile = processResourceOffering(serviceOffering);
SecurityAssertion securityAssertion = null;
// security token for this profile.
if (securityProfile.equals(Message.NULL_SAML) || securityProfile.equals(Message.TLS_SAML) || securityProfile.equals(Message.CLIENT_TLS_SAML) || securityProfile.equals(Message.NULL_BEARER) || securityProfile.equals(Message.TLS_BEARER) || securityProfile.equals(Message.CLIENT_TLS_BEARER) || securityProfile.equals(Message.NULL_SAML_WSF11) || securityProfile.equals(Message.TLS_SAML_WSF11) || securityProfile.equals(Message.CLIENT_TLS_SAML_WSF11) || securityProfile.equals(Message.NULL_BEARER_WSF11) || securityProfile.equals(Message.TLS_BEARER_WSF11) || securityProfile.equals(Message.CLIENT_TLS_BEARER_WSF11)) {
if (creds != null && creds.size() != 0) {
securityAssertion = (SecurityAssertion) creds.get(0);
securityAssertion.addToParent(header);
}
}
if (securityProfile.equals(Message.NULL_SAML) || securityProfile.equals(Message.TLS_SAML) || securityProfile.equals(Message.CLIENT_TLS_SAML) || securityProfile.equals(Message.NULL_X509) || securityProfile.equals(Message.TLS_X509) || securityProfile.equals(Message.CLIENT_TLS_X509) || securityProfile.equals(Message.NULL_SAML_WSF11) || securityProfile.equals(Message.TLS_SAML_WSF11) || securityProfile.equals(Message.CLIENT_TLS_SAML_WSF11) || securityProfile.equals(Message.NULL_X509_WSF11) || securityProfile.equals(Message.TLS_X509_WSF11) || securityProfile.equals(Message.CLIENT_TLS_X509_WSF11)) {
soapMessage = signMessage(soapMessage, securityProfile, securityAssertion);
}
if (Utils.debug.messageEnabled()) {
Utils.debug.message("MessageProcessor.secureRequest: " + XMLUtils.print(soapMessage.getSOAPPart().getEnvelope()));
}
return soapMessage;
} catch (Exception ex) {
Utils.debug.error("MessageProcessor.secureRequest: Failure in " + "Securing the request.", ex);
throw new SOAPBindingException(Utils.bundle.getString("secureRequestFailed"));
}
}
use of com.sun.identity.liberty.ws.security.SecurityAssertion in project OpenAM by OpenRock.
the class Default64ResourceIDMapper method getUserID.
/**
* Returns the ID of the user who has the resource ID in a provider.
* @param providerID ID of the provider.
* @param resourceID ID of the resource.
* @param message Request message.
* @return user ID. Return null if the user is not found.
*/
public String getUserID(String providerID, String resourceID, Message message) {
String result = null;
if ((resourceID == null) || (resourceID.equals(DiscoConstants.IMPLIED_RESOURCE))) {
if (debug.messageEnabled()) {
debug.message("Default64ResourceIDMapper.getUserID: used " + "implied resource.");
}
if (message == null) {
debug.error("Default64ResourceIDMapper.getUserID:null message");
return null;
} else {
SecurityAssertion assertion = message.getAssertion();
if (assertion == null) {
debug.error("Default64ResourceIDMapper.getUserID:null " + "assertion");
return null;
}
Subject subject = assertion.getBearerSubject();
if (subject == null) {
debug.error("Default64ResourceIDMapper.getUserID:not " + "Bearer Token");
return null;
}
NameIdentifier ni = subject.getNameIdentifier();
if (ni == null) {
debug.error("Default64ResourceIDMapper.getUserID:no " + "NameIdentifier");
return null;
}
return ni.getName();
}
}
if ((providerID == null) || (providerID.length() == 0)) {
debug.error("Default64ResourceIDMapper.getUserID:null providerID.");
return null;
}
if (!resourceID.startsWith(providerID)) {
debug.error("Default64ResourceIDMapper.getUserID:resourceID not " + "startsWith providerID:" + providerID);
return null;
}
String urlDecoded = null;
if (providerID.endsWith("/")) {
urlDecoded = URLEncDec.decode(resourceID.substring(providerID.length()));
} else {
urlDecoded = URLEncDec.decode(resourceID.substring((providerID + "/").length()));
}
try {
result = SAMLUtils.byteArrayToString(Base64.decode(urlDecoded));
} catch (Exception e) {
debug.error("Default64ResourceIDMapper.getUserID:", e);
return null;
}
return result;
}
use of com.sun.identity.liberty.ws.security.SecurityAssertion in project OpenAM by OpenRock.
the class DefaultHexResourceIDMapper method getUserID.
/**
* Returns the ID of the user who has the resource ID in a provider.
* @param providerID ID of the provider.
* @param resourceID ID of the resource.
* @param message Request message.
* @return user ID. Return null if the user is not found.
*/
public String getUserID(String providerID, String resourceID, Message message) {
if ((resourceID == null) || (resourceID.equals(DiscoConstants.IMPLIED_RESOURCE))) {
if (debug.messageEnabled()) {
debug.message("DefaultHexResourceIDMapper.getUserID: used " + "implied resource.");
}
if (message == null) {
debug.error("DefaultHexResourceIDMapper.getUserID:null message");
return null;
} else {
SecurityAssertion assertion = message.getAssertion();
if (assertion == null) {
debug.error("DefaultHexResourceIDMapper.getUserID:no " + "assertion");
return null;
}
Subject subject = assertion.getBearerSubject();
if (subject == null) {
debug.error("DefaultHexResourceIDMapper.getUserID:not " + "Bearer Token");
return null;
}
NameIdentifier ni = subject.getNameIdentifier();
if (ni == null) {
debug.error("DefaultHexResourceIDMapper.getUserID:no " + "NameIdentifier");
return null;
}
return ni.getName();
}
}
if ((providerID == null) || (providerID.length() == 0)) {
debug.error("DefaultHexResourceIDMapper.getUserID:null providerID");
return null;
}
if (!resourceID.startsWith(providerID)) {
debug.error("DefaultHexResourceIDMapper.getUserID:resourceID not " + "startsWith providerID:" + providerID);
return null;
}
if (providerID.endsWith("/")) {
return SAMLUtils.byteArrayToString(SAMLUtils.hexStringToByteArray(resourceID.substring(providerID.length())));
} else {
return SAMLUtils.byteArrayToString(SAMLUtils.hexStringToByteArray(resourceID.substring((providerID + "/").length())));
}
}
use of com.sun.identity.liberty.ws.security.SecurityAssertion in project OpenAM by OpenRock.
the class QueryResponse method parseCreds.
private void parseCreds(Element elem) throws DiscoveryException {
NodeList contentnl = elem.getChildNodes();
Node child;
String nodeName;
SecurityAssertion assertion;
for (int i = 0, length = contentnl.getLength(); i < length; i++) {
child = contentnl.item(i);
if ((nodeName = child.getLocalName()) != null) {
try {
assertion = new SecurityAssertion((Element) child);
} catch (SAMLException se) {
if (DiscoUtils.debug.messageEnabled()) {
DiscoUtils.debug.message("QueryResponse(Element): " + "Exception thrown when parsing Credentials:", se);
}
throw new DiscoveryException(DiscoUtils.bundle.getString("wrongCredential"));
}
if (creds == null) {
creds = new ArrayList();
}
creds.add(assertion);
}
}
}
use of com.sun.identity.liberty.ws.security.SecurityAssertion in project OpenAM by OpenRock.
the class LibertyManagerClient method getDiscoveryServiceCredential.
/**
* Returns the discovery service credential.
* @param token Single Sign On Token.
* @param hostProviderID Hosted <code>ProviderID</code>.
* @return <code>SecurityAssertion</code> Discovery Service Bootstrap
* Credential.
* @exception FSException if any failure.
*/
public SecurityAssertion getDiscoveryServiceCredential(Object token, String hostProviderID) throws FSException {
try {
String tokenID = SessionManager.getProvider().getSessionID(token);
String cacheKey = tokenID + DISCO_CRED;
SecurityAssertion cred = (SecurityAssertion) bootStrapCache.get(cacheKey);
if (cred != null) {
return cred;
}
String[] objs = { tokenID, hostProviderID };
String credential = (String) client.send("getDiscoveryServiceCredential", objs, null, null);
if ((credential == null) || (credential.length() == 0)) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("LibertyManagerClient.getDiscovery" + "ServiceCredential: Credential is null or empty");
}
return null;
}
Document doc = XMLUtils.toDOMDocument(credential, FSUtils.debug);
cred = new SecurityAssertion(doc.getDocumentElement());
bootStrapCache.put(cacheKey, cred);
return cred;
} catch (SessionException se) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("LibertyManagerClient.getDiscovery" + "ServiceCredential: InvalidSessionToken", se);
}
throw new FSException(FSUtils.bundle.getString("invalidSSOToken"));
} catch (DiscoveryException de) {
FSUtils.debug.error("LibertyManagerClient.getDiscovery" + "ServiceCredential: InvalidAssertion", de);
throw new FSException(FSUtils.bundle.getString("invalidCredential"));
} catch (Exception ex) {
FSUtils.debug.error("LibertyManagerClient.getDiscovery" + "ResourceOffering: SOAPClient Exception", ex);
throw new FSException(FSUtils.bundle.getString("soapException"));
}
}
Aggregations