Browse Source

new user redirect url

Jason Rivard 8 years ago
parent
commit
c8d86de43b

+ 2 - 1
src/main/java/password/pwm/config/PwmSetting.java

@@ -796,7 +796,8 @@ public enum PwmSetting {
             "newUser.minimumWaitTime", PwmSettingSyntax.DURATION, PwmSettingCategory.NEWUSER_PROFILE),
             "newUser.minimumWaitTime", PwmSettingSyntax.DURATION, PwmSettingCategory.NEWUSER_PROFILE),
     NEWUSER_PROFILE_DISPLAY_NAME(
     NEWUSER_PROFILE_DISPLAY_NAME(
             "newUser.profile.displayName", PwmSettingSyntax.LOCALIZED_STRING, PwmSettingCategory.NEWUSER_PROFILE),
             "newUser.profile.displayName", PwmSettingSyntax.LOCALIZED_STRING, PwmSettingCategory.NEWUSER_PROFILE),
-
+    NEWUSER_REDIRECT_URL(
+            "newUser.redirectUrl", PwmSettingSyntax.STRING, PwmSettingCategory.NEWUSER_PROFILE),
 
 
     // guest settings
     // guest settings
     GUEST_ENABLE(
     GUEST_ENABLE(

+ 14 - 83
src/main/java/password/pwm/http/bean/NewUserBean.java

@@ -22,59 +22,42 @@
 
 
 package password.pwm.http.bean;
 package password.pwm.http.bean;
 
 
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
 import password.pwm.bean.TokenVerificationProgress;
 import password.pwm.bean.TokenVerificationProgress;
 import password.pwm.config.option.SessionBeanMode;
 import password.pwm.config.option.SessionBeanMode;
 import password.pwm.error.PwmUnrecoverableException;
 import password.pwm.error.PwmUnrecoverableException;
 import password.pwm.util.PasswordData;
 import password.pwm.util.PasswordData;
 
 
 import java.io.Serializable;
 import java.io.Serializable;
+import java.time.Instant;
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Collections;
-import java.util.Date;
 import java.util.HashSet;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Map;
 import java.util.Set;
 import java.util.Set;
 
 
+@Getter
+@Setter
+@NoArgsConstructor
 public class NewUserBean extends PwmSessionBean {
 public class NewUserBean extends PwmSessionBean {
     private String profileID;
     private String profileID;
     private NewUserForm newUserForm;
     private NewUserForm newUserForm;
 
 
     private boolean agreementPassed;
     private boolean agreementPassed;
     private boolean formPassed;
     private boolean formPassed;
-    private Date createStartTime;
+    private Instant createStartTime;
     private boolean urlSpecifiedProfile;
     private boolean urlSpecifiedProfile;
     private final TokenVerificationProgress tokenVerificationProgress = new TokenVerificationProgress();
     private final TokenVerificationProgress tokenVerificationProgress = new TokenVerificationProgress();
 
 
+    @Getter
+    @AllArgsConstructor
     public static class NewUserForm implements Serializable {
     public static class NewUserForm implements Serializable {
-        private Map<String,String> formData;
-        private PasswordData newUserPassword;
-        private PasswordData confirmPassword;
-
-        public NewUserForm(
-                final Map<String, String> formData,
-                final PasswordData newUserPassword,
-                final PasswordData confirmPassword
-        )
-        {
-            this.formData = formData;
-            this.newUserPassword = newUserPassword;
-            this.confirmPassword = confirmPassword;
-        }
-
-        public Map<String, String> getFormData()
-        {
-            return formData;
-        }
-
-        public PasswordData getNewUserPassword()
-        {
-            return newUserPassword;
-        }
-
-        public PasswordData getConfirmPassword()
-        {
-            return confirmPassword;
-        }
+        private final Map<String,String> formData;
+        private final PasswordData newUserPassword;
+        private final PasswordData confirmPassword;
 
 
         public boolean isConsistentWith(final NewUserForm otherForm) throws PwmUnrecoverableException {
         public boolean isConsistentWith(final NewUserForm otherForm) throws PwmUnrecoverableException {
             if (otherForm == null) {
             if (otherForm == null) {
@@ -101,58 +84,6 @@ public class NewUserBean extends PwmSessionBean {
         }
         }
     }
     }
 
 
-    public String getProfileID() {
-        return profileID;
-    }
-
-    public void setProfileID(final String profileID) {
-        this.profileID = profileID;
-    }
-
-    public boolean isAgreementPassed() {
-        return agreementPassed;
-    }
-
-    public void setAgreementPassed(final boolean agreementPassed) {
-        this.agreementPassed = agreementPassed;
-    }
-
-    public boolean isFormPassed() {
-        return formPassed;
-    }
-
-    public void setFormPassed(final boolean formPassed) {
-        this.formPassed = formPassed;
-    }
-
-    public Date getCreateStartTime()
-    {
-        return createStartTime;
-    }
-
-    public void setCreateStartTime(final Date createStartTime)
-    {
-        this.createStartTime = createStartTime;
-    }
-
-    public NewUserForm getNewUserForm()
-    {
-        return newUserForm;
-    }
-
-    public void setNewUserForm(final NewUserForm newUserForm)
-    {
-        this.newUserForm = newUserForm;
-    }
-
-    public boolean isUrlSpecifiedProfile() {
-        return urlSpecifiedProfile;
-    }
-
-    public void setUrlSpecifiedProfile(final boolean urlSpecifiedProfile) {
-        this.urlSpecifiedProfile = urlSpecifiedProfile;
-    }
-
     public Type getType() {
     public Type getType() {
         return Type.PUBLIC;
         return Type.PUBLIC;
     }
     }

+ 19 - 8
src/main/java/password/pwm/http/servlet/newuser/NewUserServlet.java

@@ -53,6 +53,7 @@ import password.pwm.svc.token.TokenPayload;
 import password.pwm.util.CaptchaUtility;
 import password.pwm.util.CaptchaUtility;
 import password.pwm.util.java.JsonUtil;
 import password.pwm.util.java.JsonUtil;
 import password.pwm.util.java.Percent;
 import password.pwm.util.java.Percent;
+import password.pwm.util.java.StringUtil;
 import password.pwm.util.java.TimeDuration;
 import password.pwm.util.java.TimeDuration;
 import password.pwm.util.logging.PwmLogger;
 import password.pwm.util.logging.PwmLogger;
 import password.pwm.util.macro.MacroMachine;
 import password.pwm.util.macro.MacroMachine;
@@ -64,10 +65,10 @@ import javax.servlet.ServletException;
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.annotation.WebServlet;
 import java.io.IOException;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.time.Instant;
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Collections;
-import java.util.Date;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Locale;
 import java.util.Locale;
@@ -248,7 +249,7 @@ public class NewUserServlet extends ControlledPwmServlet {
 
 
         try {
         try {
             NewUserUtils.createUser(newUserBean.getNewUserForm(), pwmRequest, newUserDN);
             NewUserUtils.createUser(newUserBean.getNewUserForm(), pwmRequest, newUserDN);
-            newUserBean.setCreateStartTime(new Date());
+            newUserBean.setCreateStartTime(Instant.now());
             pwmRequest.forwardToJsp(JspUrl.NEW_USER_WAIT);
             pwmRequest.forwardToJsp(JspUrl.NEW_USER_WAIT);
         } catch (PwmOperationalException e) {
         } catch (PwmOperationalException e) {
             LOGGER.error(pwmRequest, "error during user creation: " + e.getMessage());
             LOGGER.error(pwmRequest, "error during user creation: " + e.getMessage());
@@ -489,7 +490,7 @@ public class NewUserServlet extends ControlledPwmServlet {
             throws IOException, ServletException, PwmUnrecoverableException
             throws IOException, ServletException, PwmUnrecoverableException
     {
     {
         final NewUserBean newUserBean = getNewUserBean(pwmRequest);
         final NewUserBean newUserBean = getNewUserBean(pwmRequest);
-        final Date startTime = newUserBean.getCreateStartTime();
+        final Instant startTime = newUserBean.getCreateStartTime();
         if (startTime == null) {
         if (startTime == null) {
             pwmRequest.respondWithError(PwmError.ERROR_INCORRECT_REQ_SEQUENCE.toInfo(), true);
             pwmRequest.respondWithError(PwmError.ERROR_INCORRECT_REQ_SEQUENCE.toInfo(), true);
             return ProcessStatus.Halt;
             return ProcessStatus.Halt;
@@ -497,13 +498,13 @@ public class NewUserServlet extends ControlledPwmServlet {
 
 
         final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
         final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
         final long minWaitTime = newUserProfile.readSettingAsLong(PwmSetting.NEWUSER_MINIMUM_WAIT_TIME) * 1000L;
         final long minWaitTime = newUserProfile.readSettingAsLong(PwmSetting.NEWUSER_MINIMUM_WAIT_TIME) * 1000L;
-        final Date completeTime = new Date(startTime.getTime() + minWaitTime);
+        final Instant completeTime = Instant.ofEpochMilli(startTime.toEpochMilli() + minWaitTime);
 
 
         final BigDecimal percentComplete;
         final BigDecimal percentComplete;
         final boolean complete;
         final boolean complete;
 
 
         // be sure minimum wait time has passed
         // be sure minimum wait time has passed
-        if (new Date().after(completeTime)) {
+        if (Instant.now().isAfter(completeTime)) {
             percentComplete = new BigDecimal("100");
             percentComplete = new BigDecimal("100");
             complete = true;
             complete = true;
         } else {
         } else {
@@ -557,7 +558,7 @@ public class NewUserServlet extends ControlledPwmServlet {
             throws ServletException, IOException, PwmUnrecoverableException, ChaiUnavailableException
             throws ServletException, IOException, PwmUnrecoverableException, ChaiUnavailableException
     {
     {
         final NewUserBean newUserBean = getNewUserBean(pwmRequest);
         final NewUserBean newUserBean = getNewUserBean(pwmRequest);
-        final Date startTime = newUserBean.getCreateStartTime();
+        final Instant startTime = newUserBean.getCreateStartTime();
         if (startTime == null) {
         if (startTime == null) {
             pwmRequest.respondWithError(PwmError.ERROR_INCORRECT_REQ_SEQUENCE.toInfo(), true);
             pwmRequest.respondWithError(PwmError.ERROR_INCORRECT_REQ_SEQUENCE.toInfo(), true);
             return ProcessStatus.Halt;
             return ProcessStatus.Halt;
@@ -565,15 +566,25 @@ public class NewUserServlet extends ControlledPwmServlet {
 
 
         final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
         final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
         final long minWaitTime = newUserProfile.readSettingAsLong(PwmSetting.NEWUSER_MINIMUM_WAIT_TIME) * 1000L;
         final long minWaitTime = newUserProfile.readSettingAsLong(PwmSetting.NEWUSER_MINIMUM_WAIT_TIME) * 1000L;
-        final Date completeTime = new Date(startTime.getTime() + minWaitTime);
+        final Instant completeTime = Instant.ofEpochMilli(startTime.toEpochMilli() + minWaitTime);
 
 
         // be sure minimum wait time has passed
         // be sure minimum wait time has passed
-        if (new Date().before(completeTime)) {
+        if (Instant.now().isBefore(completeTime)) {
             pwmRequest.forwardToJsp(JspUrl.NEW_USER_WAIT);
             pwmRequest.forwardToJsp(JspUrl.NEW_USER_WAIT);
             return ProcessStatus.Halt;
             return ProcessStatus.Halt;
         }
         }
 
 
+        // -- process complete -- \\
         pwmRequest.getPwmApplication().getSessionStateService().clearBean(pwmRequest, NewUserBean.class);
         pwmRequest.getPwmApplication().getSessionStateService().clearBean(pwmRequest, NewUserBean.class);
+
+        final String configuredRedirectUrl = newUserProfile.readSettingAsString(PwmSetting.NEWUSER_REDIRECT_URL);
+        if (!StringUtil.isEmpty(configuredRedirectUrl)) {
+            final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
+            final String macroedUrl = macroMachine.expandMacros(configuredRedirectUrl);
+            pwmRequest.sendRedirect(macroedUrl);
+            return ProcessStatus.Halt;
+        }
+
         pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_CreateUser);
         pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_CreateUser);
         return ProcessStatus.Halt;
         return ProcessStatus.Halt;
     }
     }

+ 18 - 3
src/main/java/password/pwm/ldap/UserInfoBean.java

@@ -22,6 +22,7 @@
 
 
 package password.pwm.ldap;
 package password.pwm.ldap;
 
 
+import com.novell.ldapchai.impl.edir.entry.EdirEntries;
 import lombok.Builder;
 import lombok.Builder;
 import lombok.Getter;
 import lombok.Getter;
 import password.pwm.bean.PasswordStatus;
 import password.pwm.bean.PasswordStatus;
@@ -38,6 +39,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Collections;
 import java.util.Date;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -90,25 +92,38 @@ public class UserInfoBean implements UserInfo {
     @Override
     @Override
     public String readStringAttribute(final String attribute) throws PwmUnrecoverableException
     public String readStringAttribute(final String attribute) throws PwmUnrecoverableException
     {
     {
-        return null;
+        return attributes.get(attribute);
     }
     }
 
 
     @Override
     @Override
     public Date readDateAttribute(final String attribute) throws PwmUnrecoverableException
     public Date readDateAttribute(final String attribute) throws PwmUnrecoverableException
     {
     {
+        if (attributes.containsKey(attribute)) {
+            return EdirEntries.convertZuluToDate(attributes.get(attribute));
+        }
         return null;
         return null;
     }
     }
 
 
     @Override
     @Override
     public List<String> readMultiStringAttribute(final String attribute) throws PwmUnrecoverableException
     public List<String> readMultiStringAttribute(final String attribute) throws PwmUnrecoverableException
     {
     {
-        return null;
+        if (attributes.containsKey(attribute)) {
+            return Collections.unmodifiableList(Collections.singletonList(attributes.get(attribute)));
+        }
+
+        return Collections.emptyList();
     }
     }
 
 
     @Override
     @Override
     public Map<String, String> readStringAttributes(final Collection<String> attributes) throws PwmUnrecoverableException
     public Map<String, String> readStringAttributes(final Collection<String> attributes) throws PwmUnrecoverableException
     {
     {
-        return null;
+        final Map<String,String> returnObj = new LinkedHashMap<>();
+        for (final String attribute : attributes) {
+            if (this.attributes.containsKey(attribute)) {
+                returnObj.put(attribute, this.attributes.get(attribute));
+            }
+        }
+        return Collections.unmodifiableMap(returnObj);
     }
     }
 }
 }
 
 

+ 3 - 1
src/main/java/password/pwm/svc/token/TokenPayload.java

@@ -60,7 +60,9 @@ public class TokenPayload implements Serializable {
         final Map<String,String> debugMap = new HashMap<>();
         final Map<String,String> debugMap = new HashMap<>();
         debugMap.put("date", JavaHelper.toIsoDate(date));
         debugMap.put("date", JavaHelper.toIsoDate(date));
         debugMap.put("name", getName());
         debugMap.put("name", getName());
-        debugMap.put("user", getUserIdentity().toDisplayString());
+        if (getUserIdentity() != null) {
+            debugMap.put("user", getUserIdentity().toDisplayString());
+        }
         debugMap.put("guid", getGuid());
         debugMap.put("guid", getGuid());
         return JsonUtil.serializeMap(debugMap);
         return JsonUtil.serializeMap(debugMap);
     }
     }

+ 5 - 0
src/main/resources/password/pwm/config/PwmSetting.xml

@@ -2592,6 +2592,11 @@
             <value></value>
             <value></value>
         </default>
         </default>
     </setting>
     </setting>
+    <setting hidden="false" key="newUser.redirectUrl" level="1">
+        <default>
+            <value></value>
+        </default>
+    </setting>
     <setting hidden="false" key="guest.enable" level="1" required="true">
     <setting hidden="false" key="guest.enable" level="1" required="true">
         <default>
         <default>
             <value>false</value>
             <value>false</value>

+ 2 - 0
src/main/resources/password/pwm/i18n/PwmSetting.properties

@@ -470,6 +470,7 @@ Setting_Description_newUser.minimumWaitTime=Specify a delay time during a new us
 Setting_Description_newUser.passwordPolicy.user=Specify the user @PwmAppName@ uses a template for the new user password policy. If the value is <i>TESTUSER</i>, @PwmAppName@ uses the configured test user's password policy.
 Setting_Description_newUser.passwordPolicy.user=Specify the user @PwmAppName@ uses a template for the new user password policy. If the value is <i>TESTUSER</i>, @PwmAppName@ uses the configured test user's password policy.
 Setting_Description_newUser.profile.displayName=Specify the publicly viewable display name of this profile.
 Setting_Description_newUser.profile.displayName=Specify the publicly viewable display name of this profile.
 Setting_Description_newUser.profile.list=List of New User profiles. When you configure multiple new user profiles, the user can select which profile to complete.  @PwmAppName@ shows the profile name to the users as the value of the setting <code>@PwmSettingReference\:newUser.profile.displayName@</code>.
 Setting_Description_newUser.profile.list=List of New User profiles. When you configure multiple new user profiles, the user can select which profile to complete.  @PwmAppName@ shows the profile name to the users as the value of the setting <code>@PwmSettingReference\:newUser.profile.displayName@</code>.
+Setting_Description_newUser.redirectUrl=URL to redirect user to after new user registration process is completed.
 Setting_Description_newUser.sms.verification=Enable this option to have @PwmAppName@ send an SMS to the new user's mobile phone number before it creates the account. The NewUser must verify receipt of the SMS before @PwmAppName@ creates the account.
 Setting_Description_newUser.sms.verification=Enable this option to have @PwmAppName@ send an SMS to the new user's mobile phone number before it creates the account. The NewUser must verify receipt of the SMS before @PwmAppName@ creates the account.
 Setting_Description_newUser.username.definition=<p>Specify the entry ID of the newly created LDAP entry. In some directories this is often used as the "user name", though many directories separate the concepts and values of entry ID and user name.</p><br/><br/><p>Values can (and usually do) include macros.  In case the first value already exists in the directory, @PwmAppName@ tries each successive value until it finds a free value.  Though @PwmAppName@ has not yet created the user when it evaluates the macros, the LDAP macros use the data provided on the new user form.  Other macros might not be useful as there no data yet available on the user.</p><br/><br/><p>If blank, the user name must be present in the form, defined as the LDAP naming attribute value.</p>
 Setting_Description_newUser.username.definition=<p>Specify the entry ID of the newly created LDAP entry. In some directories this is often used as the "user name", though many directories separate the concepts and values of entry ID and user name.</p><br/><br/><p>Values can (and usually do) include macros.  In case the first value already exists in the directory, @PwmAppName@ tries each successive value until it finds a free value.  Though @PwmAppName@ has not yet created the user when it evaluates the macros, the LDAP macros use the data provided on the new user form.  Other macros might not be useful as there no data yet available on the user.</p><br/><br/><p>If blank, the user name must be present in the form, defined as the LDAP naming attribute value.</p>
 Setting_Description_newUser.writeAttributes=Specify the actions the system takes when it creates a user.  The actions will be executed just after the user is created in the LDAP directory.    You can use macros in this setting.
 Setting_Description_newUser.writeAttributes=Specify the actions the system takes when it creates a user.  The actions will be executed just after the user is created in the LDAP directory.    You can use macros in this setting.
@@ -941,6 +942,7 @@ Setting_Label_newUser.minimumWaitTime=New User Minimum Wait Time
 Setting_Label_newUser.passwordPolicy.user=Password Policy Template
 Setting_Label_newUser.passwordPolicy.user=Password Policy Template
 Setting_Label_newUser.profile.displayName=Profile Display Name
 Setting_Label_newUser.profile.displayName=Profile Display Name
 Setting_Label_newUser.profile.list=New User Profile
 Setting_Label_newUser.profile.list=New User Profile
+Setting_Label_newUser.redirectUrl=After Registration Redirect URL
 Setting_Label_newUser.sms.verification=Enable New User SMS Verification
 Setting_Label_newUser.sms.verification=Enable New User SMS Verification
 Setting_Label_newUser.username.definition=LDAP Entry ID Definition
 Setting_Label_newUser.username.definition=LDAP Entry ID Definition
 Setting_Label_newUser.writeAttributes=New User Actions
 Setting_Label_newUser.writeAttributes=New User Actions