Handle frontend login and authentication via LDAP - ibm-datapower

I've created a MPGW policy to add a front page to authenticate before go to backside :
Requests Rules:
Rule1 : Matchrule: /favicon.ico
Rule2: Matchrule: /loginpage.html Transform: xsl stylesheet to dispaly a html loginpage and add the login & password at the query params in the URL
Rule3: Matchrule: /wps/portal/Home Transform: xsl stylesheet to extract login/passwrd from URL and authenticate user with a LDAP (dp:ldap-authen()) and write result in a context variable
and here is my problem:
Response Rules:
Rule4: Matchrule: "/" Transform : xsl stylesheet " i want to do: if context variable is OK nothing to do else display an error page html " !!!??
i've written in the response stylesheet something like :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions" xmlns:re="http://exslt.org/regular-expressions"
extension-element-prefixes="dp re"
exclude-result-prefixes="dp re">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:if test="string-length(dp:variable('var://context/LDAP_Auth_Status')) = 0">
<!--ERROR-->
<html>
<head>
<title> Error Page</title>
</head>
<body>
<h2> Error USER VALIDITY </h2>
<strong>doom!!</strong>
</body>
</html>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

First, Rule4: Matchrule: "*" should be an asterisk if you want it to match anything.
Secondly, is there a backside response?
Else you have to add a var://service/skip-backside=1 if the Response rule should be run. It wil go to Error rule otherwise.
Also it is good practice to not add values into the context. You should use context variables, e.g.:
var://context/LDAPInfo/LDAP_Auth_Status
You can use <xsl:message pd:priority="debug"> to add information into the logs for easier way to find values. Also use the Probe to find Context variable values and see how the flow runs.

Related

HERE GET batch geocoding response 403 but job is complete

I successfully submitted a batch geocoding request...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:SearchBatch xmlns:ns2="http://www.navteq.com/lbsp/Search-Batch/1">
<Response>
<MetaInfo>
<RequestId>CAOxHo4SFaj17sSB2UyTxeoDKHZR77f9</RequestId>
</MetaInfo>
<Status>accepted</Status>
<TotalCount>0</TotalCount>
<ValidCount>0</ValidCount>
<InvalidCount>0</InvalidCount>
<ProcessedCount>0</ProcessedCount>
<PendingCount>0</PendingCount>
<SuccessCount>0</SuccessCount>
<ErrorCount>0</ErrorCount>
</Response>
</ns2:SearchBatch>
And when I GET status, the job is completed....
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:SearchBatch xmlns:ns2="http://www.navteq.com/lbsp/Search-Batch/1">
<Response>
<MetaInfo>
<RequestId>CAOxHo4SFaj17sSB2UyTxeoDKHZR77f9</RequestId>
</MetaInfo>
<Status>completed</Status>
<JobStarted>2019-10-31T00:11:58.000Z</JobStarted>
<JobFinished>2019-10-31T00:12:26.000Z</JobFinished>
<TotalCount>13291</TotalCount>
<ValidCount>13291</ValidCount>
<InvalidCount>0</InvalidCount>
<ProcessedCount>13291</ProcessedCount>
<PendingCount>0</PendingCount>
<SuccessCount>13291</SuccessCount>
<ErrorCount>0</ErrorCount>
</Response>
However, when I then go to get the response, I get 403 forbidden
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<h1>Forbidden</h1>
<p>You don't have permission to access /
on this server.</p>
</body>
</html>
I am using the endpoint outlined here: https://developer.here.com/documentation/batch-geocoder/topics/example-get-results.html
In this case you need to pass correct apikey to download the result.
https://batch.geocoder.ls.hereapi.com/6.2/jobs/CAOxHo4SFaj17sSB2UyTxeoDKHZR77f9/result?apiKey={}
Also refer https://developer.here.com/documentation/batch-geocoder/dev_guide/topics/example-get-results.html

Displaying text in Thymeleaf

