List of usage examples for org.joda.time DateTime plusSeconds
public DateTime plusSeconds(int seconds)
From source file:eu.eidas.auth.engine.EIDASSAMLEngine.java
License:EUPL
/** * Generate authentication response in one of the supported formats. * /*w w w. j av a2 s. c o m*/ * @param request the request * @param responseAuthReq the response authentication request * @param ipAddress the IP address * @param isHashing the is hashing * @param signAssertion whether to sign the attribute assertion * * @return the authentication response * * @throws EIDASSAMLEngineException the EIDASSAML engine exception */ public EIDASAuthnResponse generateEIDASAuthnResponse(final EIDASAuthnRequest request, final EIDASAuthnResponse responseAuthReq, final String ipAddress, final boolean isHashing, final boolean signAssertion) throws EIDASSAMLEngineException { LOG.trace("generateEIDASAuthnResponse"); //if not setted before if (StringUtils.isEmpty(getCountryRespondTo())) { setCountryRespondTo(request.getCountry()); } // Validate parameters validateParamResponse(request, responseAuthReq); // Mandatory SAML LOG.trace("Generate StatusCode"); final StatusCode statusCode = SAMLEngineUtils.generateStatusCode(StatusCode.SUCCESS_URI); LOG.trace("Generate Status"); final Status status = SAMLEngineUtils.generateStatus(statusCode); LOG.trace("Generate StatusMessage"); final StatusMessage statusMessage = (StatusMessage) SAMLEngineUtils .generateStatusMessage(StatusCode.SUCCESS_URI); status.setStatusMessage(statusMessage); LOG.trace("Generate Response"); // RESPONSE final Response response = genAuthnRespBase(status, request.getAssertionConsumerServiceURL(), request.getSamlId()); if (responseAuthReq.getIssuer() != null && !responseAuthReq.getIssuer().isEmpty() && response.getIssuer() != null) { response.getIssuer().setValue(SAMLEngineUtils.getValidIssuerValue(responseAuthReq.getIssuer())); } DateTime notOnOrAfter = new DateTime(); notOnOrAfter = notOnOrAfter.plusSeconds(super.getSamlCoreProperties().getTimeNotOnOrAfter()); final Assertion assertion = this.generateAssertion(ipAddress, request, response, responseAuthReq.getPersonalAttributeList(), notOnOrAfter); final AttributeStatement attrStatement = this .generateAttributeStatement(responseAuthReq.getPersonalAttributeList(), isHashing); assertion.getAttributeStatements().add(attrStatement); addAuthnContextClassRef(responseAuthReq, assertion); // Add assertions Assertion signedAssertion = null; if (signAssertion) { try { signedAssertion = (Assertion) super.sign(assertion, getExtensionProcessor().getFormat().getName()); } catch (SAMLEngineException exc) { LOG.info(SAML_EXCHANGE, "BUSINESS EXCEPTION : cannot sign assertion: {}", exc.getMessage()); LOG.debug(SAML_EXCHANGE, "BUSINESS EXCEPTION : cannot sign assertion: {}", exc); } } response.getAssertions().add(signedAssertion == null ? assertion : signedAssertion); final EIDASAuthnResponse authresponse = new EIDASAuthnResponse(); try { authresponse .setTokenSaml(super.signAndMarshall(response, getExtensionProcessor().getFormat().getName())); authresponse.setSamlId(response.getID()); } catch (SAMLEngineException e) { LOG.info(SAML_EXCHANGE, "BUSINESS EXCEPTION : Sign and Marshall.", e.getMessage()); LOG.debug(SAML_EXCHANGE, "BUSINESS EXCEPTION : Sign and Marshall.", e); throw new EIDASSAMLEngineException(EIDASErrors.INTERNAL_ERROR.errorCode(), EIDASErrors.INTERNAL_ERROR.errorMessage(), e); } return authresponse; }
From source file:eu.eidas.auth.engine.EIDASSAMLEngine.java
License:EUPL
/** * Generate authentication response fail. * /*from w w w .ja v a 2 s .c o m*/ * @param request the request * @param response the response * @param ipAddress the IP address * @param isHashing the is hashing * * @return the authentication response * * @throws EIDASSAMLEngineException the EIDASSAML engine exception */ public EIDASAuthnResponse generateEIDASAuthnResponseFail(final EIDASAuthnRequest request, final EIDASAuthnResponse response, final String ipAddress, final boolean isHashing) throws EIDASSAMLEngineException { LOG.trace("generateEIDASAuthnResponseFail"); if (StringUtils.isEmpty(getCountryRespondTo())) { setCountryRespondTo(request.getCountry()); } validateParamResponseFail(request, response); // Mandatory final StatusCode statusCode = SAMLEngineUtils.generateStatusCode(response.getStatusCode()); // Mandatory SAML LOG.trace("Generate StatusCode."); // Subordinate code it's optional in case not covered into next codes: // - urn:oasis:names:tc:SAML:2.0:status:AuthnFailed // - urn:oasis:names:tc:SAML:2.0:status:InvalidAttrNameOrValue // - urn:oasis:names:tc:SAML:2.0:status:InvalidNameIDPolicy // - urn:oasis:names:tc:SAML:2.0:status:RequestDenied // - http://www.stork.gov.eu/saml20/statusCodes/QAANotSupported if (StringUtils.isNotBlank(response.getSubStatusCode())) { final StatusCode newStatusCode = SAMLEngineUtils.generateStatusCode(response.getSubStatusCode()); statusCode.setStatusCode(newStatusCode); } LOG.debug("Generate Status."); final Status status = SAMLEngineUtils.generateStatus(statusCode); if (StringUtils.isNotBlank(response.getMessage())) { final StatusMessage statusMessage = (StatusMessage) SAMLEngineUtils .generateStatusMessage(response.getMessage()); status.setStatusMessage(statusMessage); } LOG.trace("Generate Response."); // RESPONSE final Response responseFail = genAuthnRespBase(status, request.getAssertionConsumerServiceURL(), request.getSamlId()); if (response.getIssuer() != null && !response.getIssuer().isEmpty() && response.getIssuer() != null) { responseFail.getIssuer().setValue(response.getIssuer()); } DateTime notOnOrAfter = new DateTime(); notOnOrAfter = notOnOrAfter.plusSeconds(super.getSamlCoreProperties().getTimeNotOnOrAfter()); final Assertion assertion = this.generateAssertion(ipAddress, request, responseFail, new PersonalAttributeList(), notOnOrAfter); addAuthnContextClassRef(response, assertion); responseFail.getAssertions().add(assertion); LOG.trace("Sign and Marshall ResponseFail."); final EIDASAuthnResponse eidasResponse = new EIDASAuthnResponse(); try { eidasResponse.setTokenSaml( super.signAndMarshall(responseFail, getExtensionProcessor().getFormat().getName())); eidasResponse.setSamlId(responseFail.getID()); } catch (SAMLEngineException e) { LOG.info(SAML_EXCHANGE, "BUSINESS EXCEPTION : SAMLEngineException.", e.getMessage()); LOG.debug(SAML_EXCHANGE, "BUSINESS EXCEPTION : SAMLEngineException.", e); throw new EIDASSAMLEngineException(EIDASErrors.INTERNAL_ERROR.errorCode(), EIDASErrors.INTERNAL_ERROR.errorMessage(), e); } return eidasResponse; }
From source file:eu.eidas.auth.engine.SamlEngine.java
License:EUPL
/** * Generate authentication response in one of the supported formats. * * @param request the request//from w w w .j a va 2 s . c om * @param authnResponse the authentication response from the IdP * @param ipAddress the IP address * @param signAssertion whether to sign the attribute assertion * @return the authentication response * @throws EIDASSAMLEngineException the EIDASSAML engine exception */ @Override public IResponseMessage generateResponseMessage(IAuthenticationRequest request, IAuthenticationResponse authnResponse, boolean signAssertion, String ipAddress) throws EIDASSAMLEngineException { LOG.trace("generateResponseMessage"); // Validate parameters validateParamResponse(request, authnResponse); // At this point the assertion consumer service URL is mandatory (and must have been replaced by the value from the metadata if needed) if (StringUtils.isBlank(request.getAssertionConsumerServiceURL())) { throw new EIDASSAMLEngineException(EidasErrorKey.MESSAGE_VALIDATION_ERROR.errorCode(), EidasErrorKey.MESSAGE_VALIDATION_ERROR.errorCode(), "Request AssertionConsumerServiceURL must not be blank."); } // Mandatory SAML LOG.trace("Generate StatusCode"); StatusCode statusCode = BuilderFactoryUtil.generateStatusCode(StatusCode.SUCCESS_URI); LOG.trace("Generate Status"); Status status = BuilderFactoryUtil.generateStatus(statusCode); LOG.trace("Generate StatusMessage"); StatusMessage statusMessage = BuilderFactoryUtil.generateStatusMessage(StatusCode.SUCCESS_URI); status.setStatusMessage(statusMessage); LOG.trace("Generate Response"); // RESPONSE Response response = genAuthnRespBase(status, request.getAssertionConsumerServiceURL(), request.getId()); if (authnResponse.getIssuer() != null && !authnResponse.getIssuer().isEmpty() && response.getIssuer() != null) { response.getIssuer().setValue(SAMLEngineUtils.getValidIssuerValue(authnResponse.getIssuer())); } DateTime notOnOrAfter = new DateTime(); notOnOrAfter = notOnOrAfter.plusSeconds(getCoreProperties().getTimeNotOnOrAfter()); Assertion assertion = AssertionUtil.generateResponseAssertion(false, ipAddress, request, response.getIssuer(), authnResponse.getAttributes(), notOnOrAfter, getCoreProperties().getFormatEntity(), getCoreProperties().getResponder(), getExtensionProcessor().getFormat(), getCoreProperties().isOneTimeUse()); AttributeStatement attrStatement = generateResponseAttributeStatement(authnResponse.getAttributes()); assertion.getAttributeStatements().add(attrStatement); addResponseAuthnContextClassRef(authnResponse, assertion); // Add assertions Assertion signedAssertion = null; if (signAssertion) { try { signedAssertion = (Assertion) signAssertion(assertion); } catch (EIDASSAMLEngineException exc) { LOG.info(SAML_EXCHANGE, "BUSINESS EXCEPTION : cannot sign assertion: {}", exc.getMessage()); LOG.debug(SAML_EXCHANGE, "BUSINESS EXCEPTION : cannot sign assertion: {}", exc); } } response.getAssertions().add(signedAssertion == null ? assertion : signedAssertion); try { byte[] responseBytes = signAndMarshallResponse(request, response); return new BinaryResponseMessage(authnResponse, responseBytes); } catch (EIDASSAMLEngineException e) { LOG.info(SAML_EXCHANGE, "BUSINESS EXCEPTION : Sign and Marshall.", e.getMessage()); LOG.debug(SAML_EXCHANGE, "BUSINESS EXCEPTION : Sign and Marshall.", e); throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(), EidasErrorKey.INTERNAL_ERROR.errorMessage(), e); } }
From source file:eu.eidas.auth.engine.SamlEngine.java
License:EUPL
/** * Generate authentication response fail. * * @param request the request// ww w. j a v a 2 s . co m * @param response the response * @param ipAddress the IP address * @return the authentication response * @throws EIDASSAMLEngineException the EIDASSAML engine exception */ @Override public IResponseMessage generateResponseMessageFail(IAuthenticationRequest request, IAuthenticationResponse response, String ipAddress) throws EIDASSAMLEngineException { LOG.trace("generateResponseMessageFail"); validateParamResponseFail(request, response); // Mandatory StatusCode statusCode = BuilderFactoryUtil.generateStatusCode(response.getStatusCode()); // Mandatory SAML LOG.trace("Generate StatusCode."); // Subordinate code is optional in case not covered into next codes: // - urn:oasis:names:tc:SAML:2.0:status:AuthnFailed // - urn:oasis:names:tc:SAML:2.0:status:InvalidAttrNameOrValue // - urn:oasis:names:tc:SAML:2.0:status:InvalidNameIDPolicy // - urn:oasis:names:tc:SAML:2.0:status:RequestDenied // - http://www.stork.gov.eu/saml20/statusCodes/QAANotSupported if (StringUtils.isNotBlank(response.getSubStatusCode())) { StatusCode newStatusCode = BuilderFactoryUtil.generateStatusCode(response.getSubStatusCode()); statusCode.setStatusCode(newStatusCode); } LOG.debug("Generate Status."); Status status = BuilderFactoryUtil.generateStatus(statusCode); if (StringUtils.isNotBlank(response.getStatusMessage())) { StatusMessage statusMessage = BuilderFactoryUtil.generateStatusMessage(response.getStatusMessage()); status.setStatusMessage(statusMessage); } LOG.trace("Generate Response."); // RESPONSE Response responseFail = genAuthnRespBase(status, request.getAssertionConsumerServiceURL(), request.getId()); String responseIssuer = response.getIssuer(); if (responseIssuer != null && !responseIssuer.isEmpty()) { responseFail.getIssuer().setValue(responseIssuer); } DateTime notOnOrAfter = new DateTime(); notOnOrAfter = notOnOrAfter.plusSeconds(getCoreProperties().getTimeNotOnOrAfter()); Assertion assertion = AssertionUtil.generateResponseAssertion(true, ipAddress, request, responseFail.getIssuer(), ImmutableAttributeMap.of(), notOnOrAfter, getCoreProperties().getFormatEntity(), getCoreProperties().getResponder(), getExtensionProcessor().getFormat(), getCoreProperties().isOneTimeUse()); addResponseAuthnContextClassRef(response, assertion); responseFail.getAssertions().add(assertion); LOG.trace("Sign and Marshall ResponseFail."); AuthenticationResponse.Builder eidasResponse = new AuthenticationResponse.Builder(); try { byte[] responseBytes = signAndMarshallResponse(request, responseFail); eidasResponse.id(responseFail.getID()); eidasResponse.issuer(responseFail.getIssuer().getValue()); eidasResponse.ipAddress(ipAddress); eidasResponse.inResponseTo(responseFail.getInResponseTo()); eidasResponse.responseStatus(extractResponseStatus(responseFail)); return new BinaryResponseMessage(eidasResponse.build(), responseBytes); } catch (EIDASSAMLEngineException e) { LOG.info(SAML_EXCHANGE, "BUSINESS EXCEPTION : SAMLEngineException.", e.getMessage()); LOG.debug(SAML_EXCHANGE, "BUSINESS EXCEPTION : SAMLEngineException.", e); throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(), EidasErrorKey.INTERNAL_ERROR.errorMessage(), e); } }
From source file:eu.europa.ec.fisheries.uvms.movement.util.DateUtil.java
License:Open Source License
public static XMLGregorianCalendar addSecondsToDate(XMLGregorianCalendar inDate, int seconds) { Date date = DateUtil.parsePositionTime(inDate); DateTime newDateTime = new DateTime(date); DateTime plusSeconds = newDateTime.plusSeconds(1); return parsePositionTime(plusSeconds.toDate()); }
From source file:eu.europa.ec.fisheries.uvms.movement.util.DateUtil.java
License:Open Source License
public static Date addSecondsToDate(Date inDate, int seconds) { DateTime newDateTime = new DateTime(inDate); DateTime plusSeconds = newDateTime.plusSeconds(1); return plusSeconds.toDate(); }
From source file:eu.hydrologis.jgrass.geonotes.photo.PhotoImportWizard.java
License:Open Source License
public boolean performFinish() { final FieldbookView fieldBookView = GeonotesPlugin.getDefault().getFieldbookView(); final String path = mainPage.getPhotoFolder(); shift = mainPage.getTime();/*from w w w. j a v a2 s . c o m*/ intervalMinutes = mainPage.getIntervalMinutes(); doNotImport = mainPage.getDoNotImport(); createFeatureLayer = mainPage.doCreateFeatureLayer(); Display.getDefault().asyncExec(new Runnable() { public void run() { try { IWorkbench wb = PlatformUI.getWorkbench(); IProgressService ps = wb.getProgressService(); ps.busyCursorWhile(new IRunnableWithProgress() { public void run(IProgressMonitor pm) { File f = new File(path); File[] listFiles = f.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".jpg") || name.endsWith(".JPG"); } }); HashMap<DateTime, List<File>> imageFiles = new HashMap<DateTime, List<File>>(); HashMap<DateTime, Coordinate> timestamp2Coordinates = new HashMap<DateTime, Coordinate>(); List<String> nonTakenFilesList = new ArrayList<String>(); pm.beginTask("Browsing pictures...", listFiles.length); for (File file : listFiles) { try { HashMap<String, String> metaData = ExifHandler.readMetaData(file); DateTime creationDatetimeUtc = ExifHandler.getCreationDatetimeUtc(metaData); // correct with the given shift int secShift = (int) (shift / 1000f); creationDatetimeUtc = creationDatetimeUtc.plusSeconds(secShift); // search for gps points of that timestamp Coordinate coordinate = GeonotesHandler .getGpsCoordinateForTimeStamp(creationDatetimeUtc, intervalMinutes); if (coordinate == null) { // could not find date nonTakenFilesList.add(file.getAbsolutePath()); } else { List<File> fileList = imageFiles.get(creationDatetimeUtc); if (fileList == null) { fileList = new ArrayList<File>(); imageFiles.put(creationDatetimeUtc, fileList); } fileList.add(file); timestamp2Coordinates.put(creationDatetimeUtc, coordinate); } pm.worked(1); } catch (Exception e) { e.printStackTrace(); } } pm.done(); List<Object[]> featureObjectList = new ArrayList<Object[]>(); Set<Entry<DateTime, List<File>>> timeSet = imageFiles.entrySet(); if (!doNotImport) { pm.beginTask("Adding EXIF tags and importing matching photos...", timeSet.size()); } else { pm.beginTask("Adding EXIF tags to matching photos...", timeSet.size()); } for (Entry<DateTime, List<File>> entry : timeSet) { try { DateTime timestamp = entry.getKey(); List<File> fileList = entry.getValue(); Coordinate coordinate = timestamp2Coordinates.get(timestamp); // set gps exif tags StringBuilder sB = new StringBuilder(""); for (File file : fileList) { sB.append(file.getName()); sB.append(" "); ExifHandler.writeGPSTagsToImage(coordinate.y, coordinate.x, file); if (createFeatureLayer) { // handle feature obj Object[] featureObjects = new Object[3]; featureObjects[0] = gf.createPoint(coordinate); featureObjects[1] = file.getName(); featureObjects[2] = timestamp .toString(UtcTimeUtilities.utcDateFormatterYYYYMMDDHHMMSS); featureObjectList.add(featureObjects); } } if (!doNotImport) { String title = sB.toString(); String info = "Date:" + UtcTimeUtilities.toStringWithMinutes(timestamp) + "\nN:" + coordinate.y + "\nE:" + coordinate.x; GeonotesHandler geonotesHandler = new GeonotesHandler(coordinate.x, coordinate.y, title, info, PHOTO, timestamp, null, null, null, null); for (File mFile : fileList) { geonotesHandler.addMedia(mFile, mFile.getName()); } if (fieldBookView != null) { geonotesHandler.addObserver(fieldBookView); } geonotesHandler.notifyObservers(NOTIFICATION.NOTEADDED); } } catch (Exception e) { e.printStackTrace(); } pm.worked(1); } pm.done(); /* * dump feature layer */ if (createFeatureLayer) { SimpleFeatureCollection newCollection = FeatureCollections.newCollection(); SimpleFeatureTypeBuilder ftypeBuilder = new SimpleFeatureTypeBuilder(); ftypeBuilder.setName("pictureslayer"); ftypeBuilder.setCRS(DefaultGeographicCRS.WGS84); ftypeBuilder.add("the_geom", Point.class); ftypeBuilder.add("name", String.class); ftypeBuilder.add("date", String.class); SimpleFeatureType ftype = ftypeBuilder.buildFeatureType(); int id = 0; for (Object[] objects : featureObjectList) { SimpleFeatureBuilder builder = new SimpleFeatureBuilder(ftype); builder.addAll(objects); SimpleFeature feature = builder.buildFeature(ftype.getTypeName() + "." + id++); newCollection.add(feature); } try { FeatureUtilities.featureCollectionToTempLayer(newCollection); } catch (IOException e) { e.printStackTrace(); } } /* * handle not matched pics */ if (nonTakenFilesList.size() > 0) { final StringBuilder sB = new StringBuilder(); sB.append( "For the following images no gps point within the threshold could be found:\n"); for (String p : nonTakenFilesList) { sB.append(p).append("\n"); } Display.getDefault().asyncExec(new Runnable() { public void run() { Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); MessageDialog.openWarning(shell, "Warning", sB.toString()); } }); } else { Display.getDefault().asyncExec(new Runnable() { public void run() { Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); if (!doNotImport) { MessageDialog.openInformation(shell, "Info", "All photos were successfully tagged and imported."); } else { MessageDialog.openInformation(shell, "Info", "All photos were successfully tagged."); } } }); } } }); } catch (Exception e1) { e1.printStackTrace(); String message = "An error occurred while importing pictures"; ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, GeonotesPlugin.PLUGIN_ID, e1); } } }); return true; }
From source file:eu.stork.peps.auth.engine.STORKSAMLEngine.java
License:EUPL
/** * Generate stork authentication response. * /*from ww w .ja v a2 s. c om*/ * @param request the request * @param responseAuthReq the response authentication request * @param ipAddress the IP address * @param isHashing the is hashing * * @return the sTORK authentication response * * @throws STORKSAMLEngineException the STORKSAML engine exception */ public STORKAuthnResponse generateSTORKAuthnResponse(final STORKAuthnRequest request, final STORKAuthnResponse responseAuthReq, final String ipAddress, final boolean isHashing) throws STORKSAMLEngineException { LOG.info("generateSTORKAuthnResponse"); // Validate parameters validateParamResponse(request, responseAuthReq); // Mandatory SAML LOG.debug("Generate StatusCode"); final StatusCode statusCode = SAMLEngineUtils.generateStatusCode(StatusCode.SUCCESS_URI); LOG.debug("Generate Status"); final Status status = SAMLEngineUtils.generateStatus(statusCode); LOG.debug("Generate StatusMessage"); final StatusMessage statusMessage = (StatusMessage) SAMLEngineUtils .generateStatusMessage(StatusCode.SUCCESS_URI); status.setStatusMessage(statusMessage); LOG.debug("Generate Response"); // RESPONSE final Response response = genAuthnRespBase(status, request.getAssertionConsumerServiceURL(), request.getSamlId()); DateTime notOnOrAfter = new DateTime(); notOnOrAfter = notOnOrAfter.plusSeconds(super.getSamlCoreProperties().getTimeNotOnOrAfter()); final Assertion assertion = this.generateAssertion(ipAddress, request.getAssertionConsumerServiceURL(), request.getSamlId(), request.getIssuer(), notOnOrAfter); final AttributeStatement attrStatement = this .generateAttributeStatement(responseAuthReq.getPersonalAttributeList(), isHashing); assertion.getAttributeStatements().add(attrStatement); // Add assertions response.getAssertions().add(assertion); final STORKAuthnResponse authresponse = new STORKAuthnResponse(); try { authresponse.setTokenSaml(super.signAndMarshall(response)); authresponse.setSamlId(response.getID()); } catch (SAMLEngineException e) { LOG.error("Sign and Marshall.", e); throw new STORKSAMLEngineException(e); } return authresponse; }
From source file:eu.stork.peps.auth.engine.STORKSAMLEngine.java
License:EUPL
/** * Generate stork authentication response. * //from w w w. j a v a 2 s. co m * @param request the request * @param responseAuthReq the response authentication request * @param ipAddress the IP address * @param isHashing the is hashing * * @return the sTORK authentication response * * @throws STORKSAMLEngineException the STORKSAML engine exception */ public STORKAuthnResponse generateSTORKAuthnResponseAfterQuery(final STORKAuthnRequest request, final STORKAuthnResponse responseAuthReq, final String ipAddress, final boolean isHashing, List<STORKAttrQueryResponse> res) throws STORKSAMLEngineException { LOG.info("generateSTORKAuthnResponse"); // Validate parameters validateParamResponse(request, responseAuthReq); // Mandatory SAML LOG.debug("Generate StatusCode"); final StatusCode statusCode = SAMLEngineUtils.generateStatusCode(StatusCode.SUCCESS_URI); LOG.debug("Generate Status"); final Status status = SAMLEngineUtils.generateStatus(statusCode); LOG.debug("Generate StatusMessage"); final StatusMessage statusMessage = (StatusMessage) SAMLEngineUtils .generateStatusMessage(StatusCode.SUCCESS_URI); status.setStatusMessage(statusMessage); LOG.debug("Generate Response"); // RESPONSE final Response response = genAuthnRespBase(status, request.getAssertionConsumerServiceURL(), request.getSamlId()); DateTime notOnOrAfter = new DateTime(); notOnOrAfter = notOnOrAfter.plusSeconds(super.getSamlCoreProperties().getTimeNotOnOrAfter()); final Assertion assertion = this.generateAssertion(ipAddress, request.getAssertionConsumerServiceURL(), request.getSamlId(), request.getIssuer(), notOnOrAfter); final AttributeStatement attrStatement = this .generateAttributeStatement(responseAuthReq.getPersonalAttributeList(), isHashing); assertion.getAttributeStatements().add(attrStatement); // Add assertions response.getAssertions().add(assertion); // Check for response queries if (res != null && res.size() > 0) { //Iterate through them for (int i = 0; i < res.size(); i++) { //If response contains multiple assertions iterate through them as well if (res.get(i).getAssertions().size() > 1) { for (int j = 0; j < res.get(i).getAssertions().size(); j++) { Assertion tempAssertion = res.get(i).getAssertions().get(j); tempAssertion.setParent(response); response.getAssertions().add(tempAssertion); } } else { Assertion tempAssertion = res.get(i).getAssertion(); tempAssertion.setParent(response); response.getAssertions().add(tempAssertion); } } } final STORKAuthnResponse authresponse = new STORKAuthnResponse(); try { authresponse.setTokenSaml(super.signAndMarshall(response)); authresponse.setSamlId(response.getID()); } catch (SAMLEngineException e) { LOG.error("Sign and Marshall.", e); throw new STORKSAMLEngineException(e); } return authresponse; }
From source file:eu.stork.peps.auth.engine.STORKSAMLEngine.java
License:EUPL
/** * Generate stork authentication response fail. * /*from ww w .ja v a 2 s.co m*/ * @param request the request * @param response the response * @param ipAddress the IP address * @param isHashing the is hashing * * @return the sTORK authentication response * * @throws STORKSAMLEngineException the STORKSAML engine exception */ public STORKAuthnResponse generateSTORKAuthnResponseFail(final STORKAuthnRequest request, final STORKAuthnResponse response, final String ipAddress, final boolean isHashing) throws STORKSAMLEngineException { LOG.info("generateSTORKAuthnResponseFail"); validateParamResponseFail(request, response); // Mandatory final StatusCode statusCode = SAMLEngineUtils.generateStatusCode(response.getStatusCode()); // Mandatory SAML LOG.debug("Generate StatusCode."); // Subordinate code it's optional in case not covered into next codes: // - urn:oasis:names:tc:SAML:2.0:status:AuthnFailed // - urn:oasis:names:tc:SAML:2.0:status:InvalidAttrNameOrValue // - urn:oasis:names:tc:SAML:2.0:status:InvalidNameIDPolicy // - urn:oasis:names:tc:SAML:2.0:status:RequestDenied // - http://www.stork.gov.eu/saml20/statusCodes/QAANotSupported if (StringUtils.isNotBlank(response.getSubStatusCode())) { final StatusCode newStatusCode = SAMLEngineUtils.generateStatusCode(response.getSubStatusCode()); statusCode.setStatusCode(newStatusCode); } LOG.debug("Generate Status."); final Status status = SAMLEngineUtils.generateStatus(statusCode); if (StringUtils.isNotBlank(response.getMessage())) { final StatusMessage statusMessage = (StatusMessage) SAMLEngineUtils .generateStatusMessage(response.getMessage()); status.setStatusMessage(statusMessage); } LOG.debug("Generate Response."); // RESPONSE final Response responseFail = genAuthnRespBase(status, request.getAssertionConsumerServiceURL(), request.getSamlId()); DateTime notOnOrAfter = new DateTime(); notOnOrAfter = notOnOrAfter.plusSeconds(super.getSamlCoreProperties().getTimeNotOnOrAfter()); final Assertion assertion = this.generateAssertion(ipAddress, request.getAssertionConsumerServiceURL(), request.getSamlId(), request.getIssuer(), notOnOrAfter); responseFail.getAssertions().add(assertion); LOG.debug("Sign and Marshall ResponseFail."); final STORKAuthnResponse storkResponse = new STORKAuthnResponse(); try { storkResponse.setTokenSaml(super.signAndMarshall(responseFail)); storkResponse.setSamlId(responseFail.getID()); } catch (SAMLEngineException e) { LOG.error("SAMLEngineException.", e); throw new STORKSAMLEngineException(e); } return storkResponse; }