summaryrefslogtreecommitdiff
path: root/eaaf_modules/eaaf_module_pvp2_core/src
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2019-04-23 15:00:40 +0200
committerThomas Lenz <thomas.lenz@egiz.gv.at>2019-04-23 15:00:40 +0200
commit02851082661a924adc68230615f61a308705ce2b (patch)
treebd09998365191ddb065c3c61a0af60d0ec684bda /eaaf_modules/eaaf_module_pvp2_core/src
parent5c1b5b863fe8d6c08cfe0749fed7ce9594827f8a (diff)
downloadEAAF-Components-02851082661a924adc68230615f61a308705ce2b.tar.gz
EAAF-Components-02851082661a924adc68230615f61a308705ce2b.tar.bz2
EAAF-Components-02851082661a924adc68230615f61a308705ce2b.zip
integrate Spring ModelAndView into EAAF GUI framework
Diffstat (limited to 'eaaf_modules/eaaf_module_pvp2_core/src')
-rw-r--r--eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/binding/PostBinding.java47
-rw-r--r--eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/opensaml/HTTPPostEncoderWithOwnTemplate.java25
2 files changed, 39 insertions, 33 deletions
diff --git a/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/binding/PostBinding.java b/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/binding/PostBinding.java
index 66417c5a..79578788 100644
--- a/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/binding/PostBinding.java
+++ b/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/binding/PostBinding.java
@@ -58,9 +58,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import at.gv.egiz.eaaf.core.api.IRequest;
-import at.gv.egiz.eaaf.core.api.gui.IGUIBuilderConfiguration;
import at.gv.egiz.eaaf.core.api.gui.IGUIBuilderConfigurationFactory;
-import at.gv.egiz.eaaf.core.api.gui.IGUIFormBuilder;
+import at.gv.egiz.eaaf.core.api.gui.IVelocityGUIBuilderConfiguration;
+import at.gv.egiz.eaaf.core.api.gui.IVelocityGuiFormBuilder;
import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
import at.gv.egiz.eaaf.core.impl.gui.velocity.VelocityProvider;
import at.gv.egiz.eaaf.modules.pvp2.PVPConstants;
@@ -80,9 +80,10 @@ public class PostBinding implements IDecoder, IEncoder {
private static final Logger log = LoggerFactory.getLogger(PostBinding.class);
@Autowired(required=true) IConfiguration authConfig;
- @Autowired(required=true) IGUIFormBuilder guiBuilder;
+ @Autowired(required=true) IVelocityGuiFormBuilder guiBuilder;
@Autowired(required=true) IGUIBuilderConfigurationFactory guiConfigFactory;
+ @Override
public void encodeRequest(HttpServletRequest req, HttpServletResponse resp,
RequestAbstractType request, String targetLocation, String relayState, Credential credentials, IRequest pendingReq)
throws MessageEncodingException, SecurityException {
@@ -92,19 +93,19 @@ public class PostBinding implements IDecoder, IEncoder {
EAAFDefaultSAML2Bootstrap.initializeDefaultPVPConfiguration();
//initialize POST binding encoder with template decoration
- IGUIBuilderConfiguration guiConfig = guiConfigFactory.getSPSpecificSAML2PostConfiguration(
+ final IVelocityGUIBuilderConfiguration guiConfig = guiConfigFactory.getSPSpecificSAML2PostConfiguration(
pendingReq,
"pvp_postbinding_template.html",
authConfig.getConfigurationRootDirectory());
- HTTPPostEncoderWithOwnTemplate encoder = new HTTPPostEncoderWithOwnTemplate(guiConfig, guiBuilder,
+ final HTTPPostEncoderWithOwnTemplate encoder = new HTTPPostEncoderWithOwnTemplate(guiConfig, guiBuilder,
VelocityProvider.getClassPathVelocityEngine());
//set OpenSAML2 process parameter into binding context dao
- HttpServletResponseAdapter responseAdapter = new HttpServletResponseAdapter(
+ final HttpServletResponseAdapter responseAdapter = new HttpServletResponseAdapter(
resp, true);
- BasicSAMLMessageContext<SAMLObject, SAMLObject, SAMLObject> context = new BasicSAMLMessageContext<SAMLObject, SAMLObject, SAMLObject>();
- SingleSignOnService service = new SingleSignOnServiceBuilder().buildObject();
+ final BasicSAMLMessageContext<SAMLObject, SAMLObject, SAMLObject> context = new BasicSAMLMessageContext<SAMLObject, SAMLObject, SAMLObject>();
+ final SingleSignOnService service = new SingleSignOnServiceBuilder().buildObject();
service.setBinding("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
service.setLocation(targetLocation);;
@@ -116,13 +117,14 @@ public class PostBinding implements IDecoder, IEncoder {
encoder.encode(context);
- } catch (Exception e) {
+ } catch (final Exception e) {
log.warn("Can not encode SAML2 request", e);
throw new SecurityException(e);
}
}
+ @Override
public void encodeRespone(HttpServletRequest req, HttpServletResponse resp,
StatusResponseType response, String targetLocation, String relayState, Credential credentials, IRequest pendingReq)
throws MessageEncodingException, SecurityException {
@@ -134,18 +136,18 @@ public class PostBinding implements IDecoder, IEncoder {
log.debug("create SAML POSTBinding response");
//initialize POST binding encoder with template decoration
- IGUIBuilderConfiguration guiConfig = guiConfigFactory.getSPSpecificSAML2PostConfiguration(
+ final IVelocityGUIBuilderConfiguration guiConfig = guiConfigFactory.getSPSpecificSAML2PostConfiguration(
pendingReq,
"pvp_postbinding_template.html",
authConfig.getConfigurationRootDirectory());
- HTTPPostEncoderWithOwnTemplate encoder = new HTTPPostEncoderWithOwnTemplate(guiConfig, guiBuilder,
+ final HTTPPostEncoderWithOwnTemplate encoder = new HTTPPostEncoderWithOwnTemplate(guiConfig, guiBuilder,
VelocityProvider.getClassPathVelocityEngine());
//set OpenSAML2 process parameter into binding context dao
- HttpServletResponseAdapter responseAdapter = new HttpServletResponseAdapter(
+ final HttpServletResponseAdapter responseAdapter = new HttpServletResponseAdapter(
resp, true);
- BasicSAMLMessageContext<SAMLObject, SAMLObject, SAMLObject> context = new BasicSAMLMessageContext<SAMLObject, SAMLObject, SAMLObject>();
- SingleSignOnService service = new SingleSignOnServiceBuilder()
+ final BasicSAMLMessageContext<SAMLObject, SAMLObject, SAMLObject> context = new BasicSAMLMessageContext<SAMLObject, SAMLObject, SAMLObject>();
+ final SingleSignOnService service = new SingleSignOnServiceBuilder()
.buildObject();
service.setBinding(SAMLConstants.SAML2_POST_BINDING_URI);
service.setLocation(targetLocation);
@@ -158,19 +160,20 @@ public class PostBinding implements IDecoder, IEncoder {
encoder.encode(context);
- } catch (Exception e) {
+ } catch (final Exception e) {
log.warn("Can not encode SAML2 response", e);
throw new SecurityException(e);
}
}
+ @Override
public InboundMessageInterface decode(HttpServletRequest req,
HttpServletResponse resp, MetadataProvider metadataProvider, boolean isSPEndPoint, URIComparator comparator) throws MessageDecodingException,
SecurityException {
- HTTPPostDecoder decode = new HTTPPostDecoder(new BasicParserPool());
- BasicSAMLMessageContext<SAMLObject, ?, ?> messageContext = new BasicSAMLMessageContext<SAMLObject, SAMLObject, SAMLObject>();
+ final HTTPPostDecoder decode = new HTTPPostDecoder(new BasicParserPool());
+ final BasicSAMLMessageContext<SAMLObject, ?, ?> messageContext = new BasicSAMLMessageContext<SAMLObject, SAMLObject, SAMLObject>();
messageContext
.setInboundMessageTransport(new HttpServletRequestAdapter(req));
//set metadata descriptor type
@@ -186,25 +189,25 @@ public class PostBinding implements IDecoder, IEncoder {
messageContext.setMetadataProvider(metadataProvider);
//set security policy context
- BasicSecurityPolicy policy = new BasicSecurityPolicy();
+ final BasicSecurityPolicy policy = new BasicSecurityPolicy();
policy.getPolicyRules().add(
new PVPSignedRequestPolicyRule(metadataProvider,
TrustEngineFactory.getSignatureKnownKeysTrustEngine(metadataProvider),
messageContext.getPeerEntityRole()));
- SecurityPolicyResolver secResolver = new StaticSecurityPolicyResolver(policy);
+ final SecurityPolicyResolver secResolver = new StaticSecurityPolicyResolver(policy);
messageContext.setSecurityPolicyResolver(secResolver);
decode.decode(messageContext);
InboundMessage msg = null;
if (messageContext.getInboundMessage() instanceof RequestAbstractType) {
- RequestAbstractType inboundMessage = (RequestAbstractType) messageContext
+ final RequestAbstractType inboundMessage = (RequestAbstractType) messageContext
.getInboundMessage();
msg = new PVPSProfileRequest(inboundMessage, getSAML2BindingName());
msg.setEntityID(inboundMessage.getIssuer().getValue());
} else if (messageContext.getInboundMessage() instanceof StatusResponseType){
- StatusResponseType inboundMessage = (StatusResponseType) messageContext.getInboundMessage();
+ final StatusResponseType inboundMessage = (StatusResponseType) messageContext.getInboundMessage();
msg = new PVPSProfileResponse(inboundMessage);
msg.setEntityID(inboundMessage.getIssuer().getValue());
@@ -227,10 +230,12 @@ public class PostBinding implements IDecoder, IEncoder {
return msg;
}
+ @Override
public boolean handleDecode(String action, HttpServletRequest req) {
return (req.getMethod().equals("POST") && action.equals(PVPConstants.POST));
}
+ @Override
public String getSAML2BindingName() {
return SAMLConstants.SAML2_POST_BINDING_URI;
}
diff --git a/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/opensaml/HTTPPostEncoderWithOwnTemplate.java b/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/opensaml/HTTPPostEncoderWithOwnTemplate.java
index e9a8b320..8af12acc 100644
--- a/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/opensaml/HTTPPostEncoderWithOwnTemplate.java
+++ b/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/opensaml/HTTPPostEncoderWithOwnTemplate.java
@@ -43,8 +43,8 @@ import org.opensaml.ws.transport.http.HTTPTransportUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import at.gv.egiz.eaaf.core.api.gui.IGUIBuilderConfiguration;
-import at.gv.egiz.eaaf.core.api.gui.IGUIFormBuilder;
+import at.gv.egiz.eaaf.core.api.gui.IVelocityGUIBuilderConfiguration;
+import at.gv.egiz.eaaf.core.api.gui.IVelocityGuiFormBuilder;
/**
* @author tlenz
@@ -54,15 +54,15 @@ public class HTTPPostEncoderWithOwnTemplate extends HTTPPostEncoder {
private static final Logger log = LoggerFactory.getLogger(HTTPPostEncoderWithOwnTemplate.class);
- private VelocityEngine velocityEngine;
- private IGUIBuilderConfiguration guiConfig;
- private IGUIFormBuilder guiBuilder;
+ private final VelocityEngine velocityEngine;
+ private final IVelocityGUIBuilderConfiguration guiConfig;
+ private final IVelocityGuiFormBuilder guiBuilder;
/**
* @param engine
* @param templateId
*/
- public HTTPPostEncoderWithOwnTemplate(IGUIBuilderConfiguration guiConfig, IGUIFormBuilder guiBuilder, VelocityEngine engine) {
+ public HTTPPostEncoderWithOwnTemplate(IVelocityGUIBuilderConfiguration guiConfig, IVelocityGuiFormBuilder guiBuilder, VelocityEngine engine) {
super(engine, null);
this.velocityEngine = engine;
this.guiConfig = guiConfig;
@@ -78,12 +78,13 @@ public class HTTPPostEncoderWithOwnTemplate extends HTTPPostEncoder {
*
* @throws MessageEncodingException thrown if there is a problem encoding the message
*/
- protected void postEncode(SAMLMessageContext messageContext, String endpointURL) throws MessageEncodingException {
+ @Override
+ protected void postEncode(SAMLMessageContext messageContext, String endpointURL) throws MessageEncodingException {
log.debug("Invoking Velocity template to create POST body");
InputStream is = null;
try {
//build Velocity Context from GUI input paramters
- VelocityContext context = guiBuilder.generateVelocityContextFromConfiguration(guiConfig);
+ final VelocityContext context = guiBuilder.generateVelocityContextFromConfiguration(guiConfig);
//load template
is = guiBuilder.getTemplateInputStream(guiConfig);
@@ -92,17 +93,17 @@ public class HTTPPostEncoderWithOwnTemplate extends HTTPPostEncoder {
populateVelocityContext(context, messageContext, endpointURL);
//populate transport parameter
- HTTPOutTransport outTransport = (HTTPOutTransport) messageContext.getOutboundMessageTransport();
+ final HTTPOutTransport outTransport = (HTTPOutTransport) messageContext.getOutboundMessageTransport();
HTTPTransportUtils.addNoCacheHeaders(outTransport);
HTTPTransportUtils.setUTF8Encoding(outTransport);
HTTPTransportUtils.setContentType(outTransport, "text/html");
//evaluate template and write content to response
- Writer out = new OutputStreamWriter(outTransport.getOutgoingStream(), "UTF-8");
+ final Writer out = new OutputStreamWriter(outTransport.getOutgoingStream(), "UTF-8");
velocityEngine.evaluate(context, out, "SAML2_POST_BINDING", new BufferedReader(new InputStreamReader(is)));
out.flush();
- } catch (Exception e) {
+ } catch (final Exception e) {
log.error("Error invoking Velocity template", e);
throw new MessageEncodingException("Error creating output document", e);
@@ -111,7 +112,7 @@ public class HTTPPostEncoderWithOwnTemplate extends HTTPPostEncoder {
try {
is.close();
- } catch (IOException e) {
+ } catch (final IOException e) {
log.error("Can NOT close GUI-Template InputStream.", e);
}
}