Skip to content

Commit

Permalink
Jraft naming (#3660)
Browse files Browse the repository at this point in the history
* fix-#3595, delete the unnecessary code (#3596)

* [ISSUE #3566] move the permission code of nacos-core module to nacos-auth module (#3593)

* move the permission code of nacos-core module to nacos-auth module.

* Fix some code style issues

* address server module auth package name change.

* test change

* Incorrect package name correction

* [ISSUE #3592] Fix incorrect prompt when accessing the restricted namespace (#3603)

* Fix incorrect prompt when accessing the restricted namespace

* Modify variable name

* [ISSUE #3600] Replace the deprecated api of jwt (#3616)

* replace the deprecated api of jwt

* transfer secretKey to byte array just using String encode with utf-8

* [ISSUE #3613]  Fix `unit test method not be static` & update publish config listener  in `ConfigTest.java` (#3614)

* fix `unit test method not be static` & update publish config listener in `ConfigTest.java`

* fix `unit test method not be static` & update publish config listener in `ConfigTest.java`

* move jwt dependency from console,core to auth. (#3624)

* fix: create kvstorage

* refactor: create kv storage]

Co-authored-by: 赵延 <[email protected]>
Co-authored-by: mai.jh <[email protected]>
Co-authored-by: ljhrot <[email protected]>
Co-authored-by: Xarrow <[email protected]>
  • Loading branch information
5 people authored Aug 21, 2020
1 parent 71c8530 commit c617afe
Show file tree
Hide file tree
Showing 65 changed files with 825 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.alibaba.nacos.address.auth;

import com.alibaba.nacos.core.auth.AccessException;
import com.alibaba.nacos.core.auth.AuthManager;
import com.alibaba.nacos.core.auth.Permission;
import com.alibaba.nacos.core.auth.User;
import com.alibaba.nacos.auth.AuthManager;
import com.alibaba.nacos.auth.exception.AccessException;
import com.alibaba.nacos.auth.model.Permission;
import com.alibaba.nacos.auth.model.User;

/**
* Address server auth manager.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.alibaba.nacos.address.configuration;

import com.alibaba.nacos.address.auth.AddressServerAuthManager;
import com.alibaba.nacos.core.auth.AuthManager;
import com.alibaba.nacos.auth.AuthManager;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
29 changes: 29 additions & 0 deletions auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,36 @@
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>nacos-common</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
* limitations under the License.
*/

package com.alibaba.nacos.core.auth;
package com.alibaba.nacos.auth;

import com.alibaba.nacos.auth.exception.AccessException;
import com.alibaba.nacos.auth.model.Permission;
import com.alibaba.nacos.auth.model.User;

/**
* Access control entry. Can be extended by 3rd party implementations.
*
* @author nkorange
* @author mai.jh
* @since 1.2.0
*/
public interface AuthManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
* limitations under the License.
*/

package com.alibaba.nacos.core.auth;
package com.alibaba.nacos.auth.annotation;

import com.alibaba.nacos.auth.common.ActionTypes;
import com.alibaba.nacos.auth.parser.DefaultResourceParser;
import com.alibaba.nacos.auth.parser.ResourceParser;
import org.apache.commons.lang3.StringUtils;

import java.lang.annotation.Retention;
Expand All @@ -25,6 +28,7 @@
* Annotation indicating that the annotated request should be authorized.
*
* @author nkorange
* @author mai.jh
* @since 1.2.0
*/
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

package com.alibaba.nacos.core.auth;
package com.alibaba.nacos.auth.common;

/**
* Resource action type definitions.
*
* @author nkorange
* @author mai.jh
* @since 1.2.0
*/
public enum ActionTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,26 @@
* limitations under the License.
*/

package com.alibaba.nacos.core.auth;
package com.alibaba.nacos.auth.common;

import com.alibaba.nacos.auth.common.env.ReloadableConfigs;
import com.alibaba.nacos.common.JustForTest;
import com.alibaba.nacos.core.env.ReloadableConfigs;
import io.jsonwebtoken.io.Decoders;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
* Auth related configurations.
*
* @author nkorange
* @author mai.jh
* @since 1.2.0
*/
@Component
@Configuration
public class AuthConfigs {

Expand All @@ -51,6 +49,11 @@ public class AuthConfigs {
@Value("${nacos.core.auth.default.token.secret.key:}")
private String secretKey;

/**
* secret key byte array.
*/
private byte[] secretKeyBytes;

/**
* Token validity time(seconds).
*/
Expand All @@ -63,8 +66,11 @@ public class AuthConfigs {
@Value("${nacos.core.auth.system.type:}")
private String nacosAuthSystemType;

public String getSecretKey() {
return secretKey;
public byte[] getSecretKeyBytes() {
if (secretKeyBytes == null) {
secretKeyBytes = Decoders.BASE64.decode(secretKey);
}
return secretKeyBytes;
}

public long getTokenValidityInSeconds() {
Expand Down Expand Up @@ -107,21 +113,4 @@ public boolean isCachingEnabled() {
public static void setCachingEnabled(boolean cachingEnabled) {
AuthConfigs.cachingEnabled = cachingEnabled;
}

@Bean
public FilterRegistrationBean authFilterRegistration() {
FilterRegistrationBean<AuthFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(authFilter());
registration.addUrlPatterns("/*");
registration.setName("authFilter");
registration.setOrder(6);

return registration;
}

@Bean
public AuthFilter authFilter() {
return new AuthFilter();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

package com.alibaba.nacos.core.auth;
package com.alibaba.nacos.auth.common;

/**
* Types of all auth implementations.
*
* @author nkorange
* @author mai.jh
* @since 1.2.0
*/
public enum AuthSystemTypes {
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.core.env;
package com.alibaba.nacos.auth.common.env;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -31,6 +31,7 @@
* Reload application.properties.
*
* @author nkorange
* @author mai.jh
* @since 1.2.0
*/
@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

package com.alibaba.nacos.core.auth;
package com.alibaba.nacos.auth.exception;

import com.alibaba.nacos.api.exception.NacosException;

/**
* Exception to be thrown if authorization is failed.
*
* @author nkorange
* @author mai.jh
* @since 1.2.0
*/
public class AccessException extends NacosException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

package com.alibaba.nacos.core.auth;
package com.alibaba.nacos.auth.model;

import java.io.Serializable;

/**
* Permission to auth.
*
* @author nkorange
* @author mai.jh
* @since 1.2.0
*/
public class Permission implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

package com.alibaba.nacos.core.auth;
package com.alibaba.nacos.auth.model;

import java.io.Serializable;

/**
* Resource used in authorization.
*
* @author nkorange
* @author mai.jh
* @since 1.2.0
*/
public class Resource implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

package com.alibaba.nacos.core.auth;
package com.alibaba.nacos.auth.model;

import java.io.Serializable;

/**
* User information in authorization.
*
* @author nkorange
* @author mai.jh
* @since 1.2.0
*/
public class User implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

package com.alibaba.nacos.core.auth;
package com.alibaba.nacos.auth.parser;

import org.apache.commons.lang3.StringUtils;

/**
* Default resource parser.
*
* @author nkorange
* @author mai.jh
* @since 1.2.0
*/
public class DefaultResourceParser implements ResourceParser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

package com.alibaba.nacos.core.auth;
package com.alibaba.nacos.auth.parser;

/**
* Resource parser.
*
* @author nkorange
* @author mai.jh
* @since 1.2.0
*/
public interface ResourceParser {
Expand Down
Loading

0 comments on commit c617afe

Please sign in to comment.