Redirect to next required action if there are multiple actions

This commit is contained in:
Stian Thorgersen 2013-09-21 12:51:33 +01:00
parent b541679ef3
commit eaeed0b9dd

View file

@ -116,7 +116,7 @@ public class AccountService {
accessCodeEntry.getRequiredActions().remove(UserModel.RequiredAction.UPDATE_PROFILE); accessCodeEntry.getRequiredActions().remove(UserModel.RequiredAction.UPDATE_PROFILE);
} }
Response response = redirectOauth(accessCodeEntry); Response response = redirectOauth(user, accessCodeEntry);
if (response != null) { if (response != null) {
return response; return response;
} else { } else {
@ -161,8 +161,7 @@ public class AccountService {
return null; return null;
} }
if (accessCodeEntry.getRequiredActions() == null if (accessCodeEntry.getRequiredActions() == null || !accessCodeEntry.getRequiredActions().contains(requiredAction)) {
|| !accessCodeEntry.getRequiredActions().contains(requiredAction)) {
return null; return null;
} }
@ -208,7 +207,7 @@ public class AccountService {
user.setTotp(true); user.setTotp(true);
Response response = redirectOauth(accessCodeEntry); Response response = redirectOauth(user, accessCodeEntry);
if (response != null) { if (response != null) {
return response; return response;
} else { } else {
@ -231,7 +230,7 @@ public class AccountService {
accessCodeEntry.getRequiredActions().remove(UserModel.RequiredAction.VERIFY_EMAIL); accessCodeEntry.getRequiredActions().remove(UserModel.RequiredAction.VERIFY_EMAIL);
} }
Response response = redirectOauth(accessCodeEntry); Response response = redirectOauth(user, accessCodeEntry);
if (response != null) { if (response != null) {
return response; return response;
} else { } else {
@ -239,19 +238,26 @@ public class AccountService {
} }
} }
private Response redirectOauth(AccessCodeEntry accessCodeEntry) { private Response redirectOauth(UserModel user, AccessCodeEntry accessCode) {
if (accessCodeEntry == null) { if (accessCode == null) {
return null; return null;
} }
Set<RequiredAction> requiredActions = user.getRequiredActions();
if (!requiredActions.isEmpty()) {
return Flows.forms(realm, request, uriInfo).setCode(accessCode.getCode()).setUser(user)
.forwardToAction(requiredActions.iterator().next());
} else {
String redirect = uriInfo.getQueryParameters().getFirst("redirect_uri"); String redirect = uriInfo.getQueryParameters().getFirst("redirect_uri");
if (redirect != null) { if (redirect != null) {
String state = uriInfo.getQueryParameters().getFirst("state"); String state = uriInfo.getQueryParameters().getFirst("state");
return Flows.oauth(realm, request, uriInfo, authManager, tokenManager).redirectAccessCode(accessCodeEntry, state, return Flows.oauth(realm, request, uriInfo, authManager, tokenManager).redirectAccessCode(accessCode, state,
redirect); redirect);
} else { } else {
return null; return null;
} }
} }
}
@Path("password") @Path("password")
@POST @POST