Skip to content

Commit f79e514

Browse files
committed
add /forgottenpassword rest api
1 parent 34396c3 commit f79e514

File tree

74 files changed

+3205
-427
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+3205
-427
lines changed

build/checkstyle-suppression.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@
2525

2626
<suppressions>
2727
<suppress files="XmlFactoryTest\.xml" checks="[a-zA-Z0-9]*"/>
28+
<suppress files="rest.jsp" checks="FileLength"/>
2829
</suppressions>

server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
<dependency>
193193
<groupId>com.github.ldapchai</groupId>
194194
<artifactId>ldapchai</artifactId>
195-
<version>0.7.4</version>
195+
<version>0.7.5</version>
196196
</dependency>
197197
<dependency>
198198
<groupId>commons-net</groupId>

server/src/main/java/password/pwm/AppProperty.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ public enum AppProperty
344344
TOKEN_REMOVE_ON_CLAIM ( "token.removeOnClaim" ),
345345
TOKEN_VERIFY_PW_MODIFY_TIME ( "token.verifyPwModifyTime" ),
346346
TOKEN_STORAGE_MAX_KEY_LENGTH ( "token.storage.maxKeyLength" ),
347+
REST_SERVER_FORGOTTEN_PW_TOKEN_DISPLAY ( "rest.server.forgottenPW.token.display" ),
348+
REST_SERVER_FORGOTTEN_PW_RULE_DELIMITER ( "rest.server.forgottenPW.ruleDelimiter" ),
347349
TELEMETRY_SENDER_IMPLEMENTATION ( "telemetry.senderImplementation" ),
348350
TELEMETRY_SENDER_SETTINGS ( "telemetry.senderSettings" ),
349351
TELEMETRY_SEND_FREQUENCY_SECONDS ( "telemetry.sendFrequencySeconds" ),

server/src/main/java/password/pwm/PwmConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public abstract class PwmConstants
166166
public static final String PARAM_RECOVERY_OAUTH_RESULT = "roauthResults";
167167
public static final String PARAM_SIGNED_FORM = "signedForm";
168168
public static final String PARAM_USERKEY = "userKey";
169+
public static final String PARAM_METHOD_CHOICE = "methodChoice";
169170

170171

171172
public static final String COOKIE_PERSISTENT_CONFIG_LOGIN = "CONFIG-AUTH";

server/src/main/java/password/pwm/bean/TokenDestinationItem.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@
2323
package password.pwm.bean;
2424

2525
import lombok.Builder;
26+
import lombok.Getter;
2627
import lombok.Value;
28+
import password.pwm.AppProperty;
2729
import password.pwm.PwmApplication;
2830
import password.pwm.config.Configuration;
2931
import password.pwm.config.PwmSetting;
3032
import password.pwm.config.option.MessageSendMethod;
3133
import password.pwm.error.PwmUnrecoverableException;
34+
import password.pwm.i18n.Display;
35+
import password.pwm.i18n.PwmDisplayBundle;
3236
import password.pwm.ldap.UserInfo;
3337
import password.pwm.svc.token.TokenDestinationDisplayMasker;
38+
import password.pwm.util.i18n.LocaleHelper;
3439
import password.pwm.util.java.StringUtil;
3540
import password.pwm.util.secure.SecureService;
3641

@@ -41,6 +46,7 @@
4146
import java.util.HashMap;
4247
import java.util.LinkedHashMap;
4348
import java.util.List;
49+
import java.util.Locale;
4450
import java.util.Map;
4551
import java.util.Optional;
4652

@@ -72,21 +78,21 @@ public static Map<PwmSetting, Type> getSettingToDestTypeMap( )
7278
private String value;
7379
private Type type;
7480

81+
@Getter
7582
public enum Type
7683
{
77-
sms( MessageSendMethod.SMSONLY ),
78-
email( MessageSendMethod.EMAILONLY ),;
84+
sms( MessageSendMethod.SMSONLY, Display.Button_SMS, Display.Display_RecoverTokenSendChoiceEmail ),
85+
email( MessageSendMethod.EMAILONLY, Display.Button_Email, Display.Display_RecoverTokenSendChoiceSMS ),;
7986

8087
private MessageSendMethod messageSendMethod;
88+
private PwmDisplayBundle buttonLocalization;
89+
private PwmDisplayBundle displayLocalization;
8190

82-
Type( final MessageSendMethod messageSendMethod )
91+
Type( final MessageSendMethod messageSendMethod, final PwmDisplayBundle buttonLocalization, final PwmDisplayBundle displayLocalization )
8392
{
93+
this.buttonLocalization = buttonLocalization;
8494
this.messageSendMethod = messageSendMethod;
85-
}
86-
87-
public MessageSendMethod getMessageSendMethod( )
88-
{
89-
return messageSendMethod;
95+
this.displayLocalization = displayLocalization;
9096
}
9197
}
9298

