Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE#5696] repackage client #7029

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.alibaba.nacos.client.auth;

import com.alibaba.nacos.client.auth.spi.AbstractClientAuthService;
import com.alibaba.nacos.client.auth.spi.ClientAuthService;
import com.alibaba.nacos.common.http.client.NacosRestTemplate;
import com.alibaba.nacos.common.spi.NacosServiceLoader;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,9 +14,9 @@
* limitations under the License.
*/

package com.alibaba.nacos.client.auth;
package com.alibaba.nacos.client.auth.impl;

public class LoginAuthConstant {
public class NacosAuthLoginConstant {

public static final String ACCESSTOKEN = "accessToken";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,10 +14,12 @@
* limitations under the License.
*/

package com.alibaba.nacos.client.auth;
package com.alibaba.nacos.client.auth.impl;

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.client.auth.process.HttpLoginProcessor;
import com.alibaba.nacos.client.auth.LoginIdentityContext;
import com.alibaba.nacos.client.auth.impl.process.HttpLoginProcessor;
import com.alibaba.nacos.client.auth.spi.AbstractClientAuthService;
import com.alibaba.nacos.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -77,17 +79,17 @@ public Boolean login(Properties properties) {

for (String server : this.serverList) {
HttpLoginProcessor httpLoginProcessor = new HttpLoginProcessor(nacosRestTemplate);
properties.setProperty(LoginAuthConstant.SERVER, server);
properties.setProperty(NacosAuthLoginConstant.SERVER, server);
LoginIdentityContext identityContext = httpLoginProcessor.getResponse(properties);
if (identityContext != null) {
if (StringUtils.isNotBlank((String) identityContext.getParameter(LoginAuthConstant.ACCESSTOKEN))) {
tokenTtl = Long.parseLong((String) identityContext.getParameter(LoginAuthConstant.TOKENTTL));
if (StringUtils.isNotBlank((String) identityContext.getParameter(NacosAuthLoginConstant.ACCESSTOKEN))) {
tokenTtl = Long.parseLong((String) identityContext.getParameter(NacosAuthLoginConstant.TOKENTTL));
tokenRefreshWindow = tokenTtl / 10;
lastRefreshTime = System.currentTimeMillis();

loginIdentityContext = new LoginIdentityContext();
loginIdentityContext.setParameter(LoginAuthConstant.ACCESSTOKEN,
identityContext.getParameter(LoginAuthConstant.ACCESSTOKEN));
loginIdentityContext.setParameter(NacosAuthLoginConstant.ACCESSTOKEN,
identityContext.getParameter(NacosAuthLoginConstant.ACCESSTOKEN));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

package com.alibaba.nacos.client.auth.process;
package com.alibaba.nacos.client.auth.impl.process;

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.client.auth.LoginAuthConstant;
import com.alibaba.nacos.client.auth.impl.NacosAuthLoginConstant;
import com.alibaba.nacos.client.auth.LoginIdentityContext;
import com.alibaba.nacos.client.utils.ContextPathUtil;
import com.alibaba.nacos.common.http.HttpRestResult;
Expand Down Expand Up @@ -55,7 +55,7 @@ public LoginIdentityContext getResponse(Properties properties) {

String contextPath = ContextPathUtil
.normalizeContextPath(properties.getProperty(PropertyKeyConst.CONTEXT_PATH, webContext));
String server = properties.getProperty(LoginAuthConstant.SERVER, StringUtils.EMPTY);
String server = properties.getProperty(NacosAuthLoginConstant.SERVER, StringUtils.EMPTY);
String url = HTTP + server + contextPath + LOGIN_URL;

if (server.contains(Constants.HTTP_PREFIX)) {
Expand All @@ -79,8 +79,8 @@ public LoginIdentityContext getResponse(Properties properties) {

if (obj.has(Constants.ACCESS_TOKEN)) {
loginIdentityContext
.setParameter(LoginAuthConstant.ACCESSTOKEN, obj.get(Constants.ACCESS_TOKEN).asText());
loginIdentityContext.setParameter(LoginAuthConstant.TOKENTTL, obj.get(Constants.TOKEN_TTL).asText());
.setParameter(NacosAuthLoginConstant.ACCESSTOKEN, obj.get(Constants.ACCESS_TOKEN).asText());
loginIdentityContext.setParameter(NacosAuthLoginConstant.TOKENTTL, obj.get(Constants.TOKEN_TTL).asText());
} else {
SECURITY_LOGGER.info("[NacosClientAuthServiceImpl] ACCESS_TOKEN is empty from response");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.nacos.client.auth.process;
package com.alibaba.nacos.client.auth.impl.process;

import com.alibaba.nacos.client.auth.LoginIdentityContext;
import java.util.Properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,8 +14,9 @@
* limitations under the License.
*/

package com.alibaba.nacos.client.auth;
package com.alibaba.nacos.client.auth.spi;

import com.alibaba.nacos.client.auth.spi.ClientAuthService;
import com.alibaba.nacos.common.http.client.NacosRestTemplate;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,8 +14,9 @@
* limitations under the License.
*/

package com.alibaba.nacos.client.auth;
package com.alibaba.nacos.client.auth.spi;

import com.alibaba.nacos.client.auth.LoginIdentityContext;
import com.alibaba.nacos.common.http.client.NacosRestTemplate;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.alibaba.nacos.client.security;

import com.alibaba.nacos.client.auth.ClientAuthPluginManager;
import com.alibaba.nacos.client.auth.ClientAuthService;
import com.alibaba.nacos.client.auth.spi.ClientAuthService;
import com.alibaba.nacos.client.auth.LoginIdentityContext;
import com.alibaba.nacos.common.http.client.NacosRestTemplate;

Expand Down Expand Up @@ -82,4 +82,4 @@ public Map<String, String> getIdentityContext() {
return header;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
#
#

com.alibaba.nacos.client.auth.NacosClientAuthServiceImpl
com.alibaba.nacos.client.auth.impl.NacosClientAuthServiceImpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.client.auth;

import com.alibaba.nacos.client.auth.spi.ClientAuthService;
import com.alibaba.nacos.common.http.client.NacosRestTemplate;
import org.junit.Assert;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.nacos.client.auth;
package com.alibaba.nacos.client.auth.impl;

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.common.http.HttpRestResult;
Expand Down Expand Up @@ -160,7 +160,7 @@ public void testGetAccessToken() throws Exception {
//when
Assert.assertTrue(nacosClientAuthService.login(properties));
//then
Assert.assertEquals("abc", nacosClientAuthService.getLoginIdentityContext().getParameter(LoginAuthConstant.ACCESSTOKEN));
Assert.assertEquals("abc", nacosClientAuthService.getLoginIdentityContext().getParameter(NacosAuthLoginConstant.ACCESSTOKEN));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.alibaba.nacos.client.security;

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.client.auth.LoginAuthConstant;
import com.alibaba.nacos.client.auth.impl.NacosAuthLoginConstant;
import com.alibaba.nacos.common.http.HttpRestResult;
import com.alibaba.nacos.common.http.client.NacosRestTemplate;
import com.alibaba.nacos.common.http.param.Header;
Expand Down Expand Up @@ -72,7 +72,7 @@ public void testGetIdentityContext() {
//when
Map<String, String> keyMap = securityProxy.getIdentityContext();
//then
Assert.assertEquals("ttttttttttttttttt", keyMap.get(LoginAuthConstant.ACCESSTOKEN));
Assert.assertEquals("ttttttttttttttttt", keyMap.get(NacosAuthLoginConstant.ACCESSTOKEN));
}

}