Search in sources :

Example 36 with Client

use of com.aliyun.ons20190214.Client in project service-proxy by membrane.

the class CredentialsFlow method processWithParameters.

@Override
protected Response processWithParameters() throws Exception {
    if (!verifyClientThroughParams())
        return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "unauthorized_client");
    scope = getScope();
    token = createTokenForVerifiedClient();
    SessionManager.Session session = createSessionForAuthorizedClientWithParams();
    synchronized (session) {
        session.getUserAttributes().put(ACCESS_TOKEN, token);
    }
    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");
    }
    authServer.getSessionFinder().addSessionForToken(token, session);
    if (authServer.isIssueNonSpecRefreshTokens())
        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();
}
Also used : SessionManager(com.predic8.membrane.core.interceptor.authentication.session.SessionManager) Client(com.predic8.membrane.core.interceptor.oauth2.Client) NoResponse(com.predic8.membrane.core.interceptor.oauth2.request.NoResponse) IOException(java.io.IOException) JoseException(org.jose4j.lang.JoseException)

Example 37 with Client

use of com.aliyun.ons20190214.Client in project service-proxy by membrane.

the class RevocationEndpointProcessor method process.

@Override
public Outcome process(Exchange exc) throws Exception {
    Map<String, String> params = URLParamUtil.getParams(uriFactory, exc);
    if (!params.containsKey("token")) {
        exc.setResponse(OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_request"));
        return Outcome.RETURN;
    }
    SessionManager.Session session = authServer.getSessionFinder().getSessionForToken(params.get("token"));
    if (session == null) {
        // token doesnt exist -> token is already invalid
        exc.setResponse(Response.ok().bodyEmpty().build());
        return Outcome.RETURN;
    }
    Client client;
    Map<String, String> userAttributes = session.getUserAttributes();
    synchronized (userAttributes) {
        try {
            client = authServer.getClientList().getClient(userAttributes.get(ParamNames.CLIENT_ID));
        } catch (Exception e) {
            // This should never happen
            exc.setResponse(Response.ok().bodyEmpty().build());
            return Outcome.RETURN;
        }
    }
    String paramClientId = params.get(ParamNames.CLIENT_ID);
    String paramClientSecret = params.get(ParamNames.CLIENT_SECRET);
    if ((paramClientId != null && !client.getClientId().equals(paramClientId)) || (paramClientSecret != null && !client.getClientSecret().equals(paramClientSecret))) {
        exc.setResponse(OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_grant"));
        return Outcome.RETURN;
    }
    try {
        authServer.getTokenGenerator().invalidateToken(params.get("token"), client.getClientId(), client.getClientSecret());
    } catch (Exception e) {
        exc.setResponse(OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_grant"));
        return Outcome.RETURN;
    }
    synchronized (session) {
        session.clear();
    }
    synchronized (authServer.getSessionManager()) {
        authServer.getSessionManager().removeSession(session);
    }
    synchronized (authServer.getSessionFinder()) {
        authServer.getSessionFinder().removeSessionForToken(params.get("token"));
    }
    exc.setResponse(Response.ok().bodyEmpty().build());
    return Outcome.RETURN;
}
Also used : SessionManager(com.predic8.membrane.core.interceptor.authentication.session.SessionManager) Client(com.predic8.membrane.core.interceptor.oauth2.Client)

Example 38 with Client

use of com.aliyun.ons20190214.Client in project submarine by apache.

the class ModelManager method transferDescription.

private void transferDescription(ServeSpec spec) {
    Client s3Client = new Client();
    String modelUniquePath = String.format("%s-%d-%s", spec.getModelName(), spec.getModelVersion(), spec.getModelId());
    String res = new String(s3Client.downloadArtifact(String.format("registry/%s/%s/%d/description.json", modelUniquePath, spec.getModelName(), spec.getModelVersion())));
    JSONObject description = new JSONObject(res);
    TritonModelConfig.ModelConfig.Builder modelConfig = TritonModelConfig.ModelConfig.newBuilder();
    modelConfig.setPlatform("pytorch_libtorch");
    JSONArray inputs = (JSONArray) description.get("input");
    for (int idx = 0; idx < inputs.length(); idx++) {
        JSONArray dims = (JSONArray) ((JSONObject) inputs.get(idx)).get("dims");
        TritonModelConfig.ModelInput.Builder modelInput = TritonModelConfig.ModelInput.newBuilder();
        modelInput.setName("INPUT__" + idx);
        modelInput.setDataType(TritonModelConfig.DataType.valueOf("TYPE_FP32"));
        dims.forEach(dim -> modelInput.addDims((Integer) dim));
        modelConfig.addInput(modelInput);
    }
    JSONArray outputs = (JSONArray) description.get("output");
    for (int idx = 0; idx < outputs.length(); idx++) {
        JSONArray dims = (JSONArray) ((JSONObject) outputs.get(idx)).get("dims");
        TritonModelConfig.ModelOutput.Builder modelOutput = TritonModelConfig.ModelOutput.newBuilder();
        modelOutput.setName("OUTPUT__" + idx);
        modelOutput.setDataType(TritonModelConfig.DataType.valueOf("TYPE_FP32"));
        dims.forEach(dim -> modelOutput.addDims((Integer) dim));
        modelConfig.addOutput(modelOutput);
    }
    s3Client.logArtifact(String.format("registry/%s/%s/config.pbtxt", modelUniquePath, spec.getModelName()), modelConfig.toString().getBytes());
}
Also used : TritonModelConfig(org.apache.submarine.server.api.proto.TritonModelConfig) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Client(org.apache.submarine.server.s3.Client)

Example 39 with Client

use of com.aliyun.ons20190214.Client in project rocketmq-connect by apache.

the class RocketMQSinkConnector method validate.

@Override
public void validate(KeyValue config) {
    if (StringUtils.isBlank(config.getString(RocketMQConstant.ACCESS_KEY_ID)) || StringUtils.isBlank(config.getString(RocketMQConstant.ACCESS_KEY_SECRET)) || StringUtils.isBlank(config.getString(RocketMQConstant.NAMESRV_ADDR)) || StringUtils.isBlank(config.getString(RocketMQConstant.TOPIC))) {
        throw new RuntimeException("rocketmq required parameter is null !");
    }
    try {
        Config onsConfig = new Config().setAccessKeyId(config.getString(RocketMQConstant.ACCESS_KEY_ID)).setAccessKeySecret(config.getString(RocketMQConstant.ACCESS_KEY_SECRET));
        onsConfig.endpoint = OnsUtils.parseEndpoint(config.getString(RocketMQConstant.NAMESRV_ADDR));
        final Client client = new Client(onsConfig);
        OnsTopicListRequest onsTopicListRequest = new OnsTopicListRequest().setTopic(config.getString(RocketMQConstant.TOPIC)).setInstanceId(config.getString(RocketMQConstant.INSTANCE_ID));
        final OnsTopicListResponse onsTopicListResponse = client.onsTopicList(onsTopicListRequest);
        if (onsTopicListResponse.getBody().getData().getPublishInfoDo().isEmpty()) {
            throw new RuntimeException("rocketmq required parameter topic does not exist !");
        }
    } catch (Exception e) {
        log.error("RocketMQSinkTask | validate | error => ", e);
        throw new RuntimeException(e.getMessage());
    }
}
Also used : OnsTopicListResponse(com.aliyun.ons20190214.models.OnsTopicListResponse) Config(com.aliyun.teaopenapi.models.Config) OnsTopicListRequest(com.aliyun.ons20190214.models.OnsTopicListRequest) Client(com.aliyun.ons20190214.Client)

Example 40 with Client

use of com.aliyun.ons20190214.Client in project rocketmq-connect by apache.

the class RocketMQSourceConnector method validate.

@Override
public void validate(KeyValue config) {
    if (StringUtils.isBlank(config.getString(RocketMQConstant.ACCESS_KEY_ID)) || StringUtils.isBlank(config.getString(RocketMQConstant.ACCESS_KEY_SECRET)) || StringUtils.isBlank(config.getString(RocketMQConstant.NAMESRV_ADDR)) || StringUtils.isBlank(config.getString(RocketMQConstant.TOPIC)) || StringUtils.isBlank(config.getString(RocketMQConstant.CONSUMER_GROUP))) {
        throw new RuntimeException("rocketmq required parameter is null !");
    }
    try {
        Config onsConfig = new Config().setAccessKeyId(config.getString(RocketMQConstant.ACCESS_KEY_ID)).setAccessKeySecret(config.getString(RocketMQConstant.ACCESS_KEY_SECRET));
        onsConfig.endpoint = OnsUtils.parseEndpoint(config.getString(RocketMQConstant.NAMESRV_ADDR));
        final Client client = new Client(onsConfig);
        OnsTopicListRequest onsTopicListRequest = new OnsTopicListRequest().setTopic(config.getString(RocketMQConstant.TOPIC)).setInstanceId(config.getString(RocketMQConstant.INSTANCE_ID));
        final OnsTopicListResponse onsTopicListResponse = client.onsTopicList(onsTopicListRequest);
        if (onsTopicListResponse.getBody().getData().getPublishInfoDo().isEmpty()) {
            throw new RuntimeException("rocketmq required parameter topic does not exist !");
        }
        OnsGroupListRequest onsGroupListRequest = new OnsGroupListRequest().setInstanceId(config.getString(RocketMQConstant.INSTANCE_ID)).setGroupId(config.getString(RocketMQConstant.CONSUMER_GROUP));
        final OnsGroupListResponse onsGroupListResponse = client.onsGroupList(onsGroupListRequest);
        if (onsGroupListResponse.getBody().getData().getSubscribeInfoDo().isEmpty()) {
            throw new RuntimeException("rocketmq required parameter consumerGroup does not exist !");
        }
    } catch (Exception e) {
        log.error("RocketMQSinkTask | validate | error => ", e);
        throw new RuntimeException(e.getMessage());
    }
}
Also used : OnsTopicListResponse(com.aliyun.ons20190214.models.OnsTopicListResponse) OnsGroupListRequest(com.aliyun.ons20190214.models.OnsGroupListRequest) Config(com.aliyun.teaopenapi.models.Config) OnsTopicListRequest(com.aliyun.ons20190214.models.OnsTopicListRequest) OnsGroupListResponse(com.aliyun.ons20190214.models.OnsGroupListResponse) Client(com.aliyun.ons20190214.Client)

Aggregations

Client (org.orcid.jaxb.model.client_v2.Client)18 Test (org.junit.Test)13 Client (com.aliyun.dysmsapi20170525.Client)12 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)10 Client (com.predic8.membrane.core.interceptor.oauth2.Client)9 Config (com.aliyun.teaopenapi.models.Config)6 HashSet (java.util.HashSet)6 ClientRedirectUri (org.orcid.jaxb.model.client_v2.ClientRedirectUri)6 SessionManager (com.predic8.membrane.core.interceptor.authentication.session.SessionManager)5 BaseTest (org.orcid.core.BaseTest)5 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)5 NoResponse (com.predic8.membrane.core.interceptor.oauth2.request.NoResponse)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 SendSmsRequest (com.aliyun.dysmsapi20170525.models.SendSmsRequest)2 SendSmsResponse (com.aliyun.dysmsapi20170525.models.SendSmsResponse)2 Client (com.aliyun.ons20190214.Client)2 OnsTopicListRequest (com.aliyun.ons20190214.models.OnsTopicListRequest)2 OnsTopicListResponse (com.aliyun.ons20190214.models.OnsTopicListResponse)2