Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
11 changed files
with
344 additions
and
136 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...admin-gui/src/main/java/com/evolveum/midpoint/gui/api/component/captcha/CaptchaPanel.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!-- | ||
~ Copyright (c) 2010-2016 Evolveum | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
<!DOCTYPE html> | ||
<html xmlns:wicket="http://wicket.apache.org"> | ||
<body> | ||
|
||
<wicket:panel> | ||
<p> | ||
<img wicket:id="image" /> | ||
<a wicket:id="changeLink">change</a> | ||
</p> | ||
<p> | ||
Please replicate the text you see above | ||
<br /> | ||
<input wicket:id="text" type="text" size="40" /> | ||
</p> | ||
|
||
<div wicket:id="feedback"></div> | ||
</wicket:panel> | ||
|
||
</body> | ||
</html> |
112 changes: 112 additions & 0 deletions
112
...admin-gui/src/main/java/com/evolveum/midpoint/gui/api/component/captcha/CaptchaPanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.evolveum.midpoint.gui.api.component.captcha; | ||
|
||
import org.apache.wicket.ajax.AjaxRequestTarget; | ||
import org.apache.wicket.ajax.markup.html.AjaxLink; | ||
import org.apache.wicket.extensions.markup.html.captcha.CaptchaImageResource; | ||
import org.apache.wicket.feedback.ContainerFeedbackMessageFilter; | ||
import org.apache.wicket.markup.ComponentTag; | ||
import org.apache.wicket.markup.html.form.RequiredTextField; | ||
import org.apache.wicket.markup.html.image.Image; | ||
import org.apache.wicket.markup.html.panel.FeedbackPanel; | ||
import org.apache.wicket.model.PropertyModel; | ||
|
||
import com.evolveum.midpoint.gui.api.component.BasePanel; | ||
|
||
public class CaptchaPanel extends BasePanel<Void> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* The generated random text; | ||
*/ | ||
protected String randomText; | ||
|
||
/** | ||
* The text provided by the user | ||
*/ | ||
private String captchaText; | ||
|
||
private final CaptchaImageResource captchaImageResource; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param id | ||
* The component id | ||
*/ | ||
public CaptchaPanel(String id) { | ||
super(id); | ||
|
||
final FeedbackPanel feedback = new FeedbackPanel("feedback", | ||
new ContainerFeedbackMessageFilter(CaptchaPanel.this)); | ||
add(feedback); | ||
|
||
captchaImageResource = createCaptchImageResource(); | ||
final Image captchaImage = new Image("image", captchaImageResource); | ||
captchaImage.setOutputMarkupId(true); | ||
add(captchaImage); | ||
|
||
AjaxLink<Void> changeCaptchaLink = new AjaxLink<Void>("changeLink") { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public void onClick(AjaxRequestTarget target) { | ||
captchaImageResource.invalidate(); | ||
target.add(captchaImage); | ||
} | ||
}; | ||
add(changeCaptchaLink); | ||
|
||
add(new RequiredTextField<String>("text", | ||
new PropertyModel<String>(CaptchaPanel.this, "captchaText"), String.class) { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected final void onComponentTag(final ComponentTag tag) { | ||
super.onComponentTag(tag); | ||
// clear the field after each render | ||
tag.put("value", ""); | ||
} | ||
}); | ||
} | ||
|
||
protected CaptchaImageResource createCaptchImageResource() { | ||
return new CaptchaImageResource() { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected byte[] render() { | ||
randomText = randomString(6, 8); | ||
getChallengeIdModel().setObject(randomText); | ||
return super.render(); | ||
} | ||
}; | ||
} | ||
|
||
public void invalidateCaptcha() { | ||
captchaImageResource.invalidate(); | ||
} | ||
|
||
static int randomInt(int min, int max) | ||
{ | ||
return (int)(Math.random() * (max - min) + min); | ||
} | ||
|
||
static String randomString(int min, int max) | ||
{ | ||
int num = randomInt(min, max); | ||
byte b[] = new byte[num]; | ||
for (int i = 0; i < num; i++) | ||
b[i] = (byte)randomInt('a', 'z'); | ||
return new String(b); | ||
} | ||
|
||
public String getCaptchaText() { | ||
return captchaText; | ||
} | ||
|
||
public String getRandomText() { | ||
return randomText; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.