@@ -109,7 +115,7 @@ public static List<TokenDestinationItem> allFromConfig(
109115
userInfo.getUserEmailAddress2(),
110116
userInfo.getUserEmailAddress3(),
111117
}
112-
)
118+
)
113119
{
114120
if ( !StringUtil.isEmpty( emailValue ) )
115121
{
@@ -130,7 +136,7 @@ public static List<TokenDestinationItem> allFromConfig(
130136
userInfo.getUserSmsNumber2(),
131137
userInfo.getUserSmsNumber3(),
132138
}
133-
)
139+
)
134140
{
135141
if ( !StringUtil.isEmpty( smsValue ) )
136142
{
@@ -186,4 +192,20 @@ public static List<TokenDestinationItem> stripValues( final List<TokenDestinatio
186192
}
187193
return returnList;
188194
}
195+
196+
public String longDisplay( final Locale locale, final Configuration configuration )
197+
{
198+
final Map<String, String> tokens = new HashMap<>();
199+
tokens.put( "%LABEL%", LocaleHelper.getLocalizedMessage( locale, getType().getButtonLocalization(), configuration ) );
200+
tokens.put( "%MESSAGE%", LocaleHelper.getLocalizedMessage( locale, getType().getDisplayLocalization(), configuration ) );
201+
tokens.put( "%VALUE%", this.getDisplay() );
202+
203+
String output = configuration.readAppProperty( AppProperty.REST_SERVER_FORGOTTEN_PW_TOKEN_DISPLAY );
204+
for ( final Map.Entry<String, String> entry : tokens.entrySet() )
205+
{
206+
output = output.replace( entry.getKey(), entry.getValue() );
207+
}
208+
209+
return output;
210+
}
189211
}

server/src/main/java/password/pwm/config/PwmSetting.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,17 +1189,16 @@ public enum PwmSetting
11891189

11901190
ENABLE_EXTERNAL_WEBSERVICES(
11911191
"external.webservices.enable", PwmSettingSyntax.BOOLEAN, PwmSettingCategory.REST_SERVER ),
1192-
ENABLE_WEBSERVICES_READANSWERS(
1193-
"webservices.enableReadAnswers", PwmSettingSyntax.BOOLEAN, PwmSettingCategory.REST_SERVER ),
1194-
PUBLIC_HEALTH_STATS_WEBSERVICES(
1195-
"webservices.healthStats.makePublic", PwmSettingSyntax.BOOLEAN, PwmSettingCategory.REST_SERVER ),
1192+
WEBSERVICES_PUBLIC_ENABLE(
1193+
"webservices.public.enable", PwmSettingSyntax.OPTIONLIST, PwmSettingCategory.REST_SERVER ),
11961194
WEBSERVICES_EXTERNAL_SECRET(
11971195
"webservices.external.secrets", PwmSettingSyntax.NAMED_SECRET, PwmSettingCategory.REST_SERVER ),
11981196
WEBSERVICES_QUERY_MATCH(
11991197
"webservices.queryMatch", PwmSettingSyntax.USER_PERMISSION, PwmSettingCategory.REST_SERVER ),
12001198
WEBSERVICES_THIRDPARTY_QUERY_MATCH(
12011199
"webservices.thirdParty.queryMatch", PwmSettingSyntax.USER_PERMISSION, PwmSettingCategory.REST_SERVER ),
1202-
1200+
ENABLE_WEBSERVICES_READANSWERS(
1201+
"webservices.enableReadAnswers", PwmSettingSyntax.BOOLEAN, PwmSettingCategory.REST_SERVER ),
12031202

12041203
EXTERNAL_MACROS_DEST_TOKEN_URLS(
12051204
"external.destToken.urls", PwmSettingSyntax.STRING, PwmSettingCategory.REST_CLIENT ),
@@ -1224,6 +1223,10 @@ public enum PwmSetting
12241223

