From b51e4b4d111d3a8c097019bb4f3c4d0a01f98a6a Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Tue, 23 Apr 2013 11:46:25 +0200 Subject: Some MoaID changes --- .../moa/id/entrypoints/AuthDispatcherServlet.java | 4 +- .../moa/id/moduls/AuthenticationManager.java | 2 +- .../gv/egovernment/moa/id/moduls/IModulInfo.java | 3 +- .../at/gv/egovernment/moa/id/moduls/IRequest.java | 10 +++ .../moa/id/moduls/ITargetConfiguration.java | 5 -- .../gv/egovernment/moa/id/moduls/ModulStorage.java | 3 +- .../gv/egovernment/moa/id/moduls/RequestImpl.java | 62 ++++++++++++++++++ .../moa/id/moduls/TargetConfigurationImpl.java | 15 ----- .../moa/id/protocols/pvp2x/DoAuthentication.java | 33 ---------- .../moa/id/protocols/pvp2x/PVP2XProtocol.java | 72 ++++++++++++++++----- .../moa/id/protocols/pvp2x/PVPProcessor.java | 12 ++++ .../id/protocols/pvp2x/PVPTargetConfiguration.java | 17 +++++ .../protocols/pvp2x/SAMLRequestNotSupported.java | 10 +++ .../moa/id/protocols/pvp2x/binding/IDecoder.java | 21 ++++++ .../moa/id/protocols/pvp2x/binding/IEncoder.java | 19 ++++++ .../id/protocols/pvp2x/binding/PostBinding.java | 73 +++++++++++++++++++++ .../protocols/pvp2x/binding/RedirectBinding.java | 74 ++++++++++++++++++++++ .../pvp2x/requestHandler/AuthnRequestHandler.java | 25 ++++++++ .../pvp2x/requestHandler/IRequestHandler.java | 13 ++++ .../pvp2x/requestHandler/RequestManager.java | 46 ++++++++++++++ .../moa/id/protocols/saml1/SAML1Protocol.java | 10 +-- 21 files changed, 449 insertions(+), 80 deletions(-) create mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/IRequest.java delete mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/ITargetConfiguration.java create mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestImpl.java delete mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/TargetConfigurationImpl.java delete mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/DoAuthentication.java create mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPProcessor.java create mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPTargetConfiguration.java create mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/SAMLRequestNotSupported.java create mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/IDecoder.java create mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/IEncoder.java create mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/PostBinding.java create mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/RedirectBinding.java create mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/requestHandler/AuthnRequestHandler.java create mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/requestHandler/IRequestHandler.java create mode 100644 id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/requestHandler/RequestManager.java (limited to 'id/server/idserverlib/src/main') diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/AuthDispatcherServlet.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/AuthDispatcherServlet.java index 38b876e76..262854b50 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/AuthDispatcherServlet.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/AuthDispatcherServlet.java @@ -18,7 +18,7 @@ import at.gv.egovernment.moa.id.auth.WrongParametersException; import at.gv.egovernment.moa.id.auth.servlet.AuthServlet; import at.gv.egovernment.moa.id.moduls.AuthenticationManager; import at.gv.egovernment.moa.id.moduls.IModulInfo; -import at.gv.egovernment.moa.id.moduls.ITargetConfiguration; +import at.gv.egovernment.moa.id.moduls.IRequest; import at.gv.egovernment.moa.id.moduls.ModulStorage; import at.gv.egovernment.moa.id.moduls.ServletInfo; import at.gv.egovernment.moa.id.moduls.ServletType; @@ -170,7 +170,7 @@ public class AuthDispatcherServlet extends AuthServlet { return; } - ITargetConfiguration configuration = info.preProcess(req, resp); + IRequest configuration = info.preProcess(req, resp, protocol); if (!AuthenticationManager.isAuthenticated(req, resp)) { diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java index 302031fe3..0bba644bb 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/AuthenticationManager.java @@ -105,7 +105,7 @@ public class AuthenticationManager implements MOAIDAuthConstants { } public static void doAuthentication(HttpServletRequest request, - HttpServletResponse response, ITargetConfiguration target) + HttpServletResponse response, IRequest target) throws ServletException, IOException, MOAIDException { HttpSession session = request.getSession(); Logger.info("Starting authentication ..."); diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/IModulInfo.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/IModulInfo.java index 1f51feff6..64afc8880 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/IModulInfo.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/IModulInfo.java @@ -12,7 +12,8 @@ public interface IModulInfo { public String getName(); public String getPath(); - public ITargetConfiguration preProcess(HttpServletRequest request, HttpServletResponse response) + public IRequest preProcess(HttpServletRequest request, + HttpServletResponse response, String action) throws MOAIDException; public boolean generateErrorMessage(Throwable e,HttpServletRequest request, HttpServletResponse response); diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/IRequest.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/IRequest.java new file mode 100644 index 000000000..f05a0f088 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/IRequest.java @@ -0,0 +1,10 @@ +package at.gv.egovernment.moa.id.moduls; + +public interface IRequest { + public String getOAURL(); + public boolean isPassiv(); + public boolean forceAuth(); + public boolean isSSOSupported(); + public String requestedModule(); + public String requestedAction(); +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/ITargetConfiguration.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/ITargetConfiguration.java deleted file mode 100644 index e86f20496..000000000 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/ITargetConfiguration.java +++ /dev/null @@ -1,5 +0,0 @@ -package at.gv.egovernment.moa.id.moduls; - -public interface ITargetConfiguration { - public String getOAURL(); -} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/ModulStorage.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/ModulStorage.java index 8b13bf9a1..2a92f3ce5 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/ModulStorage.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/ModulStorage.java @@ -9,7 +9,8 @@ import at.gv.egovernment.moa.logging.Logger; public class ModulStorage { private static final String[] modulClasses = new String[]{ - "at.gv.egovernment.moa.id.protocols.saml1.SAML1Protocol" + "at.gv.egovernment.moa.id.protocols.saml1.SAML1Protocol", + "at.gv.egovernment.moa.id.protocols.pvp2x.PVP2XProtocol" }; diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestImpl.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestImpl.java new file mode 100644 index 000000000..44b00a6c0 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/RequestImpl.java @@ -0,0 +1,62 @@ +package at.gv.egovernment.moa.id.moduls; + +public class RequestImpl implements IRequest { + + private String oaURL; + private boolean passiv = false; + private boolean force = false; + private boolean ssosupport = false; + private String module = null; + private String action = null; + + + public void setOAURL(String value) { + oaURL = value; + } + + public String getOAURL() { + return oaURL; + } + + public boolean isPassiv() { + return passiv; + } + + public boolean forceAuth() { + return force; + } + + public void setPassiv(boolean passiv) { + this.passiv = passiv; + } + + public void setForce(boolean force) { + this.force = force; + } + + public boolean isSSOSupported() { + return ssosupport; + } + + public String requestedModule() { + return module; + } + + public String requestedAction() { + return action; + } + + public void setSsosupport(boolean ssosupport) { + this.ssosupport = ssosupport; + } + + public void setModule(String module) { + this.module = module; + } + + public void setAction(String action) { + this.action = action; + } + + +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/TargetConfigurationImpl.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/TargetConfigurationImpl.java deleted file mode 100644 index fadedce0b..000000000 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/TargetConfigurationImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -package at.gv.egovernment.moa.id.moduls; - -public class TargetConfigurationImpl implements ITargetConfiguration { - - private String oaURL; - - public void setOAURL(String value) { - oaURL = value; - } - - public String getOAURL() { - return oaURL; - } - -} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/DoAuthentication.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/DoAuthentication.java deleted file mode 100644 index bcc4111af..000000000 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/DoAuthentication.java +++ /dev/null @@ -1,33 +0,0 @@ -package at.gv.egovernment.moa.id.protocols.pvp2x; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import at.gv.egovernment.moa.id.auth.servlet.AuthServlet; - -public class DoAuthentication extends AuthServlet { - - /** - * - */ - private static final long serialVersionUID = 1L; - - protected void process(HttpServletRequest req, HttpServletResponse resp) { - - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - process(req, resp); - } - - @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - process(req, resp); - } -} 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 57485f7a2..f58b411d1 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 @@ -1,22 +1,27 @@ package at.gv.egovernment.moa.id.protocols.pvp2x; +import iaik.pkcs.pkcs11.objects.Object; + import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringEscapeUtils; +import org.opensaml.saml2.core.RequestAbstractType; import at.gv.egovernment.moa.id.MOAIDException; import at.gv.egovernment.moa.id.auth.MOAIDAuthConstants; import at.gv.egovernment.moa.id.auth.WrongParametersException; import at.gv.egovernment.moa.id.moduls.IModulInfo; -import at.gv.egovernment.moa.id.moduls.ITargetConfiguration; +import at.gv.egovernment.moa.id.moduls.IRequest; import at.gv.egovernment.moa.id.moduls.ServletInfo; import at.gv.egovernment.moa.id.moduls.ServletType; -import at.gv.egovernment.moa.id.moduls.TargetConfigurationImpl; -import at.gv.egovernment.moa.id.protocols.saml1.GetArtifactServlet; +import at.gv.egovernment.moa.id.protocols.pvp2x.binding.IDecoder; +import at.gv.egovernment.moa.id.protocols.pvp2x.binding.PostBinding; +import at.gv.egovernment.moa.id.protocols.pvp2x.binding.RedirectBinding; import at.gv.egovernment.moa.id.util.ParamValidatorUtils; public class PVP2XProtocol implements IModulInfo, MOAIDAuthConstants { @@ -24,14 +29,22 @@ public class PVP2XProtocol implements IModulInfo, MOAIDAuthConstants { public static final String NAME = PVP2XProtocol.class.getName(); public static final String PATH = "id_pvp2x"; - public static final String GETARTIFACT = "GetArtifact"; + public static final String REDIRECT = "Redirect"; + public static final String POST = "Post"; private static List servletList = new ArrayList(); + private static List decoder = new ArrayList(); + static { - servletList.add(new ServletInfo(GetArtifactServlet.class, GETARTIFACT, + servletList.add(new ServletInfo(PVPProcessor.class, REDIRECT, + ServletType.AUTH)); + servletList.add(new ServletInfo(PVPProcessor.class, POST, ServletType.AUTH)); + decoder.add(new PostBinding()); + decoder.add(new RedirectBinding()); + instance = new PVP2XProtocol(); } @@ -48,7 +61,6 @@ public class PVP2XProtocol implements IModulInfo, MOAIDAuthConstants { return servletList; } - public String getName() { return NAME; } @@ -57,17 +69,43 @@ public class PVP2XProtocol implements IModulInfo, MOAIDAuthConstants { return PATH; } - public ITargetConfiguration preProcess(HttpServletRequest request, - HttpServletResponse response) throws MOAIDException { - TargetConfigurationImpl config = new TargetConfigurationImpl(); - String oaURL = (String) request.getParameter(PARAM_OA); - oaURL = StringEscapeUtils.escapeHtml(oaURL); - if (!ParamValidatorUtils.isValidOA(oaURL)) - throw new WrongParametersException("StartAuthentication", PARAM_OA, - "auth.12"); - config.setOAURL(oaURL); - request.getSession().setAttribute(PARAM_OA, oaURL); - return config; + private IDecoder findDecoder(String action) { + Iterator decoderIT = decoder.iterator(); + while (decoderIT.hasNext()) { + IDecoder decoder = decoderIT.next(); + if (decoder.handleDecode(action)) { + return decoder; + } + } + + return null; + } + + public IRequest preProcess(HttpServletRequest request, + HttpServletResponse response, String action) throws MOAIDException { + + IDecoder decoder = findDecoder(action); + if (decoder == null) { + return null; + } + try { + PVPTargetConfiguration config = new PVPTargetConfiguration(); + + RequestAbstractType samlReq = decoder.decodeRequest(request, response); + + String oaURL = (String) request.getParameter(PARAM_OA); + oaURL = StringEscapeUtils.escapeHtml(oaURL); + if (!ParamValidatorUtils.isValidOA(oaURL)) + throw new WrongParametersException("StartAuthentication", + PARAM_OA, "auth.12"); + config.setOAURL(oaURL); + request.getSession().setAttribute(PARAM_OA, oaURL); + + return config; + } catch (Exception e) { + e.printStackTrace(); + throw new MOAIDException(e.getMessage(), new Object[] {}); + } } public boolean generateErrorMessage(Throwable e, diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPProcessor.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPProcessor.java new file mode 100644 index 000000000..d7079ba5c --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPProcessor.java @@ -0,0 +1,12 @@ +package at.gv.egovernment.moa.id.protocols.pvp2x; + +import at.gv.egovernment.moa.id.auth.servlet.AuthServlet; + +public class PVPProcessor extends AuthServlet { + + /** + * + */ + private static final long serialVersionUID = 4102075202310068260L; + +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPTargetConfiguration.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPTargetConfiguration.java new file mode 100644 index 000000000..4f4dedc76 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVPTargetConfiguration.java @@ -0,0 +1,17 @@ +package at.gv.egovernment.moa.id.protocols.pvp2x; + +import org.opensaml.saml2.core.RequestAbstractType; + +import at.gv.egovernment.moa.id.moduls.RequestImpl; + +public class PVPTargetConfiguration extends RequestImpl { + RequestAbstractType request; + + public RequestAbstractType getRequest() { + return request; + } + + public void setRequest(RequestAbstractType request) { + this.request = request; + } +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/SAMLRequestNotSupported.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/SAMLRequestNotSupported.java new file mode 100644 index 000000000..3a71495c1 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/SAMLRequestNotSupported.java @@ -0,0 +1,10 @@ +package at.gv.egovernment.moa.id.protocols.pvp2x; + +public class SAMLRequestNotSupported extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1244883178458802767L; + +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/IDecoder.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/IDecoder.java new file mode 100644 index 000000000..0e7dd3377 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/IDecoder.java @@ -0,0 +1,21 @@ +package at.gv.egovernment.moa.id.protocols.pvp2x.binding; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.opensaml.saml2.core.RequestAbstractType; +import org.opensaml.saml2.core.Response; +import org.opensaml.ws.message.decoder.MessageDecodingException; +import org.opensaml.xml.security.SecurityException; + +public interface IDecoder { + public RequestAbstractType decodeRequest(HttpServletRequest req, + HttpServletResponse resp) + throws MessageDecodingException, SecurityException; + + public Response decodeRespone(HttpServletRequest req, + HttpServletResponse resp) + throws MessageDecodingException, SecurityException; + + public boolean handleDecode(String action); +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/IEncoder.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/IEncoder.java new file mode 100644 index 000000000..8df44c270 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/IEncoder.java @@ -0,0 +1,19 @@ +package at.gv.egovernment.moa.id.protocols.pvp2x.binding; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.opensaml.saml2.core.RequestAbstractType; +import org.opensaml.saml2.core.Response; +import org.opensaml.ws.message.decoder.MessageDecodingException; +import org.opensaml.xml.security.SecurityException; + +public interface IEncoder { + public void encodeRequest(HttpServletRequest req, + HttpServletResponse resp, RequestAbstractType request) + throws MessageDecodingException, SecurityException; + + public void encodeRespone(HttpServletRequest req, + HttpServletResponse resp, Response response) + throws MessageDecodingException, SecurityException; +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/PostBinding.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/PostBinding.java new file mode 100644 index 000000000..cb0f0f8d8 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/PostBinding.java @@ -0,0 +1,73 @@ +package at.gv.egovernment.moa.id.protocols.pvp2x.binding; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.opensaml.common.SAMLObject; +import org.opensaml.common.binding.BasicSAMLMessageContext; +import org.opensaml.saml2.binding.decoding.HTTPPostDecoder; +import org.opensaml.saml2.core.RequestAbstractType; +import org.opensaml.saml2.core.Response; +import org.opensaml.ws.message.decoder.MessageDecodingException; +import org.opensaml.ws.transport.http.HttpServletRequestAdapter; +import org.opensaml.xml.parse.BasicParserPool; +import org.opensaml.xml.security.SecurityException; + +import at.gv.egovernment.moa.id.protocols.pvp2x.PVP2XProtocol; + +public class PostBinding implements IDecoder, IEncoder { + + public void encodeRequest(HttpServletRequest req, HttpServletResponse resp, + RequestAbstractType request) throws MessageDecodingException, + SecurityException{ + // TODO Auto-generated method stub + + } + + public void encodeRespone(HttpServletRequest req, HttpServletResponse resp, + Response response) throws MessageDecodingException, + SecurityException{ + // TODO Auto-generated method stub + + } + + public RequestAbstractType decodeRequest(HttpServletRequest req, + HttpServletResponse resp) throws MessageDecodingException, + SecurityException{ + + HTTPPostDecoder decode = new HTTPPostDecoder(new BasicParserPool()); + BasicSAMLMessageContext messageContext = + new BasicSAMLMessageContext(); + messageContext + .setInboundMessageTransport(new HttpServletRequestAdapter( + req)); + decode.decode(messageContext); + + RequestAbstractType inboundMessage = (RequestAbstractType) messageContext + .getInboundMessage(); + return inboundMessage; + + } + + public Response decodeRespone(HttpServletRequest req, + HttpServletResponse resp) throws MessageDecodingException, + SecurityException{ + + HTTPPostDecoder decode = new HTTPPostDecoder(new BasicParserPool()); + BasicSAMLMessageContext messageContext = + new BasicSAMLMessageContext(); + messageContext + .setInboundMessageTransport(new HttpServletRequestAdapter( + req)); + decode.decode(messageContext); + + Response inboundMessage = (Response) messageContext + .getInboundMessage(); + return inboundMessage; + + } + + public boolean handleDecode(String action) { + return (action.equals(PVP2XProtocol.POST)); + } +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/RedirectBinding.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/RedirectBinding.java new file mode 100644 index 000000000..d2951baf0 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/binding/RedirectBinding.java @@ -0,0 +1,74 @@ +package at.gv.egovernment.moa.id.protocols.pvp2x.binding; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.opensaml.common.SAMLObject; +import org.opensaml.common.binding.BasicSAMLMessageContext; +import org.opensaml.saml2.binding.decoding.HTTPRedirectDeflateDecoder; +import org.opensaml.saml2.core.RequestAbstractType; +import org.opensaml.saml2.core.Response; +import org.opensaml.ws.message.decoder.MessageDecodingException; +import org.opensaml.ws.transport.http.HttpServletRequestAdapter; +import org.opensaml.xml.parse.BasicParserPool; +import org.opensaml.xml.security.SecurityException; + +import at.gv.egovernment.moa.id.protocols.pvp2x.PVP2XProtocol; + +public class RedirectBinding implements IDecoder, IEncoder { + + public void encodeRequest(HttpServletRequest req, HttpServletResponse resp, + RequestAbstractType request) throws MessageDecodingException, + SecurityException { + + } + + public void encodeRespone(HttpServletRequest req, HttpServletResponse resp, + Response response) throws MessageDecodingException, + SecurityException { + // TODO Auto-generated method stub + + } + + public RequestAbstractType decodeRequest(HttpServletRequest req, + HttpServletResponse resp) throws MessageDecodingException, + SecurityException { + + HTTPRedirectDeflateDecoder decode = new HTTPRedirectDeflateDecoder( + new BasicParserPool()); + BasicSAMLMessageContext messageContext = + new BasicSAMLMessageContext(); + messageContext + .setInboundMessageTransport(new HttpServletRequestAdapter( + req)); + + decode.decode(messageContext); + + RequestAbstractType inboundMessage = (RequestAbstractType)messageContext.getInboundMessage(); + + return inboundMessage; + } + + public Response decodeRespone(HttpServletRequest req, + HttpServletResponse resp) throws MessageDecodingException, + SecurityException { + + HTTPRedirectDeflateDecoder decode = new HTTPRedirectDeflateDecoder( + new BasicParserPool()); + BasicSAMLMessageContext messageContext = + new BasicSAMLMessageContext(); + messageContext + .setInboundMessageTransport(new HttpServletRequestAdapter( + req)); + + decode.decode(messageContext); + + Response inboundMessage = (Response)messageContext.getInboundMessage(); + + return inboundMessage; + } + + public boolean handleDecode(String action) { + return (action.equals(PVP2XProtocol.REDIRECT)); + } +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/requestHandler/AuthnRequestHandler.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/requestHandler/AuthnRequestHandler.java new file mode 100644 index 000000000..cdc0a9914 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/requestHandler/AuthnRequestHandler.java @@ -0,0 +1,25 @@ +package at.gv.egovernment.moa.id.protocols.pvp2x.requestHandler; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.opensaml.saml2.core.AuthnRequest; +import org.opensaml.saml2.core.RequestAbstractType; + +public class AuthnRequestHandler implements IRequestHandler { + + public boolean handleObject(RequestAbstractType obj) { + return (obj instanceof AuthnRequest); + } + + public void process(RequestAbstractType obj, HttpServletRequest req, + HttpServletResponse resp) { + if(!handleObject(obj)) { + // TODO: throw exception + return; + } + + System.out.println("AuthnRequest"); + } + +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/requestHandler/IRequestHandler.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/requestHandler/IRequestHandler.java new file mode 100644 index 000000000..a73737f15 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/requestHandler/IRequestHandler.java @@ -0,0 +1,13 @@ +package at.gv.egovernment.moa.id.protocols.pvp2x.requestHandler; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.opensaml.saml2.core.RequestAbstractType; + +public interface IRequestHandler { + public boolean handleObject(RequestAbstractType obj); + + public void process(RequestAbstractType obj, HttpServletRequest req, + HttpServletResponse resp); +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/requestHandler/RequestManager.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/requestHandler/RequestManager.java new file mode 100644 index 000000000..2fe24b707 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/requestHandler/RequestManager.java @@ -0,0 +1,46 @@ +package at.gv.egovernment.moa.id.protocols.pvp2x.requestHandler; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.opensaml.saml2.core.RequestAbstractType; + +import at.gv.egovernment.moa.id.protocols.pvp2x.SAMLRequestNotSupported; + +public class RequestManager { + + private static RequestManager instance = null; + + private List handler; + + public static synchronized RequestManager getInstance() { + if(instance == null) { + instance = new RequestManager(); + } + return instance; + } + + private RequestManager() { + handler = new ArrayList(); + + } + + public void handle(RequestAbstractType obj, HttpServletRequest req, HttpServletResponse resp) + throws SAMLRequestNotSupported { + Iterator it = handler.iterator(); + while(it.hasNext()) { + IRequestHandler handler = it.next(); + if(handler.handleObject(obj)) { + handler.process(obj, req, resp); + return; + } + } + + // not handled + throw new SAMLRequestNotSupported(); + } +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/saml1/SAML1Protocol.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/saml1/SAML1Protocol.java index fd6c2dadb..ca1f9c380 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/saml1/SAML1Protocol.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/saml1/SAML1Protocol.java @@ -12,10 +12,10 @@ import at.gv.egovernment.moa.id.MOAIDException; import at.gv.egovernment.moa.id.auth.MOAIDAuthConstants; import at.gv.egovernment.moa.id.auth.WrongParametersException; import at.gv.egovernment.moa.id.moduls.IModulInfo; -import at.gv.egovernment.moa.id.moduls.ITargetConfiguration; +import at.gv.egovernment.moa.id.moduls.IRequest; import at.gv.egovernment.moa.id.moduls.ServletInfo; import at.gv.egovernment.moa.id.moduls.ServletType; -import at.gv.egovernment.moa.id.moduls.TargetConfigurationImpl; +import at.gv.egovernment.moa.id.moduls.RequestImpl; import at.gv.egovernment.moa.id.util.ParamValidatorUtils; public class SAML1Protocol implements IModulInfo, MOAIDAuthConstants { @@ -56,9 +56,9 @@ public class SAML1Protocol implements IModulInfo, MOAIDAuthConstants { return PATH; } - public ITargetConfiguration preProcess(HttpServletRequest request, - HttpServletResponse response) throws MOAIDException { - TargetConfigurationImpl config = new TargetConfigurationImpl(); + public IRequest preProcess(HttpServletRequest request, + HttpServletResponse response, String action) throws MOAIDException { + RequestImpl config = new RequestImpl(); String oaURL = (String) request.getParameter(PARAM_OA); oaURL = StringEscapeUtils.escapeHtml(oaURL); if (!ParamValidatorUtils.isValidOA(oaURL)) -- cgit v1.2.3