I have a class that is designed to use the future internal authentication library (I know that existing libraries already exist). Therefore, to make it as simple as possible for developers using it in many future future projects to use this library, I had in mind their definition of enumeration with roles, simple For example, the role of sysadmin:
class Auth {
public static enum AUTH_ROLE {
sysadmin( new Rule(AdminController.class, "*") );
private String name;
AUTH_ROLE() {
name = this.name();
Roles.add( name );
}
AUTH_ROLE(String name) {
this.name = name;
Roles.add( name );
}
AUTH_ROLE(Rule rule) {
name = this.name();
Roles.add( name, rule );
}
AUTH_ROLE(String name, Rule rule) {
this.name = name;
Roles.add( name, rule );
}
public String getName() {
return name;
}
}
public boolean hasRole(AUTH_ROLE role) {
String[] usersRoles = getLoggedInUsersRoles();
for ( String userRole : usersRoles ) {
if ( role.getName().equals(userRole) )
return true;
}
return false;
}
}
, , AUTH_ROLE * * project, , Auth , .
, Auth, hasRole (AUTH_ROLE...)...
, , , ββ ONCE .
, , Java, , ( , !) , , .
, , :
public enum AUTH_ROLE extends authlibrary.Auth.AUTH_ROLE {
sysadmin( new Rule(AdminController.class, "*") );
}
, , , , , , , .
, , ...
, * * , /, , .
, - , / , ?
Ps. , :)