aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols
diff options
context:
space:
mode:
authorThomas Lenz <tlenz@iaik.tugraz.at>2016-06-07 13:19:13 +0200
committerThomas Lenz <tlenz@iaik.tugraz.at>2016-06-07 13:19:13 +0200
commitf660735c26170c05396e0feeac53e7dcf3c5b5df (patch)
tree2ae4bbc58f060c54150830cacdecb03dddd1123a /id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols
parent81f86fc319e98469cc4ae65f8c4a3c8a4636ac00 (diff)
parent0cf75d5ee50f3c285a772ce96411f7bf98fe2a72 (diff)
downloadmoa-id-spss-f660735c26170c05396e0feeac53e7dcf3c5b5df.tar.gz
moa-id-spss-f660735c26170c05396e0feeac53e7dcf3c5b5df.tar.bz2
moa-id-spss-f660735c26170c05396e0feeac53e7dcf3c5b5df.zip
Merge remote-tracking branch 'remotes/origin/moapid-3.2-opb-redis' into eIDAS_node_implementation
Conflicts: id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/SingleLogOutAction.java
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/AttributQueryAction.java7
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVP2XProtocol.java2
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPAssertionStorage.java2
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/SingleLogOutAction.java289
4 files changed, 151 insertions, 149 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/AttributQueryAction.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/AttributQueryAction.java
index 2168316ab..98c6632f1 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/AttributQueryAction.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/AttributQueryAction.java
@@ -80,6 +80,7 @@ public class AttributQueryAction implements IAction {
@Autowired private AuthenticationDataBuilder authDataBuilder;
@Autowired private IDPCredentialProvider pvpCredentials;
@Autowired private AuthConfiguration authConfig;
+ @Autowired private MOASessionDBUtils moaSessionDBUtils;
private final static List<String> DEFAULTSTORKATTRIBUTES = Arrays.asList(
new String[]{PVPConstants.EID_STORK_TOKEN_NAME});
@@ -198,7 +199,7 @@ public class AttributQueryAction implements IAction {
((PVPTargetConfiguration) pendingReq).getRequest().getInboundMessage() instanceof AttributeQuery) {
try {
activeOA.setAttributeQueryUsed(true);
- MOASessionDBUtils.saveOrUpdate(activeOA);
+ moaSessionDBUtils.saveOrUpdate(activeOA);
} catch (MOADatabaseException e) {
Logger.error("MOASession interfederation information can not stored to database.", e);
@@ -251,11 +252,11 @@ public class AttributQueryAction implements IAction {
//mark attribute request as used
if (nextIDPInformation.isStoreSSOInformation()) {
nextIDPInformation.setAttributesRequested(true);
- MOASessionDBUtils.saveOrUpdate(nextIDPInformation);
+ moaSessionDBUtils.saveOrUpdate(nextIDPInformation);
//delete federated IDP from Session
} else {
- MOASessionDBUtils.delete(nextIDPInformation);
+ moaSessionDBUtils.delete(nextIDPInformation);
}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVP2XProtocol.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVP2XProtocol.java
index bca080ba6..82e46b6ce 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVP2XProtocol.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVP2XProtocol.java
@@ -525,7 +525,7 @@ public class PVP2XProtocol extends AbstractAuthProtocolModulController {
boolean isAllowedDestination = false;
for (String prefix : allowedPublicURLPrefix) {
- if (!resp.getDestination().startsWith(
+ if (resp.getDestination().startsWith(
prefix)) {
isAllowedDestination = true;
break;
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPAssertionStorage.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPAssertionStorage.java
index 0dd309154..62105abda 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPAssertionStorage.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPAssertionStorage.java
@@ -49,7 +49,7 @@ public class PVPAssertionStorage implements SAMLArtifactMap {
samlMessage);
try {
- transactionStorage.put(artifact, assertion);
+ transactionStorage.put(artifact, assertion, -1);
} catch (MOADatabaseException e) {
// TODO Insert Error Handling, if Assertion could not be stored
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/SingleLogOutAction.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/SingleLogOutAction.java
index 52bf16247..c762e2505 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/SingleLogOutAction.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/SingleLogOutAction.java
@@ -24,17 +24,11 @@ package at.gv.egovernment.moa.id.protocols.pvp2x;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
-import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.SerializationUtils;
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.opensaml.saml2.core.LogoutRequest;
import org.opensaml.saml2.core.LogoutResponse;
import org.opensaml.saml2.metadata.SingleLogoutService;
@@ -49,7 +43,6 @@ import at.gv.egovernment.moa.id.auth.servlet.RedirectServlet;
import at.gv.egovernment.moa.id.commons.MOAIDAuthConstants;
import at.gv.egovernment.moa.id.commons.api.IRequest;
import at.gv.egovernment.moa.id.commons.api.exceptions.MOAIDException;
-import at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils;
import at.gv.egovernment.moa.id.commons.db.dao.session.AssertionStore;
import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
import at.gv.egovernment.moa.id.data.IAuthData;
@@ -83,8 +76,8 @@ public class SingleLogOutAction implements IAction {
@Autowired private ITransactionStorage transactionStorage;
@Autowired private SingleLogOutBuilder sloBuilder;
@Autowired private MOAReversionLogger revisionsLogger;
-
-
+
+
/* (non-Javadoc)
* @see at.gv.egovernment.moa.id.moduls.IAction#processRequest(at.gv.egovernment.moa.id.moduls.IRequest, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, at.gv.egovernment.moa.id.data.IAuthData)
*/
@@ -94,142 +87,148 @@ public class SingleLogOutAction implements IAction {
IAuthData authData) throws MOAIDException {
PVPTargetConfiguration pvpReq = (PVPTargetConfiguration) req;
-
+
if (pvpReq.getRequest() instanceof MOARequest &&
((MOARequest)pvpReq.getRequest()).getSamlRequest() instanceof LogoutRequest) {
Logger.debug("Process Single LogOut request");
MOARequest samlReq = (MOARequest) pvpReq.getRequest();
LogoutRequest logOutReq = (LogoutRequest) samlReq.getSamlRequest();
-
+
AuthenticationSession session =
authenticationSessionStorage.searchMOASessionWithNameIDandOAID(
logOutReq.getIssuer().getValue(),
logOutReq.getNameID().getValue());
-
- if (session == null) {
- Logger.warn("Can not find active SSO session with nameID "
- + logOutReq.getNameID().getValue() + " and OA "
- + logOutReq.getIssuer().getValue());
- Logger.info("Search active SSO session with SSO session cookie");
- String ssoID = ssomanager.getSSOSessionID(httpReq);
- if (MiscUtil.isEmpty(ssoID)) {
+
+ if (session == null) {
+ Logger.warn("Can not find active SSO session with nameID "
+ + logOutReq.getNameID().getValue() + " and OA "
+ + logOutReq.getIssuer().getValue());
+ Logger.info("Search active SSO session with SSO session cookie");
+ String ssoID = ssomanager.getSSOSessionID(httpReq);
+ if (MiscUtil.isEmpty(ssoID)) {
+ Logger.info("Can not find active Session. Single LogOut not possible!");
+ SingleLogoutService sloService = sloBuilder.getResponseSLODescriptor(pvpReq);
+ //LogoutResponse message = sloBuilder.buildSLOErrorResponse(sloService, pvpReq, StatusCode.RESPONDER_URI);
+ LogoutResponse message = sloBuilder.buildSLOResponseMessage(sloService, pvpReq, null);
+ Logger.info("Sending SLO success message to requester ...");
+ sloBuilder.sendFrontChannelSLOMessage(sloService, message, httpReq, httpResp, samlReq.getRelayState());
+ return null;
+
+ } else {
+ String moasession = ssomanager.getMOASession(ssoID);
+ try {
+ session = authenticationSessionStorage.getSession(moasession);
+
+ if (session == null)
+ throw new MOADatabaseException();
+
+ } catch (MOADatabaseException e) {
Logger.info("Can not find active Session. Single LogOut not possible!");
SingleLogoutService sloService = sloBuilder.getResponseSLODescriptor(pvpReq);
//LogoutResponse message = sloBuilder.buildSLOErrorResponse(sloService, pvpReq, StatusCode.RESPONDER_URI);
LogoutResponse message = sloBuilder.buildSLOResponseMessage(sloService, pvpReq, null);
Logger.info("Sending SLO success message to requester ...");
- sloBuilder.sendFrontChannelSLOMessage(sloService, message, httpReq, httpResp, samlReq.getRelayState());
+ sloBuilder.sendFrontChannelSLOMessage(sloService, message, httpReq, httpResp, samlReq.getRelayState());
return null;
-
- } else {
- String moasession = ssomanager.getMOASession(ssoID);
- try {
- session = authenticationSessionStorage.getSession(moasession);
-
- if (session == null)
- throw new MOADatabaseException();
-
- } catch (MOADatabaseException e) {
- Logger.info("Can not find active Session. Single LogOut not possible!");
- SingleLogoutService sloService = sloBuilder.getResponseSLODescriptor(pvpReq);
- //LogoutResponse message = sloBuilder.buildSLOErrorResponse(sloService, pvpReq, StatusCode.RESPONDER_URI);
- LogoutResponse message = sloBuilder.buildSLOResponseMessage(sloService, pvpReq, null);
- Logger.info("Sending SLO success message to requester ...");
- sloBuilder.sendFrontChannelSLOMessage(sloService, message, httpReq, httpResp, samlReq.getRelayState());
- return null;
-
- }
- }
+
+ }
+ }
+ }
+
+ authManager.performSingleLogOut(httpReq, httpResp, session, pvpReq);
+
+ } else if (pvpReq.getRequest() instanceof MOAResponse &&
+ ((MOAResponse)pvpReq.getRequest()).getResponse() instanceof LogoutResponse) {
+ Logger.debug("Process Single LogOut response");
+ LogoutResponse logOutResp = (LogoutResponse) ((MOAResponse)pvpReq.getRequest()).getResponse();
+
+ //Transaction tx = null;
+
+ try {
+ String relayState = pvpReq.getRequest().getRelayState();
+ if (MiscUtil.isEmpty(relayState)) {
+ Logger.warn("SLO Response from " + logOutResp.getIssuer().getValue()
+ + " has no SAML2 RelayState.");
+ throw new SLOException("pvp2.19", null);
+
}
-
- authManager.performSingleLogOut(httpReq, httpResp, session, pvpReq);
-
- } else if (pvpReq.getRequest() instanceof MOAResponse &&
- ((MOAResponse)pvpReq.getRequest()).getResponse() instanceof LogoutResponse) {
- Logger.debug("Process Single LogOut response");
- LogoutResponse logOutResp = (LogoutResponse) ((MOAResponse)pvpReq.getRequest()).getResponse();
-
- Transaction tx = null;
-
- try {
- String relayState = pvpReq.getRequest().getRelayState();
- if (MiscUtil.isEmpty(relayState)) {
- Logger.warn("SLO Response from " + logOutResp.getIssuer().getValue()
- + " has no SAML2 RelayState.");
- throw new SLOException("pvp2.19", null);
-
- }
-
- Session session = MOASessionDBUtils.getCurrentSession();
- boolean storageSuccess = false;
- int counter = 0;
-
- //TODO: add counter to prevent deadlock
-
+
+ //Session session = MOASessionDBUtils.getCurrentSession();
+ boolean storageSuccess = false;
+ int counter = 0;
+
+ //TODO: add counter to prevent deadlock
+ synchronized(this){
while (!storageSuccess) {
- tx = session.beginTransaction();
-
- List result;
- Query query = session.getNamedQuery("getAssertionWithArtifact");
- query.setParameter("artifact", relayState);
- result = query.list();
- Logger.trace("Found entries: " + result.size());
-
- //Assertion requires an unique artifact
- if (result.size() != 1) {
+ // tx = session.beginTransaction();
+ //
+ // List result;
+ // Query query = session.getNamedQuery("getAssertionWithArtifact");
+ // query.setParameter("artifact", relayState);
+ // result = query.list();
+ //
+ //
+ // Logger.trace("Found entries: " + result.size());
+ //
+ // //Assertion requires an unique artifact
+ // if (result.size() != 1) {
+ // Logger.trace("No entries found.");
+ // throw new MOADatabaseException("No sessioninformation found with this ID");
+ // }
+ //
+ // AssertionStore element = (AssertionStore) result.get(0);
+ // Object data = SerializationUtils.deserialize(element.getAssertion());
+ Logger.debug("Current Thread getAssertionStore: "+Thread.currentThread().getId());
+ Object o = transactionStorage.getAssertionStore(relayState);
+ if(o==null){
Logger.trace("No entries found.");
- throw new MOADatabaseException("No sessioninformation found with this ID");
+ throw new MOADatabaseException("No sessioninformation found with this ID");
}
-
- AssertionStore element = (AssertionStore) result.get(0);
- Object data = SerializationUtils.deserialize(element.getAssertion());
-
+ AssertionStore element = (AssertionStore) o;
+ Object data = SerializationUtils.deserialize(element.getAssertion());
+
if (data instanceof SLOInformationContainer) {
ISLOInformationContainer sloContainer = (ISLOInformationContainer) data;
-
+
//check status
sloBuilder.checkStatusCode(sloContainer, logOutResp);
-
+
if (sloContainer.hasFrontChannelOA()) {
try {
//some response are open
byte[] serializedSLOContainer = SerializationUtils.serialize((Serializable) sloContainer);
element.setAssertion(serializedSLOContainer);
element.setType(sloContainer.getClass().getName());
-
- session.saveOrUpdate(element);
- tx.commit();
-
+
+ // session.saveOrUpdate(element);
+ // tx.commit();
+ Logger.debug("Current Thread putAssertionStore: "+Thread.currentThread().getId());
+ transactionStorage.putAssertionStore(element);
+
//sloContainer could be stored to database
storageSuccess = true;
-
- } catch(HibernateException e) {
- tx.rollback();
+
+ } catch(MOADatabaseException e) {
+ //tx.rollback();
counter++;
Logger.debug("SLOContainter could not stored to database. Wait some time and restart storage process ... ");
java.util.Random rand = new java.util.Random();
-
+
try {
Thread.sleep(rand.nextInt(20)*10);
-
+
} catch (InterruptedException e1) {
Logger.warn("Thread could not stopped. ReStart storage process immediately", e1);
}
}
-
+
} else {
- //last response received.
- try {
- session.delete(element);
- tx.commit();
-
- } catch(HibernateException e) {
- tx.rollback();
- Logger.error("SLOContainter could not deleted from database. ");
-
- }
-
+ Logger.debug("Current Thread removeElement by Artifact: "+Thread.currentThread().getId());
+ transactionStorage.remove(element.getArtifact());
+ // session.delete(element);
+ // tx.commit();
+
storageSuccess = true;
String redirectURL = null;
if (sloContainer.getSloRequest() != null) {
@@ -237,70 +236,72 @@ public class SingleLogOutAction implements IAction {
SingleLogoutService sloService = sloBuilder.getResponseSLODescriptor(sloContainer.getSloRequest());
LogoutResponse message = sloBuilder.buildSLOResponseMessage(sloService, sloContainer.getSloRequest(), sloContainer.getSloFailedOAs());
redirectURL = sloBuilder.getFrontChannelSLOMessageURL(sloService, message, httpReq, httpResp, sloContainer.getSloRequest().getRequest().getRelayState());
-
+
} else {
//print SLO information directly
redirectURL = req.getAuthURL() + "/idpSingleLogout";
-
+
String artifact = Random.nextRandom();
-
- String statusCode = null;
+
+ String statusCode = null;
if (sloContainer.getSloFailedOAs() == null ||
- sloContainer.getSloFailedOAs().size() == 0) {
- statusCode = MOAIDAuthConstants.SLOSTATUS_SUCCESS;
- revisionsLogger.logEvent(sloContainer.getSessionID(), sloContainer.getTransactionID(),
- MOAIDEventConstants.AUTHPROCESS_SLO_ALL_VALID);
-
+ sloContainer.getSloFailedOAs().size() == 0) {
+ statusCode = MOAIDAuthConstants.SLOSTATUS_SUCCESS;
+ revisionsLogger.logEvent(sloContainer.getSessionID(), sloContainer.getTransactionID(),
+ MOAIDEventConstants.AUTHPROCESS_SLO_ALL_VALID);
+
} else {
revisionsLogger.logEvent(sloContainer.getSessionID(), sloContainer.getTransactionID(),
MOAIDEventConstants.AUTHPROCESS_SLO_NOT_ALL_VALID);
- statusCode = MOAIDAuthConstants.SLOSTATUS_ERROR;
-
+ statusCode = MOAIDAuthConstants.SLOSTATUS_ERROR;
+
}
- transactionStorage.put(artifact, statusCode);
- redirectURL = addURLParameter(redirectURL, MOAIDAuthConstants.PARAM_SLOSTATUS, artifact);
-
+ transactionStorage.put(artifact, statusCode, -1);
+ redirectURL = addURLParameter(redirectURL, MOAIDAuthConstants.PARAM_SLOSTATUS, artifact);
+
}
//redirect to Redirect Servlet
String url = req.getAuthURL() + "/RedirectServlet";
url = addURLParameter(url, RedirectServlet.REDIRCT_PARAM_URL, URLEncoder.encode(redirectURL, "UTF-8"));
url = httpResp.encodeRedirectURL(url);
-
+
httpResp.setContentType("text/html");
httpResp.setStatus(302);
httpResp.addHeader("Location", url);
-
+
}
} else {
Logger.warn("Sessioninformation Cast-Exception by using Artifact=" + relayState);
throw new MOADatabaseException("Sessioninformation Cast-Exception");
-
+
}
}
-
- } catch (MOADatabaseException e) {
- Logger.error("MOA AssertionDatabase ERROR", e);
- throw new SLOException("pvp2.19", null);
-
- } catch (UnsupportedEncodingException e) {
- Logger.error("Finale SLO redirct not possible.", e);
- throw new AuthenticationException("pvp2.13", new Object[]{});
-
- } finally {
- if (tx != null && !tx.getStatus().equals(TransactionStatus.COMMITTED)) {
- tx.commit();
-
- }
}
-
-
-
- } else {
- Logger.error("Process SingleLogOutAction but request is NOT of type LogoutRequest or LogoutResponse.");
- throw new MOAIDException("pvp2.13", null);
-
- }
-
+ } catch (MOADatabaseException e) {
+ Logger.error("MOA AssertionDatabase ERROR", e);
+ throw new SLOException("pvp2.19", null);
+
+ } catch (UnsupportedEncodingException e) {
+ Logger.error("Finale SLO redirct not possible.", e);
+ throw new AuthenticationException("pvp2.13", new Object[]{});
+
+ }
+
+ // finally {
+ // if (tx != null && !tx.getStatus().equals(TransactionStatus.COMMITTED)) {
+ // tx.commit();
+ //
+ // }
+ // }
+
+
+
+ } else {
+ Logger.error("Process SingleLogOutAction but request is NOT of type LogoutRequest or LogoutResponse.");
+ throw new MOAIDException("pvp2.13", null);
+
+ }
+
return null;
}
@@ -320,7 +321,7 @@ public class SingleLogOutAction implements IAction {
public String getDefaultActionName() {
return PVP2XProtocol.SINGLELOGOUT;
}
-
+
protected static String addURLParameter(String url, String paramname,
String paramvalue) {
String param = paramname + "=" + paramvalue;