Search in sources :

Example 11 with Scope

use of org.wso2.carbon.apimgt.keymgt.model.entity.Scope in project identity-api-server by wso2.

the class OidcScopeManagementService method convertScopeDTOObjectToScope.

/**
 * Convert ScopeDTO to Scope object.
 *
 * @param scopeDTO ScopeDTO.
 * @return Converted Scope.
 */
private Scope convertScopeDTOObjectToScope(ScopeDTO scopeDTO) {
    Scope scope = new Scope();
    scope.setName(scopeDTO.getName());
    scope.setDisplayName(scopeDTO.getDisplayName());
    scope.setDescription(scopeDTO.getDescription());
    scope.setClaims(Arrays.asList(scopeDTO.getClaim()));
    return scope;
}
Also used : Scope(org.wso2.carbon.identity.api.server.oidc.scope.management.v1.model.Scope)

Example 12 with Scope

use of org.wso2.carbon.apimgt.keymgt.model.entity.Scope in project identity-api-server by wso2.

the class OidcScopeManagementService method updateScope.

/**
 * Update an existing scope.
 *
 * @param id                Scope name.
 * @param scopeUpdateObject Updated scope object.
 */
public void updateScope(String id, ScopeUpdateRequest scopeUpdateObject) {
    try {
        List<String> claimList = scopeUpdateObject.getClaims();
        String[] claimArray = claimList.toArray(new String[claimList.size()]);
        ScopeDTO scopeDTO = new ScopeDTO(id, scopeUpdateObject.getDisplayName(), scopeUpdateObject.getDescription(), claimArray);
        getOAuthAdminService().updateScope(scopeDTO);
    } catch (IdentityOAuthAdminException e) {
        throw handleException(e, "Server encountered an error while updating OIDC scope: " + id);
    }
}
Also used : IdentityOAuthAdminException(org.wso2.carbon.identity.oauth.IdentityOAuthAdminException) ScopeDTO(org.wso2.carbon.identity.oauth.dto.ScopeDTO)

Example 13 with Scope

use of org.wso2.carbon.apimgt.keymgt.model.entity.Scope in project identity-inbound-auth-oauth by wso2-extensions.

the class EndpointUtilTest method testGetLoginPageURL.

@Test(dataProvider = "provideScopeData")
public void testGetLoginPageURL(Set<String> scopes, String queryParam) throws Exception {
    Map<String, String[]> reqParams = new HashedMap();
    reqParams.put("param1", new String[] { "value1" });
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockedOAuthServerConfiguration);
    mockStatic(OAuth2Util.class);
    when(OAuth2Util.getClientTenatId()).thenReturn(-1234);
    mockStatic(FrameworkUtils.class);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return null;
        }
    }).when(FrameworkUtils.class, "addAuthenticationRequestToCache", anyString(), any(AuthenticationRequestCacheEntry.class));
    mockServiceURLBuilder(COMMONAUTH_URL);
    String url = EndpointUtil.getLoginPageURL(clientId, sessionDataKey, true, true, scopes, reqParams);
    Assert.assertTrue(url.contains("type=" + queryParam), "type parameter is not set according to the scope");
}
Also used : PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) HashedMap(org.apache.commons.collections.map.HashedMap) AuthenticationRequestCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationRequestCacheEntry) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Example 14 with Scope

use of org.wso2.carbon.apimgt.keymgt.model.entity.Scope in project identity-inbound-auth-oauth by wso2-extensions.

the class EndpointUtilTest method getScopeList.

private List<Scope> getScopeList() {
    List<Scope> scopeList = new ArrayList<>();
    // Add some sample scopes.
    scopeList.add(new Scope("internal_login", "Login", "description1"));
    scopeList.add(new Scope("internal_config_mgt_update", "Update Configs", "description2"));
    scopeList.add(new Scope("internal_config_mgt_update", "Update Email Configs", "description3"));
    scopeList.add(new Scope("internal_user_mgt_update", "Update Users", "description4"));
    scopeList.add(new Scope("internal_list_tenants", "List Tenant", "description5"));
    return scopeList;
}
Also used : Scope(org.wso2.carbon.identity.oauth2.bean.Scope) ArrayList(java.util.ArrayList)

Example 15 with Scope

use of org.wso2.carbon.apimgt.keymgt.model.entity.Scope in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuthServlet method populateOauthConsumerData.

/*
     * Populates the Parameters object from the OAuth authorization header or query string.
     */
