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;
}
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);
}
}
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");
}
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;
}
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;
}
Aggregations