use of com.sun.identity.liberty.ws.meta.jaxb.IDPDescriptorType in project OpenAM by OpenRock.
the class FSAssertionArtifactHandler method validateAssertions.
protected Subject validateAssertions(List assertions) {
FSUtils.debug.message("FSAssertionArtifactHandler.validateAssertions: Called");
// loop to check assertions
FSSubject subject = null;
Iterator iter = assertions.iterator();
FSAssertion assertion = null;
String aIDString = null;
String issuer = null;
Iterator stmtIter = null;
Statement statement = null;
int stmtType = Statement.NOT_SUPPORTED;
SubjectConfirmation subConf = null;
Set confMethods = null;
String confMethod = null;
Date date = null;
long time = System.currentTimeMillis() + 180000;
while (iter.hasNext()) {
assertion = (FSAssertion) iter.next();
if (!authnRequest.getRequestID().equals(assertion.getInResponseTo())) {
FSUtils.debug.error("FSAssertionArtifactHandler." + "validateAssertion:" + " assertion does not correspond to any valid request");
return null;
}
if (FSServiceUtils.isSigningOn()) {
if (!verifyAssertionSignature(assertion)) {
FSUtils.debug.error("FSAssertionArtifactHandler." + "validateAssertion:" + " assertion signature verification failed");
return null;
}
}
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSAssertionArtifactHandler." + "validateAssertion: Assertion signature verified");
}
aIDString = assertion.getAssertionID();
// make sure it's not being used
if (idTimeMap.containsKey(aIDString)) {
FSUtils.debug.error("FSAssertionArtifactHandler.validateAssertion: Assertion: " + aIDString + " is used");
return null;
}
// check issuer of the assertions
issuer = assertion.getIssuer();
try {
if (idpEntityId != null) {
if (!idpEntityId.equals(issuer)) {
FSUtils.debug.error("FSAssertionArtifactHandler." + "validateAssertion: " + "Assertion issuer is not the entity where " + "AuthnRequest was sent originally.");
return null;
}
} else {
FSUtils.debug.error("FSAssertionArtifactHandler." + "validateAssertion: " + "Assertion issuer is: " + issuer);
IDFFMetaManager metaManager = FSUtils.getIDFFMetaManager();
IDPDescriptorType idpDesc = metaManager.getIDPDescriptor(realm, issuer);
if (idpDesc == null) {
FSUtils.debug.error("FSAssertionArtifactHandler." + "validateAssertion:" + " Assertion issuer is not on the trust list");
return null;
}
setProviderDescriptor(idpDesc);
setProviderEntityId(issuer);
}
} catch (Exception ex) {
FSUtils.debug.error("FSAssertionArtifactHandler." + "validateAssertion: " + "Assertion issuer is not on the trust list");
return null;
}
// must be valid(timewise)
if (!assertion.isTimeValid()) {
FSUtils.debug.error("FSAssertionArtifactHandler.validateAssertion:" + " Assertion's time is not valid.");
return null;
}
// TODO: IssuerInstant of the assertion is within a few minutes
// This is a MAY in spec. Which number to use for the few minutes?
// if present, target of the assertions must == local server IP
Conditions conds = assertion.getConditions();
if (!forThisServer(conds)) {
FSUtils.debug.error("FSAssertionArtifactHandler." + "validateAssertion: " + "assertion is not issued for this site.");
return null;
}
//for each assertion, loop to check each statement
boolean authnStatementFound = false;
if (assertion.getStatement() != null) {
stmtIter = assertion.getStatement().iterator();
while (stmtIter.hasNext()) {
statement = (Statement) stmtIter.next();
stmtType = statement.getStatementType();
if (stmtType == Statement.AUTHENTICATION_STATEMENT) {
FSAuthenticationStatement authStatement = (FSAuthenticationStatement) statement;
authnStatementFound = true;
try {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSAssertionArtifactHandler." + "validateAssertion: " + "validating AuthenticationStatement:" + authStatement.toXMLString());
}
} catch (FSException e) {
FSUtils.debug.error("FSAssertionArtifactHandler." + "validateAssertion: Exception. " + "Invalid AuthenticationStatement: ", e);
return null;
}
//check ReauthenticateOnOrAfter
reAuthnOnOrAfterDate = authStatement.getReauthenticateOnOrAfter();
//process SessionIndex
idpSessionIndex = authStatement.getSessionIndex();
authnContextStmt = authStatement.getAuthnContext();
subject = (FSSubject) authStatement.getSubject();
if (subject == null) {
FSUtils.debug.error("FSAssertionArtifactHandler." + "validateAssertion: Subject is null");
return null;
} else {
try {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSAssertionArtifactHandler." + "validateAssertion: " + "found Authentication Statement. " + "Subject = " + subject.toXMLString());
}
} catch (FSException e) {
FSUtils.debug.error("FSAssertionArtifactHandler." + "validateAssertion: " + " Exception. Invalid subject: ", e);
continue;
}
}
//bearer
if (((subConf = subject.getSubjectConfirmation()) == null) || ((confMethods = subConf.getConfirmationMethod()) == null) || (confMethods.size() != 1)) {
FSUtils.debug.error("FSAssertionArtifactHandler." + "validateAssertion: " + "missing or extra ConfirmationMethod.");
return null;
}
if (((confMethod = (String) confMethods.iterator().next()) == null) || !((confMethod.equals(SAMLConstants.CONFIRMATION_METHOD_BEARER)) || (confMethod.equals(SAMLConstants.CONFIRMATION_METHOD_ARTIFACT)) || (confMethod.equals(SAMLConstants.DEPRECATED_CONFIRMATION_METHOD_ARTIFACT)))) {
FSUtils.debug.error("FSAssertionArtifactHandler." + "validateAssertion: wrong " + "ConfirmationMethod");
return null;
}
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSAssertionArtifactHandler." + "validateAssertion: Confirmation method: " + confMethod);
}
} else if (stmtType == Statement.ATTRIBUTE_STATEMENT) {
AttributeStatement attrStatement = (AttributeStatement) statement;
if (!checkForAttributeStatement(attrStatement)) {
attrStatements.add(attrStatement);
}
}
}
}
if (!authnStatementFound) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSAssertionArtifactHandler." + "validateAssertion: " + "No Authentication statement found in the Assertion. " + "User is not authenticated by the IDP");
}
return null;
}
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSAssertionArtifactHandler." + "validateAssertion: Adding " + aIDString + " to idTimeMap.");
}
// add the assertion to idTimeMap
if ((date = conds.getNotOnorAfter()) != null) {
cGoThrough.addElement(aIDString);
idTimeMap.put(aIDString, new Long(date.getTime()));
} else {
cPeriodic.addElement(aIDString);
// it doesn't matter what we store for the value.
idTimeMap.put(aIDString, aIDString);
}
securityAssertions = assertion.getDiscoveryCredential();
}
if (subject == null) {
FSUtils.debug.error("FSAssertionArtifactHandler.validateAssertion:" + " couldn't find Subject.");
return null;
}
return subject;
}
use of com.sun.identity.liberty.ws.meta.jaxb.IDPDescriptorType in project OpenAM by OpenRock.
the class FSSSOAndFedHandler method sendProxyAuthnRequest.
/**
* Sends a new AuthnRequest to the authenticating provider.
* @param authnRequest original AuthnRequest sent by the service provider.
* @param preferredIDP IDP to be proxied.
* @exception FSException for any federation failure.
* @exception IOException if there is a failure in redirection.
*/
protected void sendProxyAuthnRequest(FSAuthnRequest authnRequest, String preferredIDP) throws FSException, IOException {
FSAuthnRequest newAuthnRequest = getNewAuthnRequest(authnRequest);
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSSSOAndFedHandler.sendProxyAuthnRequest:" + "New Authentication request:" + newAuthnRequest.toXMLString());
}
FSSessionManager sessManager = FSSessionManager.getInstance(IDFFMetaUtils.getMetaAlias(realm, hostedEntityId, IFSConstants.SP, null));
String requestID = newAuthnRequest.getRequestID();
sessManager.setAuthnRequest(requestID, newAuthnRequest);
sessManager.setProxySPDescriptor(requestID, spDescriptor);
sessManager.setProxySPAuthnRequest(requestID, authnRequest);
sessManager.setIDPEntityID(requestID, preferredIDP);
String targetURL = null;
SPDescriptorType localDescriptor = null;
BaseConfigType localDescriptorConfig = null;
try {
IDPDescriptorType idpDescriptor = metaManager.getIDPDescriptor(realm, preferredIDP);
targetURL = idpDescriptor.getSingleSignOnServiceURL();
if (targetURL == null) {
FSUtils.debug.error("FSSSOAndFedHandler.sendProxyAuthnRequest: Single " + "Sign-on service is not found for the proxying IDP");
return;
}
localDescriptor = metaManager.getSPDescriptor(realm, hostedEntityId);
localDescriptorConfig = metaManager.getSPDescriptorConfig(realm, hostedEntityId);
} catch (Exception e) {
FSUtils.debug.error("FSSSOAndFedHandler.sendProxyAuthnRequest:", e);
return;
}
String queryString = newAuthnRequest.toURLEncodedQueryString();
if (FSServiceUtils.isSigningOn()) {
String certAlias = IDFFMetaUtils.getFirstAttributeValueFromConfig(localDescriptorConfig, IFSConstants.SIGNING_CERT_ALIAS);
if (localDescriptor.isAuthnRequestsSigned()) {
queryString = FSSignatureUtil.signAndReturnQueryString(queryString, certAlias);
}
}
StringBuffer tmpURL = new StringBuffer(1000);
if (targetURL.indexOf("?") != -1) {
tmpURL.append(targetURL).append("&").append(queryString);
} else {
tmpURL.append(targetURL).append("?").append(queryString);
}
String redirectURL = tmpURL.toString();
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSSSOAndFedHandler.sendProxyAuthnRequest:" + "SSO URL to be redirected" + redirectURL);
}
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location", redirectURL);
response.sendRedirect(redirectURL);
}
use of com.sun.identity.liberty.ws.meta.jaxb.IDPDescriptorType in project OpenAM by OpenRock.
the class FSSSOAndFedService method onMessage.
/**
* SOAP JAXM Listener implementation for LECP AuthnRequest.
*
* @param request <code>HttpServletRequest</code> object
* @param response <code>HttpServletResponse</code> object
* @param message SOAP message that contains LECP request
*/
public void onMessage(HttpServletRequest request, HttpServletResponse response, SOAPMessage message) {
FSUtils.debug.message("FSSSOAndFedService.onMessage: Called");
try {
Element elt = soapService.parseSOAPMessage(message);
if (elt == null) {
FSUtils.debug.error("FSSSOAndFedService.onMessage: " + "Error in processing. Invalid SOAPMessage");
response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
returnSOAPMessage(soapService.formSOAPError("Server", "cannotProcessRequest", null), response);
return;
}
String eltTagName = (elt.getTagName().trim());
String ns = elt.getNamespaceURI().trim();
String nodeName = elt.getLocalName().trim();
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSSSOAndFedService.onMessage: " + "tagName: " + eltTagName + " namespaceUri: " + ns + " localName: " + nodeName);
}
if (nodeName.equalsIgnoreCase("AuthnRequest") && (ns.equalsIgnoreCase(IFSConstants.libertyMessageNamespaceURI)) || (ns.equalsIgnoreCase(IFSConstants.FF_12_XML_NS))) {
SOAPMessage retMessage = null;
try {
FSAuthnRequest authnRequest = new FSAuthnRequest(elt);
String metaAlias = FSServiceUtils.getMetaAlias(request);
IDFFMetaManager metaManager = FSUtils.getIDFFMetaManager();
String realm = IDFFMetaUtils.getRealmByMetaAlias(metaAlias);
String hostEntityId = metaManager.getEntityIDByMetaAlias(metaAlias);
IDPDescriptorType hostedDesc = metaManager.getIDPDescriptor(realm, hostEntityId);
BaseConfigType hostedConfig = metaManager.getIDPDescriptorConfig(realm, hostEntityId);
FSSessionManager sessionService = FSSessionManager.getInstance(metaAlias);
sessionService.setAuthnRequest(authnRequest.getRequestID(), authnRequest);
handleLECPRequest(request, response, authnRequest, hostedDesc, hostedConfig, realm, hostEntityId, metaAlias);
retMessage = null;
} catch (Exception e) {
FSUtils.debug.error("FSSSOAndFedService.onMessage: " + "Error in processing lecp AuthnRequest:", e);
response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
returnSOAPMessage(soapService.formSOAPError("Server", "cannotProcessRequest", null), response);
return;
}
returnSOAPMessage(retMessage, response);
return;
} else {
FSUtils.debug.error("FSSSOAndFedService.onMessage: Invalid SOAP Request:" + nodeName);
}
} catch (Exception e) {
FSUtils.debug.error("FSSSOAndFedService.onMessage: " + "Error in processing Request: Exception occured: ", e);
response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
java.io.ByteArrayOutputStream strm = new java.io.ByteArrayOutputStream();
e.printStackTrace(new java.io.PrintStream(strm));
FSUtils.debug.error(strm.toString());
returnSOAPMessage(soapService.formSOAPError("Server", "cannotProcessRequest", null), response);
return;
}
returnSOAPMessage(soapService.formSOAPError("Server", "cannotProcessRequest", null), response);
return;
}
use of com.sun.identity.liberty.ws.meta.jaxb.IDPDescriptorType in project OpenAM by OpenRock.
the class FSSSOAndFedService method doPost.
/**
* Processes single sign on POST request.
* @param request <code>HttpServletRequest</code> object
* @param response <code>HttpServletResponse</code> object
* @exception ServletException, IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
FSUtils.debug.message("FSSSOAndFedService.doPost: Called");
if ((request == null) || (response == null)) {
response.sendError(response.SC_INTERNAL_SERVER_ERROR, FSUtils.bundle.getString("nullInputParameter"));
return;
}
if (FSUtils.needSetLBCookieAndRedirect(request, response, true)) {
return;
}
// Check if it's an LECP request
if (isLECPRequest(request)) {
// TODO: assume auth framework will understand this param
String useForward = (String) request.getAttribute(Constants.FORWARD_PARAM);
if (useForward != null && useForward.equals(Constants.FORWARD_YES_VALUE)) {
// this is a forward POST after authentication, need to
// use GET instead of POST here
FSUtils.debug.message("FSSSOAndFedService.doPost: LECP forward");
this.doGet(request, response);
} else {
try {
MimeHeaders mimeHeaders = SAMLUtils.getMimeHeaders(request);
ServletInputStream sInputStream = request.getInputStream();
SOAPMessage soapMessage = msgFactory.createMessage(mimeHeaders, sInputStream);
this.onMessage(request, response, soapMessage);
} catch (SOAPException se) {
throw new ServletException(se);
}
}
return;
}
// obtain AuthnRequest message
String enocodedAuthnRequest = request.getParameter(IFSConstants.POST_AUTHN_REQUEST_PARAM);
if (enocodedAuthnRequest == null) {
doGet(request, response);
return;
}
enocodedAuthnRequest = enocodedAuthnRequest.replace(' ', '\n');
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSSSOAndFedService.doPost: " + "BASE64 encoded AuthnRequest at the RECEIVER: " + enocodedAuthnRequest);
}
//decode and create FSAuthnRequest object
FSAuthnRequest authnRequest = null;
try {
authnRequest = FSAuthnRequest.parseBASE64EncodedString(enocodedAuthnRequest);
if (authnRequest == null) {
FSUtils.debug.error("FSSSOAndFedService: " + FSUtils.bundle.getString("invalidAuthnRequest"));
String[] data = { FSUtils.bundle.getString("invalidAuthnRequest") };
LogUtil.error(Level.INFO, LogUtil.INVALID_AUTHN_REQUEST, data);
response.sendError(response.SC_BAD_REQUEST, FSUtils.bundle.getString("invalidAuthnRequest"));
return;
} else {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSSSOAndFedService: " + "AuthnRequest received:" + authnRequest.toXMLString());
}
}
} catch (FSException e) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSSSOAndFedService: " + FSUtils.bundle.getString("invalidAuthnRequest"), e);
}
response.sendError(response.SC_BAD_REQUEST, FSUtils.bundle.getString("invalidAuthnRequest"));
return;
}
String metaAlias = null;
String realm = null;
String hostEntityId = null;
IDPDescriptorType hostedDesc = null;
BaseConfigType hostedConfig = null;
try {
metaAlias = FSServiceUtils.getMetaAlias(request);
realm = IDFFMetaUtils.getRealmByMetaAlias(metaAlias);
hostEntityId = metaManager.getEntityIDByMetaAlias(metaAlias);
hostedDesc = metaManager.getIDPDescriptor(realm, hostEntityId);
hostedConfig = metaManager.getIDPDescriptorConfig(realm, hostEntityId);
} catch (Exception e) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSSSOAndFedService: couldn't obtain hosted entity id:", e);
}
}
handleAuthnRequest(request, response, authnRequest, false, false, realm, hostEntityId, metaAlias, hostedDesc, hostedConfig);
return;
}
use of com.sun.identity.liberty.ws.meta.jaxb.IDPDescriptorType in project OpenAM by OpenRock.
the class FSIDPFinderService method getLoginURL.
private String getLoginURL(FSAuthnRequest authnRequest, String realm, String hostProviderID, HttpServletRequest httpRequest) {
if (authnRequest == null) {
FSUtils.debug.error("FSIDPFinderServer.getLoginURL: null authnrequest");
return null;
}
if (hostProviderID == null) {
FSUtils.debug.error("FSIDPFinderServer.getLoginURL: null hostProviderID");
return null;
}
IDPDescriptorType idpDescriptor = null;
BaseConfigType idpConfig = null;
try {
IDFFMetaManager metaManager = FSUtils.getIDFFMetaManager();
idpDescriptor = metaManager.getIDPDescriptor(realm, hostProviderID);
idpConfig = metaManager.getIDPDescriptorConfig(realm, hostProviderID);
} catch (Exception e) {
FSUtils.debug.error("FSIDPFinderServer.getLoginURL : exception " + "while retrieving meta config", e);
return null;
}
String authType = authnRequest.getAuthContextCompType();
FSAuthnDecisionHandler authnDecisionHandler = new FSAuthnDecisionHandler(realm, hostProviderID, httpRequest);
List defAuthnCtxList = IDFFMetaUtils.getAttributeValueFromConfig(idpConfig, IFSConstants.DEFAULT_AUTHNCONTEXT);
FSAuthContextResult authnResult = authnDecisionHandler.getURLForAuthnContext(defAuthnCtxList, authType);
return formatLoginURL(authnResult.getLoginURL(), authnResult.getAuthContextRef(), realm, hostProviderID, idpDescriptor, idpConfig, authnRequest, httpRequest);
}
Aggregations