private Parameters populateOauthConsumerData(HttpServletRequest request) {
    String authHeader = null;
    Parameters params = null;
    String splitChar = ",";
    boolean noAuthorizationHeader = false;
    authHeader = request.getHeader("Authorization");
    params = new Parameters();
    if (authHeader == null) {
        noAuthorizationHeader = true;
        // No Authorization header available.
        authHeader = request.getQueryString();
        splitChar = "&";
    }
    StringBuilder nonAuthParams = new StringBuilder();
    if (authHeader != null) {
        if (authHeader.startsWith("OAuth ") || authHeader.startsWith("oauth ")) {
            authHeader = authHeader.substring(authHeader.indexOf("o"));
        }
        String[] headers = authHeader.split(splitChar);
        if (headers != null && headers.length > 0) {
            for (int i = 0; i < headers.length; i++) {
                String[] elements = headers[i].split("=");
                if (elements != null && elements.length > 0) {
                    if (OAuthConstants.OAuth10AParams.OAUTH_CONSUMER_KEY.equals(elements[0].trim())) {
                        params.setOauthConsumerKey(removeLeadingAndTrailingQuatation(elements[1].trim()));
                    } else if (OAuthConstants.OAuth10AParams.OAUTH_NONCE.equals(elements[0].trim())) {
                        params.setOauthNonce(removeLeadingAndTrailingQuatation(elements[1].trim()));
                    } else if (OAuthConstants.OAuth10AParams.OAUTH_SIGNATURE.equals(elements[0].trim())) {
                        params.setOauthSignature(removeLeadingAndTrailingQuatation(elements[1].trim()));
                    } else if (OAuthConstants.OAuth10AParams.OAUTH_SIGNATURE_METHOD.equals(elements[0].trim())) {
                        params.setOauthSignatureMethod(removeLeadingAndTrailingQuatation(elements[1].trim()));
                    } else if (OAuthConstants.OAuth10AParams.OAUTH_TIMESTAMP.equals(elements[0].trim())) {
                        params.setOauthTimeStamp(removeLeadingAndTrailingQuatation(elements[1].trim()));
                    } else if (OAuthConstants.OAuth10AParams.OAUTH_CALLBACK.equals(elements[0].trim())) {
                        params.setOauthCallback(removeLeadingAndTrailingQuatation(elements[1].trim()));
                    } else if (OAuthConstants.OAuth10AParams.SCOPE.equals(elements[0].trim())) {
                        params.setScope(removeLeadingAndTrailingQuatation(elements[1].trim()));
                    } else if (OAuthConstants.OAuth10AParams.OAUTH_DISPLAY_NAME.equals(elements[0].trim())) {
                        params.setDisplayName(removeLeadingAndTrailingQuatation(elements[1].trim()));
                    } else if (OAuthConstants.OAUTH_TOKEN.equals(elements[0].trim())) {
                        params.setOauthToken(removeLeadingAndTrailingQuatation(elements[1].trim()));
                    } else if (OAuthConstants.OAUTH_VERIFIER.equals(elements[0].trim())) {
                        params.setOauthTokenVerifier(removeLeadingAndTrailingQuatation(elements[1].trim()));
                    } else if (OAuthConstants.OAUTH_TOKEN_SECRET.equals(elements[0].trim())) {
                        params.setOauthTokenSecret(removeLeadingAndTrailingQuatation(elements[1].trim()));
                    } else if (OAuthConstants.OAuth10AParams.OAUTH_VERSION.equals(elements[0].trim())) {
                        params.setVersion(removeLeadingAndTrailingQuatation(elements[1].trim()));
                    } else {
                        nonAuthParams.append(elements[0].trim() + "=" + removeLeadingAndTrailingQuatation(elements[1].trim()) + "&");
                    }
                }
            }
        }
    }
    String nonOauthParamStr = nonAuthParams.toString();
    if (!noAuthorizationHeader) {
        nonOauthParamStr = request.getQueryString() + "&";
    }
    String scope = request.getParameter(OAuthConstants.OAuth10AParams.SCOPE);
    if (scope != null) {
        params.setScope(scope);
    }
    params.setHttpMethod(request.getMethod());
    if (nonOauthParamStr.length() > 1) {
        params.setBaseString(request.getRequestURL().toString() + "?" + nonOauthParamStr.substring(0, nonOauthParamStr.length() - 1));
    } else {
        params.setBaseString(request.getRequestURL().toString());
    }
    return params;
}
Also used : Parameters(org.wso2.carbon.identity.oauth.stub.types.Parameters)

Aggregations

HashMap (java.util.HashMap)122 ArrayList (java.util.ArrayList)119 Scope (org.wso2.carbon.apimgt.api.model.Scope)97 Test (org.testng.annotations.Test)78 Connection (java.sql.Connection)66 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)64 Map (java.util.Map)63 SQLException (java.sql.SQLException)61 PreparedStatement (java.sql.PreparedStatement)59 HashSet (java.util.HashSet)59 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)50 ResultSet (java.sql.ResultSet)45 Scope (org.wso2.carbon.apimgt.core.models.Scope)41 List (java.util.List)39 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)39 Scope (org.wso2.carbon.identity.oauth2.bean.Scope)39 AccessTokenDO (org.wso2.carbon.identity.oauth2.model.AccessTokenDO)39 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)38 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)33 LinkedHashSet (java.util.LinkedHashSet)32