diff options
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVP2XProtocol.java')
-rw-r--r-- | id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/PVP2XProtocol.java | 72 |
1 files changed, 55 insertions, 17 deletions
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<ServletInfo> servletList = new ArrayList<ServletInfo>(); + private static List<IDecoder> decoder = new ArrayList<IDecoder>(); + 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<IDecoder> 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, |