use of com.aliyun.dysmsapi20170525.Client in project ORCID-Source by ORCID.
the class ClientManagerTest method editClientDontOverwriteConfigValuesTest.
@Test
@Transactional
public void editClientDontOverwriteConfigValuesTest() {
// Create a new client
String seed = RandomStringUtils.randomAlphanumeric(15);
Client client = getClient(seed, MEMBER_ID);
assertFalse(client.getId().startsWith("APP-"));
client = clientManager.create(client);
assertTrue(client.getId().startsWith("APP-"));
assertEquals(ClientType.PREMIUM_CREATOR, client.getClientType());
ClientDetailsEntity newEntity = clientDetailsDao.find(client.getId());
assertEquals("authentication-provider-id " + seed, newEntity.getAuthenticationProviderId());
assertNull(newEntity.getEmailAccessReason());
newEntity.setAuthenticationProviderId("my-authentication-provider-id");
newEntity.setEmailAccessReason("my-email-access-reason");
newEntity.setPersistentTokensEnabled(true);
newEntity.setAllowAutoDeprecate(true);
clientDetailsDao.merge(newEntity);
client.setName("Updated name");
// Try to disable the persistent tokens
client.setPersistentTokensEnabled(false);
client.setAuthenticationProviderId("another-authentication-provider-id");
client.setClientType(ClientType.PUBLIC_CLIENT);
client.setDescription("Updated description");
client.setEmailAccessReason("another-email-access-reason");
client.setWebsite("http://updated.com");
clientManager.edit(client, false);
ClientDetailsEntity updatedEntity = clientDetailsDao.find(client.getId());
// Check config options where not overwritten
assertEquals(client.getId(), updatedEntity.getId());
assertEquals("my-authentication-provider-id", updatedEntity.getAuthenticationProviderId());
assertEquals("my-email-access-reason", updatedEntity.getEmailAccessReason());
assertTrue(updatedEntity.isPersistentTokensEnabled());
assertEquals(ClientType.PREMIUM_CREATOR, updatedEntity.getClientType());
// Check updated fields where persisted
assertEquals("Updated name", updatedEntity.getClientName());
assertEquals("Updated description", updatedEntity.getClientDescription());
assertEquals("http://updated.com", updatedEntity.getClientWebsite());
}
use of com.aliyun.dysmsapi20170525.Client in project service-proxy by membrane.
the class DynamicRegistration method registerWithCallbackAt.
public Client registerWithCallbackAt(String callbackUri, String registrationEndpoint) throws Exception {
Exchange exc = new Request.Builder().post(registrationEndpoint).header(Header.CONTENT_TYPE, MimeType.APPLICATION_JSON_UTF8).body(getRegistrationBody(callbackUri)).buildExchange();
Response response = doRequest(exc);
HashMap<String, String> json = Util.parseSimpleJSONResponse(response);
if (!json.containsKey("client_id") || !json.containsKey("client_secret"))
throw new RuntimeException("Registration endpoint didn't return clientId/clientSecret");
return new Client(json.get("client_id"), json.get("client_secret"), "");
}
use of com.aliyun.dysmsapi20170525.Client in project cloud-sdk by mizhousoft.
the class AliyunSendSmsClient method init.
public void init(AliyunSmsProfile profile) throws CloudSDKException {
AssertUtils.notNull(profile.getAccessKeyId(), "Access key id is null.");
AssertUtils.notNull(profile.getAccessKeySecret(), "Access key secret is null.");
AssertUtils.notNull(profile.getEndpoint(), "Endpoint is null.");
Config config = new Config().setAccessKeyId(profile.getAccessKeyId()).setAccessKeySecret(profile.getAccessKeySecret()).setEndpoint(profile.getEndpoint());
try {
this.client = new com.aliyun.dysmsapi20170525.Client(config);
} catch (Exception e) {
throw new CloudSDKException("Init sms client failed.", e);
}
}
use of com.aliyun.dysmsapi20170525.Client in project service-proxy by membrane.
the class PasswordFlow method processWithParameters.
@Override
protected Response processWithParameters() throws Exception {
if (!verifyClientThroughParams())
return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "unauthorized_client");
Map<String, String> userParams = verifyUserThroughParams();
if (userParams == null)
return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "access_denied");
scope = getScope();
token = createTokenForVerifiedUserAndClient();
refreshToken = authServer.getRefreshTokenGenerator().getToken(getUsername(), getClientId(), getClientSecret());
SessionManager.Session session = createSessionForAuthorizedUserWithParams();
synchronized (session) {
session.getUserAttributes().put(ACCESS_TOKEN, token);
session.getUserAttributes().putAll(userParams);
}
authServer.getSessionFinder().addSessionForToken(token, session);
Client client;
try {
synchronized (authServer.getClientList()) {
client = authServer.getClientList().getClient(getClientId());
}
} catch (Exception e) {
return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_client");
}
String grantTypes = client.getGrantTypes();
if (!grantTypes.contains(getGrantType())) {
return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_grant_type");
}
refreshToken = authServer.getRefreshTokenGenerator().getToken(client.getClientId(), client.getClientId(), client.getClientSecret());
if (authServer.isIssueNonSpecIdTokens() && OAuth2Util.isOpenIdScope(scope)) {
idToken = createSignedIdToken(session, client.getClientId(), client);
}
exc.setResponse(getEarlyResponse());
return new NoResponse();
}
use of com.aliyun.dysmsapi20170525.Client in project service-proxy by membrane.
the class AuthWithoutSessionRequest method processWithParameters.
@Override
protected Response processWithParameters() throws Exception {
Client client;
try {
client = authServer.getClientList().getClient(getClientId());
} catch (Exception e) {
return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "unauthorized_client");
}
if (!OAuth2Util.isAbsoluteUri(getRedirectUri()) || !getRedirectUri().equals(client.getCallbackUrl()))
return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_request");
if (promptEqualsNone())
return createParameterizedFormUrlencodedRedirect(exc, getState(), client.getCallbackUrl() + "?error=login_required");
if (!authServer.getSupportedAuthorizationGrants().contains(getResponseType()))
return createParameterizedFormUrlencodedRedirect(exc, getState(), client.getCallbackUrl() + "?error=unsupported_response_type");
String validScopes = verifyScopes(getScope());
if (validScopes.isEmpty())
return createParameterizedFormUrlencodedRedirect(exc, getState(), client.getCallbackUrl() + "?error=invalid_scope");
if (OAuth2Util.isOpenIdScope(validScopes)) {
if (!isCodeRequest())
return createParameterizedFormUrlencodedRedirect(exc, getState(), client.getCallbackUrl() + "?error=invalid_request");
// Parses the claims parameter into a json object. Claim values are always ignored and set to "null" as it is optional to react to those values
addValidClaimsToParams();
} else
removeClaimsWhenNotOpenidScope();
setScope(validScopes);
String invalidScopes = hasGivenInvalidScopes(getScope(), validScopes);
if (!invalidScopes.isEmpty())
setScopeInvalid(invalidScopes);
SessionManager.Session session = authServer.getSessionManager().getOrCreateSession(exc);
addParams(session, params);
return new NoResponse();
}
Aggregations