Keycloak SPI custom labels - keycloak

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.

Related

Excerpt and taxonomies on SULU Admin

how can I hide or disable "Excerpt and taxonomies" tab on SULU Admin UI, on my custom page template?
You can manipulate existing tabs by registering a custom Admin class and use the $viewCollection->get method to get the excerpt instance you could then hide it using a setTabCondition.
public function configureViews(ViewCollection $viewCollection): void
{
if ($viewCollection->has('sulu_page.page_edit_form.excerpt')) {
$viewCollection->get('sulu_page.page_edit_form.excerpt')
->setTabCondition(false);
}
}
Make sure the priority is lower then the original Admin Priority e.g.:
public function static getPriority(): int
{
return PageAdmin::getPriority() - 1;
}
Still I would not recommend hiding the excerpt tab as things like smart content which using the excerpt categories and tags.

How to redirect User to website specific landing page

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.

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();

How to add a Behavior to a component inside another Behavior added to that component in Wicket

I would like to add an AttributeAppender to a Component inside an AjaxEventBehavior using Apache Wicket. A Behavior has a getComponent() method but in the Constructor getComponent() obvioulsy returns null.
Now I pass the component to the Constructor of the AjaxEventBehavior and it's working but is this a good way to achieve my goal..
Here's what I'm doing:
AjaxTooltipBehavior:
public class AjaxTooltipBehavior extends AjaxEventBehavior {
public AjaxTooltipBehaviour(String event, Component tooltippedComponent) {
super(event);
tooltippedComponent.add(new AttributeAppender("data-tooltip","wicketAjaxTooltip"));
}
...
}
And that's the way I use it:
...
final WebMarkupContainer icon = new WebMarkupContainer("icon"); //a tooltiped icon
icon2.add(new AjaxTooltipBehaviour("mouseover",icon2)
I asked myself if there isn't a way to add the AttributeAppender to the componet without passing the component to the AjaxTooltipBehavior.
Does anyone know if this is possible in wicket or if there are better solutions?
FYI: I'm using wicket 1.6.
Thanks in advance for your support!
Ronny
Generally you would override Behavior#onBind(Component), but this method is made final in AbstractAjaxBehavior. But it will call onBind() and you use getComponent() there:
#Override
protected void onBind() {
super.onBind();
getComponent().add(new AttributeAppender("data-tooltip","wicketAjaxTooltip"));
}
Because you have extended from AbstractAjaxBehavior (AjaxEventBehavior extends AbstractAjaxBehavior), you should gain access to getComponent(), which will give you the component the behavior is attached to.
I override Behavior#onConfigure(Component component) wich is possible the most suitable way to add Behaviors or do some other stuff with the component belonging to the Behavior.
#Override
protected void onConfigure(Component component) {
super.onConfigure();
component().add(new AttributeAppender("data-tooltip","wicketAjaxTooltip"));
}

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();