Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate Identity Context in password update flow #597

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.wso2.carbon.identity.scim2.provider.resources;


import org.wso2.carbon.identity.core.context.model.Flow;
import org.wso2.carbon.identity.core.context.IdentityContext;
import org.wso2.carbon.identity.jaxrs.designator.PATCH;
import org.wso2.carbon.identity.scim2.common.impl.IdentitySCIMManager;
import org.wso2.carbon.identity.scim2.provider.util.SCIMProviderConstants;
Expand Down Expand Up @@ -155,6 +157,7 @@ public Response updateUser(@HeaderParam(SCIMProviderConstants.CONTENT_TYPE) Stri
@QueryParam (SCIMProviderConstants.EXCLUDE_ATTRIBUTES) String excludedAttributes,
String resourceString) {

updateIdentityContext();
String userId = SupportUtils.getAuthenticatedUserId();
try {
// content-type header is compulsory in post request.
Expand Down Expand Up @@ -201,6 +204,7 @@ public Response patchUser(@HeaderParam(SCIMProviderConstants.CONTENT_TYPE) Strin
@QueryParam (SCIMProviderConstants.EXCLUDE_ATTRIBUTES) String excludedAttributes,
String resourceString) {

updateIdentityContext();
String userId = SupportUtils.getAuthenticatedUserId();
try {
// content-type header is compulsory in post request.
Expand Down Expand Up @@ -239,4 +243,17 @@ public Response patchUser(@HeaderParam(SCIMProviderConstants.CONTENT_TYPE) Strin
return handleFormatNotSupportedException(e);
}
}

/**
* This is used to set the flow and initiator in the identity context.
* These values will be used in the pre update password action.
*/
private void updateIdentityContext() {

Flow flow = new Flow.Builder()
.name(Flow.Name.PASSWORD_UPDATE)
.initiatingPersona(Flow.InitiatingPersona.USER)
.build();
IdentityContext.getThreadLocalIdentityContext().setFlow(flow);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.core.context.model.Flow;
import org.wso2.carbon.identity.core.context.IdentityContext;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.jaxrs.designator.PATCH;
import org.wso2.carbon.identity.recovery.IdentityRecoveryConstants;
Expand Down Expand Up @@ -282,6 +284,7 @@ public Response updateUser(@PathParam(SCIMConstants.CommonSchemaConstants.ID) St
String resourceString) {

try {
updateIdentityContext();
// content-type header is compulsory in post request.
if (inputFormat == null) {
String error = SCIMProviderConstants.CONTENT_TYPE
Expand Down Expand Up @@ -331,6 +334,7 @@ public Response patchUser(@PathParam(SCIMConstants.CommonSchemaConstants.ID) Str


try {
updateIdentityContext();
// content-type header is compulsory in post request.
if (inputFormat == null) {
String error = SCIMProviderConstants.CONTENT_TYPE
Expand Down Expand Up @@ -420,4 +424,26 @@ private int validateCountParameter(Integer count) {

return count;
}

/**
* This is used to set the flow and initiator in the identity context.
* These values will be used in the pre update password action.
*/
private void updateIdentityContext() {

if (IdentityContext.getThreadLocalIdentityContext().isUserActor()) {
Flow flow = new Flow.Builder()
.name(Flow.Name.PASSWORD_UPDATE)
.initiatingPersona(Flow.InitiatingPersona.ADMIN)
.build();
IdentityContext.getThreadLocalIdentityContext().setFlow(flow);
}
if (IdentityContext.getThreadLocalIdentityContext().isApplicationActor()) {
Flow flow = new Flow.Builder()
.name(Flow.Name.PASSWORD_UPDATE)
.initiatingPersona(Flow.InitiatingPersona.APPLICATION)
.build();
IdentityContext.getThreadLocalIdentityContext().setFlow(flow);
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
<inbound.auth.oauth.version>6.5.3</inbound.auth.oauth.version>
<commons-collections.version>3.2.0.wso2v1</commons-collections.version>
<carbon.kernel.version>4.10.24</carbon.kernel.version>
<identity.framework.version>7.7.96</identity.framework.version>
<identity.framework.version>7.7.138</identity.framework.version>
<junit.version>4.13.1</junit.version>
<commons.lang.version>20030203.000129</commons.lang.version>
<identity.governance.version>1.8.12</identity.governance.version>
Expand Down
Loading