Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…inbound-auth-oauth into migrationIssue
  • Loading branch information
gershom96 committed Jul 26, 2023
2 parents 780e68e + 7797cdf commit afacda4
Show file tree
Hide file tree
Showing 62 changed files with 679 additions and 284 deletions.
4 changes: 2 additions & 2 deletions components/org.wso2.carbon.identity.api.server.dcr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<version>6.11.81-SNAPSHOT</version>
<version>6.11.90-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.api.server.dcr</artifactId>
<version>6.11.81-SNAPSHOT</version>
<version>6.11.90-SNAPSHOT</version>
<name>WSO2 Carbon - User DCR Rest API</name>
<description>WSO2 Carbon - User DCR Rest API</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ paths:
"grant_types": ["password"],
"ext_param_client_id":"provided_client_id0001",
"ext_param_client_secret":"provided_client_secret0001" }'
"https://localhost:9443/api/identity/oauth2/dcr/v1.0/register"
"https://localhost:9443/api/identity/oauth2/dcr/v1.1/register"
x-wso2-response: |
"HTTP/1.1 201 Created"
{"client_name”:"application_test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<version>6.11.81-SNAPSHOT</version>
<version>6.11.90-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.api.server.oauth.scope</artifactId>
<version>6.11.81-SNAPSHOT</version>
<version>6.11.90-SNAPSHOT</version>

<name>WSO2 Carbon - Identity OAuth 2.0 Scope Rest APIs</name>
<description>Rest APIs for OAuth 2.0 Scope Handling</description>
Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.discovery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>6.11.81-SNAPSHOT</version>
<version>6.11.90-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
3 changes: 1 addition & 2 deletions components/org.wso2.carbon.identity.oauth.ciba/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>identity-inbound-auth-oauth</artifactId>
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<version>6.11.81-SNAPSHOT</version>
<version>6.11.90-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -135,7 +135,6 @@
="${identity.inbound.auth.oauth.imp.pkg.version.range}",
org.wso2.carbon.identity.oauth.* ; version
="${identity.inbound.auth.oauth.imp.pkg.version.range}",
org.wso2.carbon.registry.core.* ; version ="${carbon.kernel.imp.pkg.version.range}",
org.wso2.carbon.user.core.* ; version ="${carbon.kernel.imp.pkg.version.range}",
org.wso2.carbon.user.api.* ; version ="${carbon.user.api.imp.pkg.version.range}",
org.wso2.carbon.identity.base.* ; version =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>6.11.81-SNAPSHOT</version>
<version>6.11.90-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.oauth.common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>6.11.81-SNAPSHOT</version>
<version>6.11.90-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public final class OAuthConstants {
public static final String OAUTH_PKCE_CODE_CHALLENGE_METHOD = "code_challenge_method";
public static final String OAUTH_PKCE_S256_CHALLENGE = "S256";
public static final String OAUTH_PKCE_PLAIN_CHALLENGE = "plain";
//OAuth PKCE request attribute
public static final String PKCE_UNSUPPORTED_FLOW = "pkce_unsupported_flow";
//Response types
public static final String NONE = "none";
public static final String TOKEN = "token";
Expand Down Expand Up @@ -182,6 +184,7 @@ public final class OAuthConstants {
public static final String RENEW_TOKEN_WITHOUT_REVOKING_EXISTING_ENABLE_CONFIG =
"OAuth.JWT.RenewTokenWithoutRevokingExisting.Enable";
public static final String REQUEST_BINDING_TYPE = "request";
public static final String ORG_ID = "org_id";

private OAuthConstants() {

Expand Down Expand Up @@ -307,7 +310,7 @@ public static class OAuth20Endpoints {
public static final String OAUTH20_AUTHORIZE_TOKEN_URL = "/authorize";
public static final String OAUTH2_AUTHZ_EP_URL = "oauth2/authorize";
public static final String OAUTH2_TOKEN_EP_URL = "oauth2/token";
public static final String OAUTH2_DCR_EP_URL = "/api/identity/oauth2/dcr/v1.0/register";
public static final String OAUTH2_DCR_EP_URL = "/api/identity/oauth2/dcr/v1.1/register";
public static final String OAUTH2_JWKS_EP_URL = "/oauth2/jwks";
public static final String OAUTH2_DISCOVERY_EP_URL = "/oauth2/oidcdiscovery";
public static final String OAUTH2_USER_INFO_EP_URL = "oauth2/userinfo";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>6.11.81-SNAPSHOT</version>
<version>6.11.90-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
4 changes: 1 addition & 3 deletions components/org.wso2.carbon.identity.oauth.dcr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>6.11.81-SNAPSHOT</version>
<version>6.11.90-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -151,8 +151,6 @@
org.wso2.carbon.context; version="${carbon.kernel.imp.pkg.version.range}",
org.wso2.carbon.utils.multitenancy;version="${carbon.kernel.imp.pkg.version.range}",

org.wso2.carbon.registry.api;version="${carbon.kernel.registry.imp.pkg.version.range}",
org.wso2.carbon.registry.core.*;version="${carbon.kernel.registry.imp.pkg.version.range}",
org.wso2.carbon.user.core.*; version="${carbon.kernel.imp.pkg.version.range}",

org.wso2.carbon.identity.core.*; version="${carbon.identity.framework.imp.pkg.version.range}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
import org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequest;
import org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile;
import org.wso2.carbon.identity.oauth.dcr.util.DCRConstants;
import org.wso2.carbon.registry.core.utils.UUIDGenerator;
import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;

import java.io.IOException;
import java.io.Reader;
import java.util.UUID;
import java.util.regex.Matcher;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -181,7 +181,7 @@ protected void parseJson(JSONObject jsonData, RegistrationRequest.RegistrationRe
if (objClient != null) {
registrationRequestProfile.setClientName((String) objClient);
} else {
registrationRequestProfile.setClientName(UUIDGenerator.generateUUID());
registrationRequestProfile.setClientName(UUID.randomUUID().toString());
}

registrationRequestProfile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.context.RegistryType;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
import org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig;
import org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig;
Expand All @@ -44,7 +43,6 @@
import org.wso2.carbon.identity.oauth.dcr.util.DCRMUtils;
import org.wso2.carbon.identity.oauth.dcr.util.ErrorCodes;
import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.user.core.util.UserCoreUtil;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;

Expand Down Expand Up @@ -388,10 +386,4 @@ private String createRegexPattern(List<String> redirectURIs) throws DCRException
return regexPattern.toString();
}

protected Registry getConfigSystemRegistry() {

return (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry(
RegistryType.SYSTEM_CONFIGURATION);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.testng.annotations.Test;
import org.wso2.carbon.base.CarbonBaseConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.context.RegistryType;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
import org.wso2.carbon.identity.application.common.model.ServiceProvider;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
Expand All @@ -44,7 +43,6 @@
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;

import java.nio.file.Paths;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -454,14 +452,6 @@ public void oAuthApplicationAvailableExceptionTest() throws Exception {
fail("Expected IdentityException was not thrown by isOAuthApplicationAvailable method");
}

@Test
public void getConfigSystemRegistryTest() {
startTenantFlow();
Registry registry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
getRegistry(RegistryType.SYSTEM_CONFIGURATION);
assertEquals(dcrManagementService.getConfigSystemRegistry(), registry);
}

private void startTenantFlow() {

String carbonHome = Paths.get(System.getProperty("user.dir"), "target").toString();
Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.oauth.endpoint/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>6.11.81-SNAPSHOT</version>
<version>6.11.90-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
import org.wso2.carbon.identity.openidconnect.OpenIDConnectClaimFilterImpl;
import org.wso2.carbon.identity.openidconnect.model.RequestObject;
import org.wso2.carbon.identity.openidconnect.model.RequestedClaim;
import org.wso2.carbon.registry.core.utils.UUIDGenerator;
import org.wso2.carbon.utils.CarbonUtils;

import java.io.IOException;
Expand Down Expand Up @@ -1409,7 +1408,7 @@ private String handleUserConsent(OAuthMessage oAuthMessage, String consent, OIDC
oAuthAuthzReqMessageContext.setAuthorizationReqDTO(authzReqDTO);
// authorizing the request
OAuth2AuthorizeRespDTO authzRespDTO = authorize(oAuthAuthzReqMessageContext);
if (authorizationResponseDTO.getRedirectUrl() == null) {
if (authzRespDTO != null && authzRespDTO.getCallbackURI() != null) {
authorizationResponseDTO.setRedirectUrl(authzRespDTO.getCallbackURI());
}

Expand Down Expand Up @@ -1879,7 +1878,7 @@ private String handleOAuthAuthorizationRequest(OAuthMessage oAuthMessage)
OAuthAuthzRequest oauthRequest = getOAuthAuthzRequest(oAuthMessage.getRequest());

OAuth2Parameters params = new OAuth2Parameters();
String sessionDataKey = UUIDGenerator.generateUUID();
String sessionDataKey = UUID.randomUUID().toString();
params.setSessionDataKey(sessionDataKey);
String redirectURI = populateOauthParameters(params, oAuthMessage, validationResponse, oauthRequest);
if (redirectURI != null) {
Expand Down Expand Up @@ -1923,8 +1922,12 @@ private void populateValidationResponseWithAppDetail(OAuthMessage oAuthMessage,
String clientId = oAuthMessage.getRequest().getParameter(CLIENT_ID);
try {
OAuthAppDO appDO = OAuth2Util.getAppInformationByClientId(clientId);
if (Boolean.TRUE.equals(oAuthMessage.getRequest().getAttribute(OAuthConstants.PKCE_UNSUPPORTED_FLOW))) {
validationResponse.setPkceMandatory(false);
} else {
validationResponse.setPkceMandatory(appDO.isPkceMandatory());
}
validationResponse.setApplicationName(appDO.getApplicationName());
validationResponse.setPkceMandatory(appDO.isPkceMandatory());
validationResponse.setPkceSupportPlain(appDO.isPkceSupportPlain());
} catch (InvalidOAuthClientException | IdentityOAuth2Exception e) {
throw new OAuthSystemException("Error while retrieving app information for client_id : " + clientId, e);
Expand Down Expand Up @@ -3708,11 +3711,13 @@ private String manageOIDCSessionState(OAuthMessage oAuthMessage,
}
}

return OIDCSessionManagementUtil.getSessionStateParam(oAuth2Parameters.getClientId(),
oAuth2Parameters.getRedirectURI(),
opBrowserStateCookie == null ?
null :
opBrowserStateCookie.getValue());
String sessionStateParam = null;
if (sessionStateObj.isAddSessionState() && StringUtils.isNotEmpty(oAuth2Parameters.getRedirectURI())) {
sessionStateParam = OIDCSessionManagementUtil.getSessionStateParam(oAuth2Parameters.getClientId(),
oAuth2Parameters.getRedirectURI(),
opBrowserStateCookie == null ? null : opBrowserStateCookie.getValue());
}
return sessionStateParam;
}

private String appendAuthenticatedIDPs(SessionDataCacheEntry sessionDataCacheEntry, String redirectURL,
Expand Down Expand Up @@ -4028,6 +4033,6 @@ private Response forwardToOauthResponseJSP(OAuthMessage oAuthMessage, String par

private boolean isPromptSelectAccount(OAuth2Parameters oauth2Params) {

return (OAuthConstants.Prompt.SELECT_ACCOUNT).equals(oauth2Params.getPrompt());
return OAuthConstants.Prompt.SELECT_ACCOUNT.equals(oauth2Params.getPrompt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public Response deviceAuthorize(@Context HttpServletRequest request, @Context Ht
commonAuthRequestWrapper.setParameter(Constants.CLIENT_ID, clientId);
commonAuthRequestWrapper.setParameter(Constants.RESPONSE_TYPE, Constants.RESPONSE_TYPE_DEVICE);
commonAuthRequestWrapper.setParameter(Constants.REDIRECTION_URI, deviceFlowDO.getCallbackUri());
commonAuthRequestWrapper.setAttribute(OAuthConstants.PKCE_UNSUPPORTED_FLOW, true);
List<String> scopes = deviceFlowDODetails.getScopes();
if (CollectionUtils.isNotEmpty(scopes)) {
String scope = String.join(Constants.SEPARATED_WITH_SPACE, scopes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.oltu.oauth2.common.message.types.GrantType;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.oauth.client.authn.filter.OAuthClientAuthenticatorProxy;
import org.wso2.carbon.identity.oauth.common.OAuth2ErrorCodes;
import org.wso2.carbon.identity.oauth.common.OAuthConstants;
Expand Down Expand Up @@ -89,7 +90,10 @@ public Response issueAccessToken(@Context HttpServletRequest request, String pay

Map<String, List<String>> paramMap;
try {
startSuperTenantFlow();
// Start super tenant flow only if tenant qualified URLs are disabled.
if (!IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
startSuperTenantFlow();
}
paramMap = parseJsonTokenRequest(payload);
if (LoggerUtils.isDiagnosticLogsEnabled()) {
Map<String, Object> params = new HashMap<>();
Expand All @@ -104,7 +108,9 @@ public Response issueAccessToken(@Context HttpServletRequest request, String pay
triggerOnTokenExceptionListeners(e, request, null);
throw e;
} finally {
PrivilegedCarbonContext.endTenantFlow();
if (!IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
PrivilegedCarbonContext.endTenantFlow();
}
}
return issueAccessToken(request, paramMap);
}
Expand Down Expand Up @@ -133,7 +139,10 @@ protected Response issueAccessToken(HttpServletRequest request, Map<String, List
OAuthSystemException, InvalidRequestParentException {

try {
startSuperTenantFlow();
// Start super tenant flow only if tenant qualified URLs are disabled.
if (!IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
startSuperTenantFlow();
}
validateRepeatedParams(request, paramMap);
HttpServletRequestWrapper httpRequest = new OAuthRequestWrapper(request, paramMap);
CarbonOAuthTokenRequest oauthRequest = buildCarbonOAuthTokenRequest(httpRequest);
Expand All @@ -157,7 +166,9 @@ protected Response issueAccessToken(HttpServletRequest request, Map<String, List
throw e;

} finally {
PrivilegedCarbonContext.endTenantFlow();
if (!IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
PrivilegedCarbonContext.endTenantFlow();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public class ClaimUtil {

private static final String SP_DIALECT = "http://wso2.org/oidc/claim";
private static final String GROUPS = "groups";
private static final String ATTRIBUTE_SEPARATOR = FrameworkUtils.getMultiAttributeSeparator();
private static final Log log = LogFactory.getLog(ClaimUtil.class);

private ClaimUtil() {
Expand Down Expand Up @@ -381,7 +380,7 @@ private static Map<ClaimMapping, String> getUserAttributesFromCache(OAuth2TokenV
*/
public static boolean isMultiValuedAttribute(String claimValue) {

return StringUtils.contains(claimValue, ATTRIBUTE_SEPARATOR);
return StringUtils.contains(claimValue, FrameworkUtils.getMultiAttributeSeparator());
}

/**
Expand All @@ -398,7 +397,7 @@ public static boolean isMultiValuedAttribute(String claimUri, String claimValue)
if (GROUPS.equals(claimUri)) {
return true;
}
return StringUtils.contains(claimValue, ATTRIBUTE_SEPARATOR);
return StringUtils.contains(claimValue, FrameworkUtils.getMultiAttributeSeparator());
}

/**
Expand All @@ -409,6 +408,6 @@ public static boolean isMultiValuedAttribute(String claimUri, String claimValue)
*/
public static String[] processMultiValuedAttribute(String claimValue) {

return claimValue.split(Pattern.quote(ATTRIBUTE_SEPARATOR));
return claimValue.split(Pattern.quote(FrameworkUtils.getMultiAttributeSeparator()));
}
}
Loading

0 comments on commit afacda4

Please sign in to comment.