How to redirect User to website specific landing page - fragment

I wanted to redirect user to default landing page based on the website access user has in liferay. I am using liferay DXP. I know how it can be done in liferay 6.2, but i don't have a idea how to override/extend DefaultLandingPageAction class in liferay 7.
Let me know if anybody has done this before.
Thanks!!

I assume that you are trying to redirect the user after login.
Have a look at this. Should do the trick.
Place the class into a bundle and adjust the logic.
#Component(
immediate = true,
property = {
"key=login.events.post"
},
service = LifecycleAction.class
)
public class LandingPageRouter implements LifecycleAction {
private static Log LOG = LogFactoryUtil.getLog(LandingPageRouter.class);
#Reference
private UserLocalService userLocalService;
#Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {
//Do some magic
//build the path.
LastPath lastPath = new LastPath(StringPool.BLANK, path);
lifecycleEvent.getRequest().getSession().setAttribute(WebKeys.LAST_PATH, lastPath);
}
}
LastPath works as in DefaultLandingPageAction.

Related

Keycloak SPI custom labels

I'm building a Keycloak UserStorage SPI. For it, I need to configure some properties...
public class MyUserStorageProviderFactory implements UserStorageProviderFactory<MyUserStorageProvider> {
//...
#Override
public List<ProviderConfigProperty> getConfigProperties() {
if (configProperties == null) {
configProperties = ProviderConfigurationBuilder.create().property().name(Constants.CONFIG_URL)
.helpText(Constants.CONFIG_URL_HELP).label(Constants.CONFIG_URL_LABEL)
.type(ProviderConfigProperty.STRING_TYPE).add().property().name(Constants.CONFIG_USERNAME)
.helpText(Constants.CONFIG_USERNAME_HELP).label(Constants.CONFIG_USERNAME_LABEL)
.type(ProviderConfigProperty.STRING_TYPE).add().property().name(Constants.CONFIG_PASSWORD)
.helpText(Constants.CONFIG_PASSWORD_HELP).label(Constants.CONFIG_PASSWORD_LABEL)
.type(ProviderConfigProperty.PASSWORD).secret(true).add().build();
}
return configProperties;
}
And Constants.CONFIG_URL_LABEL as an example is just a string like "my url". Inside the Keycloak Admin, it presents these strings. My problem is - how can I use i8n labels here? The SPI is deployed as a JAR in standalone/deployments.
I don't want to build a custom theme for that? Adding a file META-INF/messages/messages_en.properties has no effect. What is wrong?
I think you need to set a custom theme. Please take a look at the keycloak source code for update-profile-on-first-login help text and the translation (admin-messages_en) for admin-messages.

Redirect Vaadin App

I am currently hosting my vaadin app on openshift. My main website redirects to the vaadin app when the login button is clicked. The first thing the user sees is the login page
I have 2 buttons on my website, a free trial button and a login button, and I have 2 different classes in my vaadin app, a login class and a free trial class.
How can I make the login button redirect to the login class of my vaadin app and the free trial button redirect to the free trial class of my vaadin app?
This is what it currently looks like:
#Theme("mytheme")
#Widgetset("com.example.myapp.MyAppWidgetset")
#PreserveOnRefresh
public class MyUI extends UI {
#WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
#VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
#Override
protected void init(VaadinRequest vaadinRequest) {
login();
}
You can use the Navigator as Chris M said, or you can try to implement an event driven architecture. I implemented a project like that using Vaadin too with Google Guava.
Here you can find some examples of how to use Google Guava if you are interested.
http://codingjunkie.net/guava-eventbus/
Below you can find some code fragments of my implementation:
// Using guava
final Button signin = new Button(
Lang.getMessage("login.signin"),
eventClick -> {BarsEventBus.post(new UserLoginRequestedEvent(
username.getValue(), password.getValue()));});
//Using Navigator, I also used spring here, so the registration view is a Spring View
final Button register = new Button(
Lang.getMessage("login.registration"),
clickEvent -> {getUI().getNavigator().navigateTo(ViewToken.REGISTRO);}
);
#UIScope
#SpringView(name = ViewToken.REGISTRO)
public class RegistrationView extends VerticalLayout implements View {...}
Please verify the code for the vaadin demo application. That code is having an example on how to handle it too. Find it here:
https://github.com/vaadin/dashboard-demo
You could pass in a parameter to your request and use a UI provider to serve the UI depending on this parameter.
See here.
Example:
public class DifferentFeaturesForDifferentClients extends UIProvider {
#Override
public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
if ("trial".equalsIgnoreCase(event.getRequest().getParameter("app-type"))) {
return TrialUI.class;
} else {
return LognUI.class;
}
}
}
web.xml:
<servlet>
<servlet-name>My Vaadin App</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<init-param>
<description>Vaadin UI</description>
<param-name>UIProvider</param-name>
<param-value>com.example.myexampleproject.DifferentFeaturesForDifferentClients</param-value>
</init-param>
</servlet>
And then in your main websites html code:
<form>
<input type="submit" name="app-type" value="Trial" formaction="/your/vaadin/url" formmethod="post">
<input type="submit" name="app-type" value="Login" formaction="/your/vaadin/url" formmethod="post">
<!-- Alternative using button tag (better for customization, but no IE < 9) -->
<button name="app-type" value="trial" type="submit">Trial</button>
<button name="app-type" value="login" type="submit">Login</button>
</form>
I now understand what you were truing to do. You can do this quite easily. You need to cast the VaadinRequest into a VaadinServletRequest. The reason it passes a VaadinRequest rather than an VaadinServletRequest is so you can deploy your application as a portlet too. In that case you would need to cast it to VaadinPortletRequest instead. Then you can use the serverName provided by the user.
#Override
protected void init(VaadinRequest vaadinRequest) {
VaadinServletRequest req = (VaadinServletRequest) vaadinRequest;
String serverName = req.getServerName();
if (serverName.equals("www.login.mywebsite.com"))
{
login();
}
else
{
trial();
}
}

wicket download link clear feedback panel

I have couple of drop downdowns and a download link button. Based on the user selection, i get the file to be downloaded. if the user did not make a selection I show an error on the feedback panel. if the user then makes a selection and clicks on download link it works fine, but the previous feedback message is still visible. How do I clear it.
onclick of the download link, i tried the following, but no use
FeedbackMessages me = Session.get().getFeedbackMessages();
me.clear();
Probably it is
Session.get().cleanupFeedbackMessages()
even it has been changed in Wicket 6.x
I've found this post and I think it is time to share the way for Wicket 6.x and for Wicket 7.x, because Session.get().cleanupFeedbackMessages() was deprecated already.
To do it for Wicket 6.x you have to implement additional filter for the feedback panel. Where to do it, it is your decision to decide.
Create a new FeedbackPanel implementation by extending from the existing FeedBackPanel class
private class MessagesFeedbackPanel extends FeedbackPanel{
private MessageFilter filter = new MessageFilter();
public MessagesFeedbackPanel(String id){
super(id);
setFilter(filter);
}
#Override
protected void onBeforeRender(){
super.onBeforeRender();
// clear old messages
filter.clearMessages();
}
}
Provide a new Filter implementation, by implementing the existing IFeedbackMessageFilter interface
public class MessageFilter implements IFeedbackMessageFilter{
List<FeedbackMessage> messages = new ArrayList<FeedbackMessage>();
public void clearMessages(){
messages.clear();
}
#Override
public boolean accept(FeedbackMessage currentMessage){
for(FeedbackMessage message: messages){
if(message.getMessage().toString().equals(currentMessage.getMessage().toString()))
return false;
}
messages.add(currentMessage);
return true;
}
}
Following code works for me in Wicket 6:
public class MyComponent extends Panel {
...
FeedbackMessages feedback = getFeedbackMessages();
feedback.clear();

Facebook action script 3 API login/logout issue

I'm making mobile AIR app for Android using Flash builder 4.5, AIR 2.6, Facebook action script 3 API the latest version.
I have a problem with login/logout. I can login only one time - then my data caches somehow and Facebook automatically logs me in. When I call logout I receive response TRUE, but I don't really logout from system. Standard login dialog doesn't appear for me. I have already read a lot of articles on stackoverflow and open issues on official site, but none of them were helpfull. How can I solve this? Here is the code I use:
package
{
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.external.ExternalInterface;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.Capabilities;
import flash.system.Security;
import flash.display.Loader;
import com.facebook.graph.FacebookMobile;
public class TestProj extends Sprite
{
public function TestProj()
{
super();
//register to add to stage
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
}
private function onAddedToStage(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
FacebookMobile.init("195053007196177", initCallback);
}
private function initCallback(success:Object, fail:Object):void
{
var appPermissions:Array = new Array("read_stream", "offline_access", "publish_stream", "read_friendlists");
FacebookMobile.login(loginCallback, this.stage, appPermissions);
//FacebookMobile.logout(logoutCallback);
}
private function loginCallback(success:Object, fail:Object):void
{
//And here I always receive success with my UserID
//and login dialog don't appears to me before this
if (success)
{
trace("login ok");
}
else
trace("login failed");
}
private function logoutCallback(success:Object):void
{
//here I reseive "TRUE" always!!
trace(success);
}
}
}
You're only passing the 1st argument of logoutCallback to your logout method. If you add in the 2nd argument of your site url specified for your app, it should clear it out the html cookie for that window. Also, set FacebookMobile.manageSession = false;
FacebookMobile.logout(logoutCallback, "http://your_app_origin_url");
There is a potential, related bug that involves Desktop and Mobile not accessing or clearing the access token's the same way. For that, there's a hack that describes exposing the access token in FacebookMobile, then manually calling the "logout" method with the access token. The issue is described here, including a method called "reallyLogout". If what I've written above doesn't work, implement "reallyLogout".
When you log out, your app clears the local session but does not log you out of the system. This is clearly defined in the documentation for logout. Think about it, if you're logged into Facebook on your Smartphone, Web Browser, and now this Mobile Desktop App, and suddenly you log out... it shouldn't log you out EVERYWHERE, just within that browsers session. So pass that 2nd parameter.
I've had this exact problem, and after trying numerous fixes, this finally seems to work:
The default logout functionality seems to not be properly clearing cookies via the FacebookMobile actionscript API. The solution in comment #33 here worked for me, reproduced here. Make sure to sub in your own APP_ID:
function logout(e:MouseEvent):void {
FacebookMobile.logout(onLogout, "https://m.facebook.com/dialog/permissions.request?app_id=APP_ID&display=touch&next=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&type=user_agent&perms=publish_stream&fbconnect=1");
}
function onLogout(result:Object):void
{
trace("Perfect Log Out!")
}
Have had this Android Facebook clean logout problem the whole day, manage to solve it. Hope it helps. Here is my FB mobile handlelogin code to ensure all fb cookies and sessions are being removed and user will need to relogin.
Sometimes FB server is very slow. Its best to put a timer before you call handleLoginClick() again
function handleLoginClick():void
{
trace("connecting to facebook");
if (FacebookMobile.getSession() == null)
{
FacebookMobile.init(APP_ID, onHandleInit, null);
FacebookMobile.manageSession = false
}
else
{
var webView:StageWebView = new StageWebView();
webView.viewPort = new Rectangle(0, 0, 1, 1);
webView.stage = this.stage;
webView.loadURL("https://m.facebook.com/logout.php?confirm=1&next=http://www.facebook.com&access_token=" + FacebookMobile.getSession().accessToken);
webView.addEventListener(Event.COMPLETE,webviewhandleLoad);
function webviewhandleLoad(e:Event)
{
FacebookMobile.logout(null, "http://apps.facebook.com/<appName>/");
FacebookMobile.logout(null, "http://www.facebook.com");
webView.dispose()
webView = null
setTimeout(handleLoginClick,3000)
}
}
}
look at the solution of this problem. Maby someone it helps:
var stage_ref:Stage = PlatformUtil.originalStage(); //my custom class to get stage
var webView:StageWebView = new StageWebView();
webView.viewPort = new Rectangle(0, 0, stage_ref.width, stage_ref.height);
FacebookMobile.login(loginCallback, stage_ref, appPermissions, webView);
http://code.google.com/p/facebook-actionscript-api/issues/detail?id=381
http://code.google.com/p/facebook-actionscript-api/issues/detail?id=382
http://code.google.com/p/facebook-actionscript-api/issues/detail?id=383

GWT TestCase: Simulating clicking a button on my page

I'm using GWT 2.4 with JUnit 4.8.1. When writing my class that extends GWTTestCase, I want to simulate clicking on a button on the page. Currently, in my onModuleLoad method, this button is only a local field ...
public void onModuleLoad() {
final Button submitButton = Button.wrap(Document.get().getElementById(SUBMIT_BUTTON_ID));
...
// Add a handler to send the name to the server
GetHtmlHandler handler = new GetHtmlHandler();
submitButton.addClickHandler(handler);
How do I simulate clicking on this button from the GWTTestCase? Do I have to expose this button as a public member accessor is there a more elegant way to access it? Here is what I have in my test case so far ...
public class GetHtmlTest extends GWTTestCase {
// Entry point class of the GWT application being tested.
private Productplus_gwt productPlusModule;
#Override
public String getModuleName() {
return "com.myco.clearing.productplus.Productplus_gwt";
}
#Before
public void prepareTests() {
productPlusModule = new Productplus_gwt();
productPlusModule.onModuleLoad();
} // setUp
#Test
public void testSuccessEvent() {
// TODO: Simulate clicking on button
} // testSuccessEvent
}
Thanks, - Dave
It can be as easy as buttonElement.click() (or ButtonElement.as(buttonWidget.getElement()).click(), or ButtonElement.as(Document.get().getElementById(SUBMIT_BUTTON_ID)).click())
But remember that a GWTTestCase doesn't run in your own HTML host page, but an empty one, so you'll first have to insert your button within the page before simulating your module's load.
gwt-test-utils seems to be the perfect framework to answer your need. Instead of inheriting from GWTTestCase, extend the gwt-test-utils GwtTest class and implement your click test with the Browser class, like shown in the getting starting guide :
#Test
public void checkClickOnSendMoreThan4chars() {
// Arrange
Browser.fillText(app.nameField, "World");
// Act
Browser.click(app.sendButton);
// Assert
assertTrue(app.dialogBox.isShowing());
assertEquals("", app.errorLabel.getText());
assertEquals("Hello, World!", app.serverResponseLabel.getHTML());
assertEquals("Remote Procedure Call", app.dialogBox.getText());
}
If you want to keep your button private, you'd be able to retrieve it by introspection. But my advice is to make you view's widgets package protected and to write your unit test in the same package so it could access them. It's more convinent and refactoring-friendly.
gwt-test-utils provide introspection convinence. For example, to retrieve the "dialogBox" field which could have been private, you could have do this :
DialogBox dialogBox = GwtReflectionUtils.getPrivateFieldValue(app, "dialogBox");
But note that using GwtReflectionUtils is not mandatory. gwt-test-utils allows you to use ANY java classes in GWT client side tests, without restriction :)
You can do it like this:
YourComposite view = new YourComposite();
RootPanel.get().add(view);
view.getSubmitButton.getElement().<ButtonElement>cast().click();