Java Code Examples for org.wso2.carbon.utils.multitenancy.MultitenantUtils#getDomainNameFromOpenId()

The following examples show how to use org.wso2.carbon.utils.multitenancy.MultitenantUtils#getDomainNameFromOpenId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenIDUtil.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public static String getFronEndUrl(String openId, HttpServletRequest request, String relativeUrl) {
    String tenant = MultitenantUtils.getDomainNameFromOpenId(openId);
    if (getHostName().equals(tenant)) {
        tenant = null;
    }

    String frontEndUrl = IdentityUtil.getServerURL("/carbon/", false, true) + relativeUrl;

    if (tenant != null && tenant.trim().length() > 0) {
        return frontEndUrl.replace("/carbon/", "/t/" + tenant + "/carbon/");
    }

    return frontEndUrl;
}
 
Example 2
Source File: OpenIDUtil.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private static String getHostName() {
    ServerConfiguration serverConfig = ServerConfiguration.getInstance();
    if (serverConfig.getFirstProperty("HostName") != null) {
        return MultitenantUtils.getDomainNameFromOpenId(serverConfig.getFirstProperty("HostName"));
    } else {
        return "localhost";
    }
}
 
Example 3
Source File: OpenIDProviderService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param userName
 * @return
 * @throws IdentityProviderException
 */
public OpenIDProviderInfoDTO getOpenIDProviderInfo(String userName, String openid)
        throws IdentityProviderException {

    OpenIDProviderInfoDTO providerInfo = new OpenIDProviderInfoDTO();
    String domain = null;
    UserRealm realm = null;

    try {
        domain = MultitenantUtils.getDomainNameFromOpenId(openid);
        realm = IdentityTenantUtil.getRealm(domain, userName);
    } catch (IdentityException e) {
        if (log.isDebugEnabled()) {
            log.debug("Ignoring IdentityException", e);
        }
    }
    if (realm == null) {
        return providerInfo;
    }

    providerInfo.setSubDomain(domain);
    String tenantFreeUsername = MultitenantUtils.getTenantAwareUsername(userName);

    providerInfo.setOpenIDProviderServerUrl(OpenIDUtil.getOpenIDServerURL());
    providerInfo.setOpenID(OpenIDUtil.getOpenIDUserPattern() + "/" + tenantFreeUsername);

    return providerInfo;
}
 
Example 4
Source File: OpenIDProviderService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Get Profile details of an user
 *
 * @param openId
 * @return
 * @throws IdentityProviderException
 */
public OpenIDUserProfileDTO[] getUserProfiles(String openId, OpenIDParameterDTO[] requredClaims)
        throws IdentityProviderException {
    String userName = null;
    UserRealm realm = null;
    UserStoreManager reader = null;
    String tenatUser = null;
    String domainName = null;

    try {
        userName = OpenIDUtil.getUserName(openId);
        tenatUser = MultitenantUtils.getTenantAwareUsername(userName);
        domainName = MultitenantUtils.getDomainNameFromOpenId(openId);
        realm = IdentityTenantUtil.getRealm(domainName, userName);
        reader = realm.getUserStoreManager();
        String[] profileNames = reader.getProfileNames(tenatUser);
        OpenIDUserProfileDTO[] profileDtoSet = new OpenIDUserProfileDTO[profileNames.length];

        List<String> claimList = null;
        ParameterList paramList = getParameterList(requredClaims);
        AuthRequest authReq =
                AuthRequest.createAuthRequest(paramList, OpenIDProvider.getInstance()
                                                                       .getManager()
                                                                       .getRealmVerifier());

        claimList = getRequestedAttributes(authReq);

        for (int i = 0; i < profileNames.length; i++) {
            OpenIDUserProfileDTO profileDTO = new OpenIDUserProfileDTO();
            OpenIDClaimDTO[] claimSet =
                    getOpenIDClaimValues(openId, profileNames[i], claimList);
            profileDTO.setProfileName(profileNames[i]);
            profileDTO.setClaimSet(claimSet);
            profileDtoSet[i] = profileDTO;
        }
        return profileDtoSet;
    } catch (MalformedURLException | UserStoreException | MessageException | IdentityException e) {
        throw new IdentityProviderException("Error while retrieving user profiles", e);
    }
}
 
Example 5
Source File: OpenIDProviderService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Returns RP DTO objects for the given OpenID
 *
 * @param openID
 * @return openIDUserDTOs
 * @throws IdentityProviderException
 */
public OpenIDUserRPDTO[] getOpenIDUserRPs(String openID) throws IdentityProviderException {

    String username = null;
    try {
        username = OpenIDUtil.getUserName(openID);
    } catch (MalformedURLException e) {
        throw new IdentityProviderException("Error while getting username for OpenID " + username, e);
    }
    String domainName = MultitenantUtils.getDomainNameFromOpenId(openID);
    int tenantId = IdentityTenantUtil.getTenantId(domainName);

    OpenIDUserRPDO[] rpdos = null;
    OpenIDUserRPDAO dao = new OpenIDUserRPDAO();
    rpdos = dao.getOpenIDUserRPs(username, tenantId);
    if (rpdos == null) {
        return new OpenIDUserRPDTO[0];
    }

    OpenIDUserRPDTO[] rpdto = new OpenIDUserRPDTO[rpdos.length];
    int i = 0;
    for (OpenIDUserRPDO rpdo : rpdos) {
        rpdto[i] = new OpenIDUserRPDTO(rpdo);
        i++;
    }
    return rpdto;
}