I'm totally new in Thymeleaf. Just read about it earlier, now, I'm trying to display some text using Thymeleaf in the front end, getting the values from Spring MVC in back-end.
File successPwd.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<meta charset="UTF-8"/>
<title>Password Change</title>
</head>
<body>
<h2>Password Changed</h2>
Your password has been changed. Your account information is below.
Username: [[${account.username}]] <br/>
First Name: [[${account.firstName}]] <br/>
Last Name: [[${account.surname}]] <br/>
</body>
</html>
File PasswordResetController.java
#RequestMapping(value= "/user/new_password", method = RequestMethod.POST)
public String saveNewPassword(#RequestParam(value="new_password",required=false) String password, #RequestParam(value="hash") String hash, Model model)
{
//some codes to check hash
AccountInfo account = accountInfoService.getAccount(hash);
model.addAttribute("account", account);
return "/successPwd";
}
What I'm getting is like this:
Password Changed
Your password has been changed. Your account information is below.
Username: [[${account.username}]]
First Name: [[${account.firstName}]]
Last Name: [[${account.surname}]]
Thymeleaf is not converting to the proper values, most likely I missed something very very basic here.
In this case, you should use th:text. For example, Username: <p th:text=${account.username}>Username will be rendered here</p>. Note that, the text inside p tag won't be shown.
See here for more details: Standard thymeleaf syntax
If you want to get rid of the "awkward" Html tag you can do as follows.
<span th:text="${account.username}" th:remove="tag">userName</span>

How to upload and save a picture with eXist-db?

I am tryng to upload a picture and store it in exist-db but i get the next error when opening the stored picture:
Cannot open specified file: Could not recognize image encoding.
I have tryed the next code with a small adjustment for normal txt files and it works fine but not with pictures.
picture.xhtml
<?xml-model href="http://www.oxygenxml.com/1999/xhtml/xhtml-xforms.nvdl" schematypens="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<head>
<title/>
<xf:model>
<xf:instance xmlns="">
<data>
<image xsi:type="xs:base64Binary"/>
</data>
</xf:instance>
<xf:submission id="save" action="save.xquery" method="post"/>
</xf:model>
</head>
<body>
<xf:upload ref="image">
<xf:label>Upload Photo:</xf:label>
</xf:upload>
<br/>
<xf:submit submission="save">
<xf:label>Save</xf:label>
</xf:submit>
</body>
</html>
save.xquery
xquery version "3.1";
declare option exist:serialize "method=xhtml media-type=text/html indent=yes";
let $login:=xmldb:login('xmldb:exist:///db/apps/places','admin','admin')
(: The small adjusment i refer is just to change file extension from .jpeg to .txt :)
return xmldb:store("/db/apps/places/",concat("pic",".jpeg"), util:base64-decode(request:get-data()//image))
If you want to store images to the eXist-db you should probably replace xmldb:store() with xmldb:store-as-binary().

Symfony2 - "Invalid Resource Exception" when translating twig template

I am trying to translate labels in my twig template located in Resources/views/User/ folder:
<label for="username">{% trans %}Username{% endtrans %} </label>
And the following is a section from my login.ka.xliff file located in my project under "translations" folder:
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Username</source>
<target>მომხმარებელი</target>
</trans-unit>
</body>
</file>
</xliff>
and this is my route to the login page:
login:
path: /login/{_locale}
defaults: { _controller: ExampleBundle:LogIn:login }
requirements:
_locale: en|ka
I have two problems:
When I try to open the login page with a locale (say, ka) I get the:
500 Internal Server Error - Twig_Error_Runtime
1 linked Exception:
InvalidResourceException »
I know I can get the locale from request using $request->getLocale(); but how do I specify that login page should use login.ka.xliff file for translations?
Ok, I seem to have provided not enough info, so here it is:
I put my translation file in Example:MyBundle:Resources:translations (this is what I meant above "in my project").
I get exception when rending my login view and the following is the full version of the exception I get:
"An exception has been thrown during the rendering of a template ("") in ExampleMyBundle:User:login.html.twig at line 32.
500 Internal Server Error - Twig_Error_Runtime
1 linked Exception:
InvalidResourceException »"
And yes, I did try clearing cache each time I made changes, but it didn't help.
And also, I added the complete version of my login.ka.xliff file.
Thanks again!
Your xliff file seems to be invalid - it should look like this: ( containing the xml-namespace, body, ... ).
<!-- messages.ka.xliff -->
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Username</source>
<target>მომხმარებელი</target>
</trans-unit>
</body>
</file>
</xliff>
The file should be named messages.ka.xliff if you haven't actually specified a different translation domain in your template!
{{ 'Username'|trans({}, "login") }}
... or configured a different default translation-domain in your template ...
{% trans_default_domain "login" %}
<trans-unit id="1">
<source>Username</source>
<target>მომხმარებელი</target>
</trans-unit>
... is an invalid xliff-file.

App in development hangs every second time it is run

This is a fairly straightforward question for such odd behaviour, but that is exactly what my app is doing on the Playbook. I open the app the first time and it runs perfectly. I close the app, and then open it again and it hangs/freezes after the first action I perform with it. I then close the app, it seems to reset itself, and then opens and runs perfectly the next time.
I am using the latest WebWorks and am debugging on the PB with a debug token. My previous app (written/tested on pre OS2.0) worked, and continues to work, just fine.
I am pleased to post code if you would like, but it may be a waste of space. In an effort to root out the problem, I wrote a quick Hello World app that writes one item to an HTML5 database on the playbook (my main app also uses WebDB), and that app, as simple as it is, has exactly the same behavior. All my apps function fine in Chrome.
If anyone has any thoughts about what could be causing this behaviour, please post a reply.
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="helloworld.js"></script>
</head>
<body>
<input type="text" id="testDBInput"/>
<button type="button" onclick="testDB()">go</button>
</body>
</html>
JavaScript Document:
var taskdb=openDatabase ("helloworldDB", "1.0", "test database", 10*1024*1024);
taskdb.transaction(function(tx)
{
tx.executeSql("CREATE TABLE IF NOT EXISTS maintable (id integer primary key autoincrement, nametitle TEXT)");
});
function testDB()
{
var testTitle=document.getElementById("testDBInput").value;
taskdb.transaction(function(tx)
{
tx.executeSql("INSERT INTO maintable (nametitle) VALUES (?)", [testTitle], function (tx, results)
{
});
});
}
blackberry-tablet.xml:
<?xml version="1.0" encoding="utf-8"?>
<qnx>
<icon>
<image></image>
</icon>
<author>***edited for privacy***</author>
<authorId>***edited for privacy***</authorId>
<platformVersion>1.0.0.0</platformVersion>
</qnx>
config.xml:
<?xml version="1.0" encoding="utf-8"?>
<widget xmlns=" http://www.w3.org/ns/widgets"
xmlns:rim="http://www.blackberry.com/ns/widgets"
version="1.0.0.0">
<name>Tester</name>
<description>
PB Tester
</description>
<rim:orientation mode="landscape"/>
<rim:loadingScreen onFirstLaunch="true" >
</rim:loadingScreen>
<author>***edited for privacy***</author>
<icon src="bdicon.png"/>
<content src="index.html"/>
<feature id="blackberry.app" required="true" version="1.0.0.0"/>
<feature id="blackberry.ui.dialog" required="true" version="1.0.0.0"/>
</widget>
It sounds like the javascript crashed when the appli hangs. testDB() has few lines, you can insert alert() to see which line is not reached

Resources