12251224
// deprecated.
12261225

1226+
// deprecated 2019-06-01
1227+
PUBLIC_HEALTH_STATS_WEBSERVICES(
1228+
"webservices.healthStats.makePublic", PwmSettingSyntax.BOOLEAN, PwmSettingCategory.REST_SERVER ),
1229+
12271230
// deprecated 2019-01-20
12281231
PEOPLE_SEARCH_DISPLAY_NAME(
12291232
"peopleSearch.displayName.user", PwmSettingSyntax.STRING, PwmSettingCategory.PEOPLE_SEARCH ),

server/src/main/java/password/pwm/config/option/WebServiceUsage.java

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,47 @@
2222

2323
package password.pwm.config.option;
2424

25+
import password.pwm.ws.server.RestAuthenticationType;
26+
27+
import java.util.Arrays;
28+
import java.util.Collections;
29+
import java.util.HashSet;
30+
import java.util.Set;
31+
import java.util.stream.Collectors;
32+
2533
public enum WebServiceUsage
2634
{
27-
Challenges,
28-
CheckPassword,
29-
Health,
30-
Profile,
31-
RandomPassword,
32-
SetPassword,
33-
SigningForm,
34-
Statistics,
35-
Status,
36-
VerifyOtp,
37-
VerifyResponses,
35+
Challenges( RestAuthenticationType.NAMED_SECRET, RestAuthenticationType.LDAP ),
36+
CheckPassword( RestAuthenticationType.NAMED_SECRET, RestAuthenticationType.LDAP ),
37+
ForgottenPassword( RestAuthenticationType.PUBLIC ),
38+
Health( RestAuthenticationType.PUBLIC ),
39+
Profile( RestAuthenticationType.NAMED_SECRET, RestAuthenticationType.LDAP ),
40+
RandomPassword( RestAuthenticationType.PUBLIC, RestAuthenticationType.NAMED_SECRET, RestAuthenticationType.LDAP ),
41+
SetPassword( RestAuthenticationType.NAMED_SECRET, RestAuthenticationType.LDAP ),
42+
SigningForm( RestAuthenticationType.NAMED_SECRET ),
43+
Statistics( RestAuthenticationType.PUBLIC, RestAuthenticationType.NAMED_SECRET, RestAuthenticationType.LDAP ),
44+
Status( RestAuthenticationType.NAMED_SECRET, RestAuthenticationType.LDAP ),
45+
VerifyOtp( RestAuthenticationType.NAMED_SECRET, RestAuthenticationType.LDAP ),
46+
VerifyResponses( RestAuthenticationType.NAMED_SECRET, RestAuthenticationType.LDAP ),;
47+
48+
private Set<RestAuthenticationType> type;
49+
50+
WebServiceUsage( final RestAuthenticationType... type )
51+
{
52+
this.type = type == null ? Collections.emptySet() : Collections.unmodifiableSet( new HashSet<>( Arrays.asList( type ) ) );
53+
}
54+
55+
public Set<RestAuthenticationType> getTypes()
56+
{
57+
return type;
58+
}
59+
60+
public static Set<WebServiceUsage> forType( final RestAuthenticationType type )
61+
{
62+
return Collections.unmodifiableSet(
63+
Arrays.stream( WebServiceUsage.values() )
64+
.filter( webServiceUsage -> webServiceUsage.getTypes().contains( type ) )
65+
.collect( Collectors.toSet() )
66+
);
67+
}
3868
}

server/src/main/java/password/pwm/config/stored/ConfigurationCleaner.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import password.pwm.config.PwmSetting;
2828
import password.pwm.config.StoredValue;
2929
import password.pwm.config.option.ADPolicyComplexity;
30+
import password.pwm.config.option.WebServiceUsage;
31+
import password.pwm.config.value.OptionListValue;
3032
import password.pwm.config.value.StringArrayValue;
3133
import password.pwm.config.value.StringValue;
3234
import password.pwm.error.PwmUnrecoverableException;
@@ -36,7 +38,9 @@
3638

3739
import java.util.ArrayList;
3840
import java.util.Collections;
41+
import java.util.LinkedHashSet;
3942
import java.util.List;
43+
import java.util.Set;
4044

