Situation
I'm migrating a project from Wicket 1.5.7 to Wicket 6.12, one of the errors I get is explained below.
Code
#Override
protected void onSubmit() {
final String usernameValue = mail.getModelObject();
//Password is left empty in this particular case
AuthenticatedWebSession.get().signIn(usernameValue,"");
if (!continueToOriginalDestination())
{
setResponsePage(getApplication().getHomePage());
}
}
Error
This is the error I got when changing wicket versions: The operator !
is undefined for the argument type(s) void
Note: I see this error when hovering over !continueToOriginalDestination
What did I try
In my search on stackoverflow I came accross this question:
continueToOriginalDestination does not bring me back to originating page
Also checked this topic on apache wicket:
http://apache-wicket.1842946.n4.nabble.com/Handling-ReplaceHandlerException-on-continueToOriginalDestination-in-wicket-1-5-td4101981.html#a4115437
So I changed my code to this:
#Override
public void onSubmit() {
final String usernameValue = mail.getModelObject();
AuthenticatedWebSession.get().signIn(usernameValue,"");
setResponsePage(getApplication().getHomePage());
throw new RestartResponseAtInterceptPageException(SignInPage.class);
}
Question
The old situation nor the code change seem to work in my particular case.
Maybe it's a small change, is my new code wrong, how should this work?
Has Wicket changed that much, so that the old code is not supported anymore, or can !continueToOriginalDestination be used as well?
This helps
http://www.skybert.net/java/wicket/changes-in-wicket-after-1.5/
In 1.5, you could do the following to break out of the rendering of one page, go to another page (like login page) and then send the user back to where he/she was:
public class BuyProductPage extends WebPage {
public BuyProductPage() {
User user = session.getLoggedInUser();
if (user null) {
throw new RestartResponseAtInterceptPageException(LoginPage.class);
}
}
}
and then in LoginPage.java have this to redirect the user back to BuyProductPage after he/she's logged in:
public class LoginPage extends WebPage {
public LoginPage() {
// first, login the user, then check were to send him/her:
if (!continueToOriginalDestination()) {
// redirect the user to the default page.
setResponsePage(HomePage.class);
}
}
}
The method continueToOriginalDestination has changed in Wicket 6, it's now void which makes your code look more magic and less than logic IMO:
public class LoginPage extends WebPage {
public LoginPage() {
// first, login the user, then check were to send him/her:
continueToOriginalDestination();
// Magic! If we get this far, it means that we should redirect the
// to the default page.
setResponsePage(HomePage.class);
}
}
Related
so I have this application. It has newly got sso via kerberos but is also running ldap as a fallback option. There is a routingpage that directs people to the homepage if authenticated by kerberos or leads them to the loginpage if not. Now I was made aware of the fact, that a lot of people actually go first to the application via a link they receive via mail where they need to approve something and they are annoyed that they get directed to the homepage after clicking the link because that is how it's implemented that after authentification they will go to the homepage.
So now I found a way to get redirect them straight to the approvalpage from the e-mail via kerberos but I can't seem to make it work via kerberos. I keep getting directed to the homepage.
So this is my attempt:
RoutingPage:
public class RouterPage extends BasePage {
public SSORouterPage () {
super();
AppSession session = (AppSession) SecureWebSession.get();
String approvalLink = getRequest().getRequestParameters().getParameterValue("approval_link").toString();
if (approvalLink != null) {
session.setApprovalLink(approvalLink);
}
if (!session.singleSignOn()) {
log.warn("User not logged in, redirecting to login page");
if (session.hasApprovalLink()) {
approvalLink = session.getApprovalLink();
session.setApprovalLink(null);
setResponsePage(LoginPage.class, getApprovalPageParameters(approvalLink));
} else {
setResponsePage(LoginPage.class);
}
} else {
String name = Optional
.ofNullable(SecurityContextHolder.getContext()).map(SecurityContext::getAuthentication).map(
Authentication::getName).orElse("undefined");
log.info("Sucessfull sign in for {}", name);
if (session.hasApprovalLink()) {
approvalLink = session.getApprovalLink();
session.setApprovalLink(null);
setResponsePage(new ApprovalPage(getApprovalPageParameters(approvalLink)));
} else {
setResponsePage(HomePage.class);
}
}
}
LoginPage
public class LoginPage extends BasePage {
private static final long serialVersionUID = 4297836260248255954L;
public static final String LOGIN_PANEL_ID = "panel";
public LoginPage() {
super();
if (AuthenticatedWebSession.class.isAssignableFrom(getSession().getClass()) && ((AuthenticatedWebSession) getSession()).isSignedIn()) {
continueToOriginalDestination();
}
}
public LoginPage(final PageParameters pageParameters){
super(pageParameters);
if (AuthenticatedWebSession.class.isAssignableFrom(getSession().getClass()) && ((AuthenticatedWebSession) getSession()).isSignedIn()) {
setResponsePage(new ApprovalPage(pageParameters));
}
}
The constructor with the PageParameters is clearly called because I can see them in the url, why do I get directed to the homepage? Any ideas?
I would recommend you to use Component#continueToOriginalDestination(). See its javadoc. Its purpose is to continue to the originally requested page after an interception like "you need to login first". You need to use #redirectToInterceptPage(LoginPage.class) with it.
I'm actually writing a java code in the setupRender() method. Depending of a value provided by the server side, i would like to display an Alert dialog box to the user. By clicking on ok, the application should be closed.
I have not already found how to display an Alert dialog box with tapestry. Do somebody know how to procedd?
Thanks
It's not quite clear to me what you are trying to achieve, but perhaps the following two suggestions are useful.
Suggestion 1 - Display a message using AlertManager
In the page class, inject AlertManager and add the message to it.
public class YourPage {
#Inject
AlertManager alertManager;
Object setupRender() {
// ...
alertManager.alert(Duration.UNTIL_DISMISSED, Severity.INFO, "Love Tapestry");
}
}
Then use the <t:alerts/> component in the page template file to have the message displayed.
Note: The user may dismiss the message, that is, make it disappear. But it doesn't 'close the application' (whatever it is that you mean by that).
Suggestion 2 - Redirect to another page
The setupRender method can return different things. For example, it could return another page class, causing a redirect to that page. On that page, you could have the messages displayed and the session subsequently invalidated (if that's what you meant by 'application should be closed'.
public class YourPage {
Object setupRender() {
// ...
return AnotherPage.class;
}
}
public class AnotherPage {
#Inject
Request request;
void afterRender() {
Session session = request.getSession(false);
session.invalidate();
}
}
See the Tapestry docs for details about what setupRender() can return.
Suggestion 3 - Use JavaScript to display Alert and trigger Component Event
This approach uses JavaScript to display an Alert and subsequently trigger a component event via ajax. The event handler takes care of invalidating the session.
Note: Closing the current browser windows/tab with JavaScript isn't as easy as it used to be. See this Stackoverflow question for details.
YourPage.java
public class YourPage {
boolean someCondition;
void setupRender() {
someCondition = true;
}
#Inject
private JavaScriptSupport javaScriptSupport;
#Inject
ComponentResources resources;
public static final String EVENT = "logout";
void afterRender() {
if (someCondition) {
Link link = resources.createEventLink(EVENT);
JSONObject config = new JSONObject(
"msg", "See ya.",
"link", link.toAbsoluteURI()
);
javaScriptSupport.require("LogoutAndCloseWindow").with(config);
}
}
#Inject Request request;
#OnEvent(value = EVENT)
void logout() {
Session session = request.getSession(false);
if (session != null) session.invalidate();
}
}
YourPage.tml
<!DOCTYPE html>
<html
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd"
xmlns:p="tapestry:parameter">
<h1>Hit the Road Jack</h1>
</html>
LogoutAndCloseWindow.js
define(["jquery"], function($) {
return function(config) {
alert(config.msg);
$.ajax({
type: "GET",
url: config.link
});
window.close(); // Legacy. Doesn't work in current browsers.
// See https://stackoverflow.com/questions/2076299/how-to-close-current-tab-in-a-browser-window
}
})
I followed the guide on the Android docs but for some reason nothing is showing when i start my app.
I even tried logging the listeners but nothing is showing up in logcat.
I also changed the ad technology in admob setting to Custom set of ad technology providers, but still not working.
My code
ConsentInformation consentInformation = ConsentInformation.getInstance(getApplicationContext());
ConsentInformation.getInstance(getApplicationContext()).addTestDevice("6AE7D8950FE9E464D988F340C0D625B0");
ConsentInformation.getInstance(getApplicationContext()).
setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_EEA);
String[] publisherIds = {""};
consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
#Override
public void onConsentInfoUpdated(ConsentStatus consentStatus) {
// User's consent status successfully updated.
Log.d(TAG,"onConsentInfoUpdated");
}
#Override
public void onFailedToUpdateConsentInfo(String errorDescription) {
// User's consent status failed to update.
Log.d(TAG,"onFailedToUpdateConsentInfo");
}
});
form = new ConsentForm.Builder(this, privacyUrl)
.withListener(new ConsentFormListener() {
#Override
public void onConsentFormLoaded() {
// Consent form loaded successfully.
Log.d(TAG,"form loaded!");
form.show();
}
#Override
public void onConsentFormOpened() {
// Consent form was displayed.
}
#Override
public void onConsentFormClosed(
ConsentStatus consentStatus, Boolean userPrefersAdFree) {
// Consent form was closed.
}
#Override
public void onConsentFormError(String errorDescription) {
// Consent form error.
Log.d(TAG,"form error!");
}
})
.withPersonalizedAdsOption()
.withNonPersonalizedAdsOption()
.withAdFreeOption()
.build();
form.load();
Gradle
dependencies {
classpath 'com.google.gms:google-services:4.3.2'
}
implementation 'com.google.android.ads.consent:consent-library:1.0.7'
implementation 'com.google.android.gms:play-services-plus:17.0.0'
implementation 'com.google.android.gms:play-services-ads:18.2.0'
EDIT
I tried it on a project which was pre android x and now it calls the listener onFailedToUpdateConsentInfo.
With following error message:
onFailedToUpdateConsentInfoCould not parse Event FE preflight response.
Searched a bit and found this could be because of an invalid pub id, but i'm certain i'm using the right one.
1) I think you forget to check isRequestLocationInEeaOrUnknown() method.
It will return true If user already agreed to the consent. In this case, you don't need to ask it again. I think you already agreed to consent.
wrap your code with
if(ConsentInformation.getInstance(context).isRequestLocationInEeaOrUnknown()){
//setup admob
}else{
//Ask for consent
}
2) You have to call form.show(); to present the form to the user, check Google Doc
I was still using test app id and test ad ids, remove them and change it with your id's and make sure you use it as a testdevice so you don't violate admob policies.
Like this
adLoader.loadAd(new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build());
Not getting sessin value in vaadin framework
Used below :
private void setCurrentUsername(String username){
VaadinService.getCurrentRequest().getWrappedSession().setAttribute("LOGGED_IN_AS_USER",username);
userSubMenu.setText(username);
}
public static String getCurrentUsername() {
//log.info("User:::::::::::::::::" + (String) VaadinService.getCurrentRequest().getWrappedSession().getAttribute("LOGGED_IN_AS_USER"));
return (String) VaadinService.getCurrentRequest().getWrappedSession().getAttribute("LOGGED_IN_AS_USER");
}
getting value as null when flow going to other class
You could try using VaadinSession.getCurrent().getSession() instead?
iIf you are using this for a user interface i.e a user logging in. Don't forget that when your app first builds/ when the user first enters it they will of course have a null value(including any sub pages).
Try adding a ViewChangeListener to the page that the user now enters (apologies for any errors in coding i'm not currently able to gain access to my machine) into:
#Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
this.username = VaadinSession.getCurrent().getAttribute("LOGGED_IN_AS_USER");
}
I have a problem to redirect a page after invalidating session using Wicket.
Careers1 is a page, that needs user to be logged in, with six buttons linked to other pages and an a href button, which get the user logged out.
My code apparently works, because if I click to log out, and I click to one of the six buttons, it redirects me to the log in page.
But I need it to redirect me immediately, after I clicked "log out".
I tried setResponsePage() and also adding signOut() the problem is the same of the RestartResponseException.
Here is my code
Careers1:
public class Careers1 extends WebPage
{
public Careers1()
{
Link logoutLink = new Link("logout")
{
#Override
public void onClick()
{
getSession().invalidate();
throw new RestartResponseException(Careers1.class);
}
};
add(logoutLink);
}
}
On careers.html I have
<div class="logout" > <a wicket:id="logout" href="#"> LOG OUT </a></div>
Which should invalidate the session, and redirect the user to the login.
You can try forcing wicket to redirect immediately using a fake page that just redirects back to Careers1. Let's name it RedirectorPage:
public class RedirectorPage extends WebPage
{
#Override
protected void onBeforeRender()
{
throw new RestartResponseException(Careers1.class);
}
}
Now in the logout link of Careers1 you redirect to RedirectorPage. That worked for me, but only after I moved the exception of RedirectorPage into onBeforeRender(). Throwing the exception in the page constructor still makes wicket ignore the fact the session has already been invalidated.