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

Introduce new Identity Context to the carbon core #6325

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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.
*/

package org.wso2.carbon.identity.core.context;

import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.identity.core.context.model.Flow;
import org.wso2.carbon.identity.core.context.model.Initiator;
import org.wso2.carbon.identity.core.internal.IdentityContextDataHolder;

/**
* This class is used to store the identity context information of the current thread.
*/
public class IdentityContext extends CarbonContext {

private final IdentityContextDataHolder identityContextDataHolder;

/**
* Creates a IdentityContext using the given IdentityContext data holder as its backing instance.
*
* @param identityContextDataHolder the IdentityContext data holder that backs this CarbonContext object.
*/
protected IdentityContext(IdentityContextDataHolder identityContextDataHolder) {

super();
this.identityContextDataHolder = identityContextDataHolder;
}

public static IdentityContext getThreadLocalIdentityContext() {

return new IdentityContext(IdentityContextDataHolder.getThreadLocalIdentityContextHolder());
}

/**
* Set the flow of the request.
*
* @param flow flow of the request.
*/
public void setFlow(Flow flow) {

identityContextDataHolder.setFlow(flow);
}

/**
* Get the flow id of the request.
*
* @return Flow of the request.
*/
public Flow getFlow() {

return identityContextDataHolder.getFlow();
}

/**
* Set the initiator of the request.
*
* @param initiator initiator of the request.
*/
public void setInitiator(Initiator initiator) {

identityContextDataHolder.setInitiator(initiator);
}

/**
* Get the initiator of the request.
*
* @return Initiator of the request.
*/
public Initiator getInitiator() {

return identityContextDataHolder.getInitiator();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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.
*/

package org.wso2.carbon.identity.core.context.model;

/**
* Entity class for Application.
* This class holds the application entity details for a given flow.
*/
public class ApplicationEntity implements InitiatingEntity {

private final String applicationId;
private final String applicationName;
private final String clientId;
private final String issuer;
ashanthamara marked this conversation as resolved.
Show resolved Hide resolved
private final String realm;
ashanthamara marked this conversation as resolved.
Show resolved Hide resolved

private ApplicationEntity(Builder builder) {

this.applicationId = builder.applicationId;
this.applicationName = builder.applicationName;
this.clientId = builder.clientId;
this.issuer = builder.issuer;
this.realm = builder.realm;
}

public String getApplicationId() {

return applicationId;
}

public String getApplicationName() {

return applicationName;
}

public String getClientId() {

return clientId;
}

public String getIssuer() {

return issuer;
}

public String getRealm() {

return realm;
}

/**
* Builder for the ApplicationEntity.
*/
public static class Builder {

private String applicationId;
private String applicationName;
private String clientId;
private String issuer;
private String realm;

public Builder() {

}

public Builder(ApplicationEntity applicationEntity) {

this.applicationId = applicationEntity.applicationId;
this.applicationName = applicationEntity.applicationName;
this.clientId = applicationEntity.clientId;
this.issuer = applicationEntity.issuer;
this.realm = applicationEntity.realm;
}

public Builder applicationId(String applicationId) {

this.applicationId = applicationId;
return this;
}

public Builder applicationName(String applicationName) {

this.applicationName = applicationName;
return this;
}

public Builder clientId(String clientId) {

if (issuer != null && realm != null) {
throw new IllegalStateException("Cannot set both clientId and issuer/realm at the same time.");
}
this.clientId = clientId;
return this;
}

public Builder issuer(String issuer) {

if (clientId != null && realm != null) {
throw new IllegalStateException("Cannot set both issuer and clientId/realm at the same time.");
}
this.issuer = issuer;
return this;
}

public Builder realm(String realm) {

if (clientId != null && issuer != null) {
throw new IllegalStateException("Cannot set both realm and clientId/issuer at the same time.");
}
this.realm = realm;
return this;
}

public ApplicationEntity build() {

return new ApplicationEntity(this);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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.
*/

package org.wso2.carbon.identity.core.context.model;

import java.util.EnumSet;

/**
* Enum for flows.
* This enum holds the flow type and the action that is being executed.
*/
public class Flow {

/**
* Enum for types.
*/
public enum Type {

PASSWORD_RECOVERY(EnumSet.of(Action.INVITE, Action.UPDATE, Action.RESET));
ashanthamara marked this conversation as resolved.
Show resolved Hide resolved

private final EnumSet<Action> states;

Type(EnumSet<Action> states) {
this.states = states;
}

public boolean isValidAction(Action action) {
return states.contains(action);
}

public EnumSet<Action> getActions() {
return states;
}
}

/**
* Enum for actions.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better expain this initiating persona bit more

public enum Action {
INVITE,
UPDATE,
RESET
}

private final Type type;
private final Action action;

public Flow(Type type, Action action) {

if (type.isValidAction(action)) {
this.type = type;
this.action = action;
return;
}
throw new IllegalArgumentException("Invalid action or the flow type provided.");
}

public Type getType() {
return type;
}

public Action getAction() {
return action;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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.
*/

package org.wso2.carbon.identity.core.context.model;

/**
* Interface for Initiating Entity.
* This interface is implemented by the entities that initiate a flow.
*/
public interface InitiatingEntity {

}
Loading
Loading