Merge branch 'master' of github.com:wso2/carbon-device-mgt

merge-requests/7/head
Kasun Delgolla 9 years ago
commit acdfc475be

@ -27,9 +27,7 @@ import org.wso2.carbon.apimgt.core.authenticate.APITokenValidator;
import org.wso2.carbon.apimgt.impl.APIConstants; import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO; import org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.base.IdentityException; import org.wso2.carbon.webapp.authenticator.framework.Utils.Utils;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
@ -61,13 +59,12 @@ public class AuthenticationFrameworkUtil {
if (apiKeyValidationDTO.isAuthorized()) { if (apiKeyValidationDTO.isAuthorized()) {
String username = apiKeyValidationDTO.getEndUserName(); String username = apiKeyValidationDTO.getEndUserName();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username);
try { // try {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(IdentityUtil. PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(Utils.getTenantIdOFUser(username));
getTenantIdOFUser(username)); // } catch (IdentityException e) {
} catch (IdentityException e) { // throw new AuthenticationException("Error occurred while retrieving the tenant ID of user '" +
throw new AuthenticationException("Error occurred while retrieving the tenant ID of user '" + // username + "'", e);
username + "'", e); // }
}
return true; return true;
} else { } else {
throw new AuthenticationException(apiKeyValidationDTO.getValidationStatus(), throw new AuthenticationException(apiKeyValidationDTO.getValidationStatus(),

@ -0,0 +1,50 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.webapp.authenticator.framework.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.user.api.TenantManager;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import org.wso2.carbon.webapp.authenticator.framework.AuthenticationException;
public class Utils {
private static final Log log = LogFactory.getLog(Utils.class);
public static int getTenantIdOFUser(String username) throws AuthenticationException {
int tenantId = 0;
String domainName = MultitenantUtils.getTenantDomain(username);
if (domainName != null) {
try {
TenantManager tenantManager = IdentityTenantUtil.getRealmService().getTenantManager();
tenantId = tenantManager.getTenantId(domainName);
} catch (UserStoreException e) {
String errorMsg = "Error when getting the tenant id from the tenant domain : " +
domainName;
log.error(errorMsg, e);
throw new AuthenticationException(errorMsg, e);
}
}
return tenantId;
}
}

@ -25,12 +25,11 @@ import org.apache.commons.logging.LogFactory;
import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.buf.MessageBytes; import org.apache.tomcat.util.buf.MessageBytes;
import org.wso2.carbon.apimgt.core.gateway.APITokenAuthenticator; import org.wso2.carbon.apimgt.core.gateway.APITokenAuthenticator;
import org.wso2.carbon.identity.base.IdentityException;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO; import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO;
import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationResponseDTO; import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationResponseDTO;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import org.wso2.carbon.webapp.authenticator.framework.*; import org.wso2.carbon.webapp.authenticator.framework.*;
import org.wso2.carbon.webapp.authenticator.framework.Utils.Utils;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -111,14 +110,14 @@ public class OAuthAuthenticator implements WebappAuthenticator {
AuthenticatorFrameworkDataHolder.getInstance().getoAuth2TokenValidationService().validate(dto); AuthenticatorFrameworkDataHolder.getInstance().getoAuth2TokenValidationService().validate(dto);
if (oAuth2TokenValidationResponseDTO.isValid()) { if (oAuth2TokenValidationResponseDTO.isValid()) {
String username = oAuth2TokenValidationResponseDTO.getAuthorizedUser(); String username = oAuth2TokenValidationResponseDTO.getAuthorizedUser();
try { // try {
authenticationInfo.setUsername(username); authenticationInfo.setUsername(username);
authenticationInfo.setTenantDomain(MultitenantUtils.getTenantDomain(username)); authenticationInfo.setTenantDomain(MultitenantUtils.getTenantDomain(username));
authenticationInfo.setTenantId(IdentityUtil.getTenantIdOFUser(username)); authenticationInfo.setTenantId(Utils.getTenantIdOFUser(username));
} catch (IdentityException e) { // } catch (AuthenticationException e) {
throw new AuthenticationException( // throw new AuthenticationException(
"Error occurred while retrieving the tenant ID of user '" + username + "'", e); // "Error occurred while retrieving the tenant ID of user '" + username + "'", e);
} // }
if (oAuth2TokenValidationResponseDTO.isValid()) { if (oAuth2TokenValidationResponseDTO.isValid()) {
authenticationInfo.setStatus(Status.CONTINUE); authenticationInfo.setStatus(Status.CONTINUE);
} }
@ -149,6 +148,9 @@ public class OAuthAuthenticator implements WebappAuthenticator {
tokenValue = tokenValue.substring(matcher.end()); tokenValue = tokenValue.substring(matcher.end());
} }
} }
if(log.isDebugEnabled()) {
log.debug("Oauth Token : " + tokenValue);
}
return tokenValue; return tokenValue;
} }

@ -1468,7 +1468,7 @@
<carbon.deployment.version>4.5.2</carbon.deployment.version> <carbon.deployment.version>4.5.2</carbon.deployment.version>
<!-- Carbon Identity --> <!-- Carbon Identity -->
<carbon.identity.version>4.6.0-M2</carbon.identity.version> <carbon.identity.version>4.6.0-SNAPSHOT</carbon.identity.version>
<!-- Carbon Multi-tenancy --> <!-- Carbon Multi-tenancy -->
<carbon.multitenancy.version>4.5.0-m1</carbon.multitenancy.version> <carbon.multitenancy.version>4.5.0-m1</carbon.multitenancy.version>

Loading…
Cancel
Save