4145
class ConfigurationCleaner
4246
{
@@ -338,5 +342,18 @@ private void updateDeprecatedSettings( ) throws PwmUnrecoverableException
338342
storedConfiguration.resetSetting( PwmSetting.RECOVERY_ENFORCE_MINIMUM_PASSWORD_LIFETIME, profileID, actor );
339343
}
340344
}
345+
346+
if ( !storedConfiguration.isDefaultValue( PwmSetting.PUBLIC_HEALTH_STATS_WEBSERVICES ) )
347+
{
348+
LOGGER.warn( "converting deprecated non-default setting "
349+
+ PwmSetting.PUBLIC_HEALTH_STATS_WEBSERVICES.toMenuLocationDebug( null, PwmConstants.DEFAULT_LOCALE )
350+
+ " to replacement setting " + PwmSetting.WEBSERVICES_PUBLIC_ENABLE.toMenuLocationDebug( null, PwmConstants.DEFAULT_LOCALE ) );
351+
final Set<String> existingValues = (Set<String>) storedConfiguration.readSetting( PwmSetting.WEBSERVICES_PUBLIC_ENABLE ).toNativeObject();
352+
final Set<String> newValues = new LinkedHashSet<>( existingValues );
353+
newValues.add( WebServiceUsage.Health.name() );
354+
newValues.add( WebServiceUsage.Statistics.name() );
355+
storedConfiguration.writeSetting( PwmSetting.WEBSERVICES_PUBLIC_ENABLE, null, new OptionListValue( newValues ), actor );
356+
storedConfiguration.resetSetting( PwmSetting.PUBLIC_HEALTH_STATS_WEBSERVICES, null, actor );
357+
}
341358
}
342359
}

server/src/main/java/password/pwm/cr/CrChallengeItemBean.java

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,69 +22,46 @@
2222

2323
package password.pwm.cr;
2424

25+
import com.novell.ldapchai.cr.Challenge;
26+
import com.novell.ldapchai.cr.bean.ChallengeBean;
27+
import lombok.Builder;
28+
import lombok.Value;
29+
2530
import java.io.Serializable;
2631

27-
public class CrChallengeItemBean implements Serializable
32+
@Value
33+
@Builder
34+
public class CrChallengeItemBean implements Serializable, Challenge
2835
{
29-
public String challengeText;
30-
public int minLength;
31-
public int maxLength;
32-
public boolean adminDefined;
33-
public boolean required;
34-
public int maxQuestionCharsInAnswer;
35-
public boolean enforceWordlist;
36-
37-
public CrChallengeItemBean(
38-
final String challengeText,
39-
final int minLength,
40-
final int maxLength,
41-
final boolean adminDefined,
42-
final boolean required,
43-
final int maxQuestionCharsInAnswer,
44-
final boolean enforceWordlist
45-
)
46-
{
47-
this.challengeText = challengeText;
48-
this.minLength = minLength;
49-
this.maxLength = maxLength;
50-
this.adminDefined = adminDefined;
51-
this.required = required;
52-
this.maxQuestionCharsInAnswer = maxQuestionCharsInAnswer;
53-
this.enforceWordlist = enforceWordlist;
54-
}
55-
56-
public String getChallengeText( )
57-
{
58-
return challengeText;
59-
}
60-
61-
public int getMinLength( )
62-
{
63-
return minLength;
64-
}
36+
private String challengeText;
37+
private int minLength;
38+
private int maxLength;
39+
private boolean adminDefined;
40+
private boolean required;
41+
private int maxQuestionCharsInAnswer;
42+
private boolean enforceWordlist;
6543

66-
public int getMaxLength( )
44+
@Override
45+
public boolean isLocked()
6746
{
68-
return maxLength;
47+
return true;
6948
}
7049

71-
public boolean isAdminDefined( )
50+
@Override
51+
public void lock()
7252
{
73-
return adminDefined;
74-
}
7553

76-
public boolean isRequired( )
77-
{
78-
return required;
7954
}
8055

81-
public int getMaxQuestionCharsInAnswer( )
56+
@Override
57+
public void setChallengeText( final String challengeText )
8258
{
83-
return maxQuestionCharsInAnswer;
59+
throw new IllegalStateException();
8460
}
8561

86-
public boolean isEnforceWordlist( )
62+
@Override
63+
public ChallengeBean asChallengeBean()
8764
{
88-
return enforceWordlist;
65+
throw new IllegalStateException();
8966
}
9067
}

0 commit comments

Comments
 (0)