Java Code Examples for org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser#isFederatedUser()

The following examples show how to use org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser#isFederatedUser() . 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: CellerySignedJWTGenerator.java    From cellery-security with Apache License 2.0 6 votes vote down vote up
private String getEndUserName(TokenValidationContext validationContext) throws APIManagementException {

        try {
            String accessToken = validationContext.getAccessToken();
            AccessTokenDO tokenInfo = OAuth2Util.getAccessTokenDOfromTokenIdentifier(accessToken);
            AuthenticatedUser authzUser = tokenInfo.getAuthzUser();
            String endUserName = validationContext.getValidationInfoDTO().getEndUserName();
            if (authzUser.isFederatedUser()) {
                return endUserName;
            } else {
                return MultitenantUtils.getTenantAwareUsername(endUserName);
            }
        } catch (IdentityOAuth2Exception e) {
            throw new APIManagementException("Error while retrieving authenticated user metadata.", e);
        }

    }
 
Example 2
Source File: AbstractScopesIssuer.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * This method is used to get the application scopes including the scopes defined for the APIs subscribed to the
 * application and the API-M REST API scopes set of the current tenant.
 *
 * @param consumerKey       Consumer Key of the application
 * @param authenticatedUser Authenticated User
 * @return Application Scope List
 */
public Map<String, String> getAppScopes(String consumerKey, AuthenticatedUser authenticatedUser) {

    //Get all the scopes and roles against the scopes defined for the APIs subscribed to the application.
    Map<String, String> appScopes = null;
    String tenantDomain;
    if (authenticatedUser.isFederatedUser()) {
        tenantDomain = MultitenantUtils.getTenantDomain(authenticatedUser.getAuthenticatedSubjectIdentifier());
    } else {
        tenantDomain = authenticatedUser.getTenantDomain();
    }
    try {
        appScopes = getApiMgtDAOInstance().getScopeRolesOfApplication(consumerKey);
        //Add API Manager rest API scopes set. This list should be loaded at server start up and keep
        //in memory and add it to each and every request coming.
        appScopes.putAll(APIUtil.getRESTAPIScopesForTenant(tenantDomain));
    } catch (APIManagementException e) {
        log.error("Error while getting scopes of application " + e.getMessage(), e);
    }
    return appScopes;
}
 
Example 3
Source File: SSOConsentServiceImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private String buildSubjectWithUserStoreDomain(AuthenticatedUser authenticatedUser) {

        String userStoreDomain;
        if (authenticatedUser.isFederatedUser()) {
            userStoreDomain = getFederatedUserDomain(authenticatedUser.getFederatedIdPName());
        } else {
            userStoreDomain = authenticatedUser.getUserStoreDomain();
        }

        return UserCoreUtil.addDomainToName(authenticatedUser.getUserName(), userStoreDomain);
    }
 
Example 4
Source File: RoleBasedScopesIssuer.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * This method is used to get roles list of the user.
 *
 * @param authenticatedUser Authenticated user
 * @return roles list
 */
private String[] getUserRoles(AuthenticatedUser authenticatedUser) {

    String[] userRoles = null;
    String tenantDomain;
    String username;
    if (authenticatedUser.isFederatedUser()) {
        tenantDomain = MultitenantUtils.getTenantDomain(authenticatedUser.getAuthenticatedSubjectIdentifier());
        username = MultitenantUtils.getTenantAwareUsername(authenticatedUser.getAuthenticatedSubjectIdentifier());
    } else {
        tenantDomain = authenticatedUser.getTenantDomain();
        username = authenticatedUser.getUserName();
    }
    String userStoreDomain = authenticatedUser.getUserStoreDomain();
    RealmService realmService = getRealmService();
    try {
        int tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
        // If tenant Id is not set in the tokenReqContext, deriving it from username.
        if (tenantId == 0 || tenantId == -1) {
            tenantId = getTenantIdOfUser(username);
        }
        UserStoreManager userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
        String endUsernameWithDomain = addDomainToName(username, userStoreDomain);
        userRoles = userStoreManager.getRoleListOfUser(endUsernameWithDomain);

    } catch (UserStoreException e) {
        //Log and return since we do not want to stop issuing the token in case of scope validation failures.
        log.error("Error when getting the tenant's UserStoreManager or when getting roles of user ", e);
    }
    return userRoles;
}
 
Example 5
Source File: DefaultAuthenticationRequestHandler.java    From carbon-identity-framework with Apache License 2.0 2 votes vote down vote up
private boolean isFederatedUser(AuthenticatedUser authenticatedUser) {

        return authenticatedUser.isFederatedUser();
    }