Merge branch 'master' of http://git.komect.net/ISG/secogateway
This commit is contained in:
commit
88004a6c47
|
@ -370,7 +370,6 @@ PLAT_LINUX_OBJS :=
|
|||
PLAT_LINUX_DEPS :=
|
||||
endif
|
||||
|
||||
$(info objects:[$(PLAT_LINUX_OBJS)])
|
||||
# 构建系统最终需要生成的目标,包含 ARM64 和 Linux 平台
|
||||
ALL_OBJS += $(PLAT_ARM64_OBJS) $(PLAT_LINUX_OBJS)
|
||||
ALL_DEPS += $(PLAT_ARM64_DEPS) $(PLAT_LINUX_DEPS)
|
||||
|
|
|
@ -85,6 +85,7 @@ enum commcfgmsgtype{
|
|||
COMMMSGNL_BASE = 0x10,/*netlink 保留控制消息*/
|
||||
COMMNMSG_CFG_DEBUGFS = 0x11,/*keep the same with NLMSG_PDELIV_DEBUGFS */
|
||||
FREEAUTH_CFG = 0x13, /*用户态发送给内核态的免认证规则消息*/
|
||||
AGINGTIME_CFG = 0x14, /*用户态发送给内核态的用户老化时间消息 */
|
||||
COMMNMSG_POLICYCONF,
|
||||
|
||||
NK_DEBUGFS_PRK_ONOFF_CFG = 0X16,/*keep the same with DEBUGFS PRINTK ON OR OFF */
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/* This file is auto generated,for sGATE version info */
|
||||
/* Used readelf to get this information form driver of application */
|
||||
/* "readelf --debug-dump=macro <filename>" */
|
||||
#define sGATE_COMPILE_DATE "2019-07-01"
|
||||
#define sGATE_COMPILE_TIME "17:53:10"
|
||||
#define sGATE_COMPILE_MAJOR "20190701"
|
||||
#define sGATE_COMPILE_SUB "175310"
|
||||
#define sGATE_COMPILE_BY "cl"
|
||||
#define sGATE_COMPILE_DATE "2019-07-04"
|
||||
#define sGATE_COMPILE_TIME "16:24:06"
|
||||
#define sGATE_COMPILE_MAJOR "20190704"
|
||||
#define sGATE_COMPILE_SUB "162406"
|
||||
#define sGATE_COMPILE_BY "zza"
|
||||
#define sGATE_COMPILE_HOST "esgwdev01"
|
||||
#define sGATE_GIT_TAGS "aaa812c65-dev"
|
||||
#define sGATE_GIT_VERS "aaa812c654225f595f12a32bc7d56bcc225f3ee4"
|
||||
#define sGATE_GIT_TAGS "8ab4e9178-dev"
|
||||
#define sGATE_GIT_VERS "8ab4e9178e1bfa02cef1e2de1991daf1c7593b86"
|
||||
|
|
|
@ -80,32 +80,6 @@ extern "C" {
|
|||
#define s2j_struct_get_struct_element(child_struct, to_struct, child_json, from_json, type, element) \
|
||||
S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, element)
|
||||
|
||||
/* s2j.c */
|
||||
//extern S2jHook s2jHook;
|
||||
S2jHook s2jHook = {
|
||||
.malloc_fn = malloc,
|
||||
.free_fn = free,
|
||||
};
|
||||
|
||||
static void s2j_init(S2jHook *hook)
|
||||
{
|
||||
/* initialize cJSON library */
|
||||
if(hook == NULL)
|
||||
{
|
||||
hook = &s2jHook;
|
||||
}
|
||||
|
||||
cJSON_InitHooks((cJSON_Hooks *)hook);
|
||||
/* initialize hooks */
|
||||
if (hook) {
|
||||
s2jHook.malloc_fn = (hook->malloc_fn) ? hook->malloc_fn : malloc;
|
||||
s2jHook.free_fn = (hook->free_fn) ? hook->free_fn : free;
|
||||
} else {
|
||||
s2jHook.malloc_fn = malloc;
|
||||
s2jHook.free_fn = free;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include <cjson/cJSON.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -116,11 +117,11 @@ typedef struct {
|
|||
|
||||
#define S2J_CREATE_STRUCT_OBJECT(struct_obj, type) \
|
||||
cJSON *json_temp; \
|
||||
type *struct_obj = s2jHook.malloc_fn(sizeof(type)); \
|
||||
type *struct_obj = malloc(sizeof(type)); \
|
||||
if (struct_obj) memset(struct_obj, 0, sizeof(type));
|
||||
|
||||
#define S2J_DELETE_STRUCT_OBJECT(struct_obj) \
|
||||
s2jHook.free_fn(struct_obj);
|
||||
free(struct_obj);
|
||||
|
||||
#define S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, _element) \
|
||||
S2J_STRUCT_GET_##type##_ELEMENT(to_struct, from_json, _element)
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
#ifndef USER_H_
|
||||
#define USER_H_
|
||||
#include <time.h>
|
||||
#include <stdbool.h>
|
||||
#include "user_group.h"
|
||||
|
||||
#define UNAMESIZE (127 + 1)
|
||||
#define UDESIZE (127 + 1)
|
||||
#define UPWDSIZE (63 + 1)
|
||||
#define UTIME 20
|
||||
#define USER_ATTRIBUTE_NUM 7
|
||||
|
||||
#define ADD_FAIL_NOGROUP 1
|
||||
#define ADD_FAIL_NAMELEN 2
|
||||
#define ADD_FAIL_NAMESPE 3
|
||||
#define ADD_FAIL_NAMEDUP 4
|
||||
#define ADD_FAIL_USERFULL 5
|
||||
#define ADD_SUCCESS 0
|
||||
|
||||
typedef struct user
|
||||
{
|
||||
unsigned short ID; //用户id
|
||||
unsigned short GID; //用户组ID
|
||||
unsigned short multi_valid; //多人登陆、永久有效
|
||||
char uname[UNAMESIZE]; //用户名
|
||||
char passwd[UPWDSIZE]; //密码
|
||||
char udescription[UDESIZE]; //用户描述
|
||||
time_t valid_begin_time; //有效期开始时间
|
||||
time_t valid_end_time; //有效期结束时间
|
||||
}USERACCOUNT;
|
||||
|
||||
typedef struct userlist
|
||||
{
|
||||
unsigned short ID;
|
||||
unsigned short GID;
|
||||
unsigned short multi;
|
||||
unsigned short valid;
|
||||
char uname[UNAMESIZE];
|
||||
char gname[GNAMESIZE];
|
||||
char passwd[UPWDSIZE];
|
||||
char udescription[UDESIZE];
|
||||
char valid_begin_time[UTIME];
|
||||
char valid_end_time[UTIME];
|
||||
}USERLIST;
|
||||
|
||||
typedef struct result_user_add
|
||||
{
|
||||
int result;
|
||||
int userID;
|
||||
}USERADD;
|
||||
|
||||
/*初始化参数*/
|
||||
int init_user();
|
||||
|
||||
/*添加元素-新增用户*/
|
||||
void usermanager_add_user(char* UNAME, char* UGNAME, USERADD* UADDRES);
|
||||
|
||||
/* 按用户ID查询用户 */
|
||||
void get_user_by_id(unsigned short ID, USERLIST* ULIST);
|
||||
|
||||
/* 修改用户-web */
|
||||
bool mod_user_web(USERLIST* ULIST);
|
||||
|
||||
/* 根据用户名查询用户ID */
|
||||
unsigned short get_userid_by_name(char* UNAME);
|
||||
|
||||
/* 修改用户-命令行 */
|
||||
bool mod_user_line(char* UNAME, const int INTYPE, char* IN);
|
||||
|
||||
#endif
|
|
@ -4,6 +4,16 @@
|
|||
#define GNAMESIZE (127 + 1)
|
||||
#define GDESIZE (127 + 1)
|
||||
|
||||
#define ADD_SUCCESS 0
|
||||
#define ADD_FAIL_FULL 1
|
||||
#define ADD_FAIL_LENGTH 2
|
||||
#define ADD_FAIL_SPECHARS 3
|
||||
#define ADD_FAIL_DUP 4
|
||||
|
||||
#define DEL_SUCCESS 0
|
||||
#define DEL_FAIL_NOTEXIST 1
|
||||
#define DEL_FAIL_STRTEGY 2
|
||||
|
||||
typedef struct usergroup
|
||||
{
|
||||
unsigned short ID;
|
|
@ -69,6 +69,7 @@ public class AAAShiroProvider {
|
|||
this.certificateManager = certificateManager;
|
||||
this.shiroConfiguration = shiroConfiguration;
|
||||
|
||||
//使用h2的方式做IIDMStore
|
||||
if (datastoreConfig != null && datastoreConfig.getStore()
|
||||
.equals(DatastoreConfig.Store.H2DataStore)) {
|
||||
final IdmLightConfig config = new IdmLightConfigBuilder().dbUser(dbUsername).dbPwd(dbPassword).build();
|
||||
|
|
|
@ -1,12 +1,21 @@
|
|||
/*
|
||||
* Copyright © 2016 Red Hat, Inc. and others.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.PreparedStatement;
|
||||
|
@ -16,10 +25,8 @@ import java.sql.Statement;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
* Base class for H2 stores.
|
||||
*/
|
||||
abstract class AbstractStore<T> {
|
||||
|
@ -118,8 +125,8 @@ abstract class AbstractStore<T> {
|
|||
List<T> result = new ArrayList<>();
|
||||
String query = "SELECT * FROM " + tableName;
|
||||
try (Connection conn = dbConnect();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(query)) {
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(query)) {
|
||||
while (rs.next()) {
|
||||
result.add(fromResultSet(rs));
|
||||
}
|
||||
|
@ -185,3 +192,12 @@ abstract class AbstractStore<T> {
|
|||
*/
|
||||
protected abstract T fromResultSet(ResultSet rs) throws SQLException;
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,20 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import java.sql.Connection;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
* Provider of JDBC Connections.
|
||||
* Essentially a much simplified {@link DataSource}.
|
||||
*
|
||||
* @author Michael Vorburger
|
||||
*/
|
||||
public interface ConnectionProvider {
|
||||
|
||||
|
@ -30,3 +35,12 @@ public interface ConnectionProvider {
|
|||
Connection getConnection() throws StoreException;
|
||||
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
@ -22,11 +26,11 @@ import org.opendaylight.aaa.api.model.Domains;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
* Domain store.
|
||||
*
|
||||
* @author peter.mellquist@hp.com
|
||||
*
|
||||
*/
|
||||
public class DomainStore extends AbstractStore<Domain> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DomainStore.class);
|
||||
|
@ -43,11 +47,9 @@ public class DomainStore extends AbstractStore<Domain> {
|
|||
|
||||
@Override
|
||||
protected String getTableCreationStatement() {
|
||||
return "CREATE TABLE DOMAINS "
|
||||
+ "(domainid VARCHAR(128) PRIMARY KEY,"
|
||||
return "CREATE TABLE DOMAINS " + "(domainid VARCHAR(128) PRIMARY KEY,"
|
||||
+ "name VARCHAR(128) UNIQUE NOT NULL, "
|
||||
+ "description VARCHAR(128) , "
|
||||
+ "enabled INTEGER NOT NULL)";
|
||||
+ "description VARCHAR(128) , " + "enabled INTEGER NOT NULL)";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,17 +62,29 @@ public class DomainStore extends AbstractStore<Domain> {
|
|||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的域
|
||||
* @return 所有的域
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
public Domains getDomains() throws StoreException {
|
||||
Domains domains = new Domains();
|
||||
domains.setDomains(listAll());
|
||||
return domains;
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据domainName获取所有的域
|
||||
* @param domainName 域名
|
||||
* @return 符合条件的所有的域
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
protected Domains getDomains(String domainName) throws StoreException {
|
||||
LOG.debug("getDomains for: {}", domainName);
|
||||
Domains domains = new Domains();
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM DOMAINS WHERE name = ?")) {
|
||||
PreparedStatement pstmt = conn
|
||||
.prepareStatement("SELECT * FROM DOMAINS WHERE name = ?")) {
|
||||
pstmt.setString(1, domainName);
|
||||
LOG.debug("query string: {}", pstmt.toString());
|
||||
domains.setDomains(listFromStatement(pstmt));
|
||||
|
@ -81,9 +95,16 @@ public class DomainStore extends AbstractStore<Domain> {
|
|||
return domains;
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据id获取所有的域
|
||||
* @param id id
|
||||
* @return 符合条件的所有的域
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
protected Domain getDomain(String id) throws StoreException {
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM DOMAINS WHERE domainid = ? ")) {
|
||||
PreparedStatement pstmt = conn
|
||||
.prepareStatement("SELECT * FROM DOMAINS WHERE domainid = ? ")) {
|
||||
pstmt.setString(1, id);
|
||||
LOG.debug("query string: {}", pstmt.toString());
|
||||
return firstFromStatement(pstmt);
|
||||
|
@ -93,13 +114,19 @@ public class DomainStore extends AbstractStore<Domain> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建域
|
||||
* @param domain 域名
|
||||
* @return 创建的域
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
public Domain createDomain(Domain domain) throws StoreException {
|
||||
Preconditions.checkNotNull(domain);
|
||||
Preconditions.checkNotNull(domain.getName());
|
||||
Preconditions.checkNotNull(domain.isEnabled());
|
||||
String query = "insert into DOMAINS (domainid,name,description,enabled) values(?, ?, ?, ?)";
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
statement.setString(1, domain.getName());
|
||||
statement.setString(2, domain.getName());
|
||||
statement.setString(3, domain.getDescription());
|
||||
|
@ -116,6 +143,12 @@ public class DomainStore extends AbstractStore<Domain> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改域
|
||||
* @param domain 新的域对象
|
||||
* @return 修改之后的domain
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
protected Domain putDomain(Domain domain) throws StoreException {
|
||||
Domain savedDomain = this.getDomain(domain.getDomainid());
|
||||
if (savedDomain == null) {
|
||||
|
@ -134,7 +167,7 @@ public class DomainStore extends AbstractStore<Domain> {
|
|||
|
||||
String query = "UPDATE domains SET description = ?, enabled = ?, name = ? WHERE domainid = ?";
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
statement.setString(1, savedDomain.getDescription());
|
||||
statement.setInt(2, savedDomain.isEnabled() ? 1 : 0);
|
||||
statement.setString(3, savedDomain.getName());
|
||||
|
@ -148,6 +181,12 @@ public class DomainStore extends AbstractStore<Domain> {
|
|||
return savedDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除域
|
||||
* @param domainid 要删除的域的id
|
||||
* @return 被删除的域对象
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
protected Domain deleteDomain(String domainid) throws StoreException {
|
||||
domainid = StringEscapeUtils.escapeHtml4(domainid);
|
||||
Domain deletedDomain = this.getDomain(domainid);
|
||||
|
@ -155,8 +194,7 @@ public class DomainStore extends AbstractStore<Domain> {
|
|||
return null;
|
||||
}
|
||||
String query = String.format("DELETE FROM DOMAINS WHERE domainid = '%s'", domainid);
|
||||
try (Connection conn = dbConnect();
|
||||
Statement statement = conn.createStatement()) {
|
||||
try (Connection conn = dbConnect(); Statement statement = conn.createStatement()) {
|
||||
int deleteCount = statement.executeUpdate(query);
|
||||
LOG.debug("deleted {} records", deleteCount);
|
||||
return deletedDomain;
|
||||
|
@ -166,3 +204,12 @@ public class DomainStore extends AbstractStore<Domain> {
|
|||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
@ -22,10 +27,8 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
* Grant store.
|
||||
*
|
||||
* @author peter.mellquist@hp.com
|
||||
*
|
||||
*/
|
||||
public class GrantStore extends AbstractStore<Grant> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GrantStore.class);
|
||||
|
@ -42,8 +45,7 @@ public class GrantStore extends AbstractStore<Grant> {
|
|||
|
||||
@Override
|
||||
protected String getTableCreationStatement() {
|
||||
return "CREATE TABLE GRANTS "
|
||||
+ "(grantid VARCHAR(128) PRIMARY KEY,"
|
||||
return "CREATE TABLE GRANTS " + "(grantid VARCHAR(128) PRIMARY KEY,"
|
||||
+ "domainid VARCHAR(128) NOT NULL, "
|
||||
+ "userid VARCHAR(128) NOT NULL, "
|
||||
+ "roleid VARCHAR(128) NOT NULL)";
|
||||
|
@ -64,11 +66,18 @@ public class GrantStore extends AbstractStore<Grant> {
|
|||
return grant;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Grants
|
||||
* @param did 域id
|
||||
* @param uid user id
|
||||
* @return 符合条件的Grants
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
public Grants getGrants(String did, String uid) throws StoreException {
|
||||
Grants grants = new Grants();
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement pstmt = conn
|
||||
.prepareStatement("SELECT * FROM grants WHERE domainid = ? AND userid = ?")) {
|
||||
PreparedStatement pstmt = conn.prepareStatement(
|
||||
"SELECT * FROM grants WHERE domainid = ? AND userid = ?")) {
|
||||
pstmt.setString(1, did);
|
||||
pstmt.setString(2, uid);
|
||||
LOG.debug("query string: {}", pstmt.toString());
|
||||
|
@ -79,10 +88,17 @@ public class GrantStore extends AbstractStore<Grant> {
|
|||
return grants;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Grants
|
||||
* @param userid userid
|
||||
* @return 符合条件的Grants
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
protected Grants getGrants(String userid) throws StoreException {
|
||||
Grants grants = new Grants();
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM GRANTS WHERE userid = ? ")) {
|
||||
PreparedStatement pstmt = conn
|
||||
.prepareStatement("SELECT * FROM GRANTS WHERE userid = ? ")) {
|
||||
pstmt.setString(1, userid);
|
||||
LOG.debug("query string: {}", pstmt.toString());
|
||||
grants.setGrants(listFromStatement(pstmt));
|
||||
|
@ -94,7 +110,8 @@ public class GrantStore extends AbstractStore<Grant> {
|
|||
|
||||
protected Grant getGrant(String id) throws StoreException {
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM GRANTS WHERE grantid = ? ")) {
|
||||
PreparedStatement pstmt = conn
|
||||
.prepareStatement("SELECT * FROM GRANTS WHERE grantid = ? ")) {
|
||||
pstmt.setString(1, id);
|
||||
LOG.debug("query string: ", pstmt.toString());
|
||||
return firstFromStatement(pstmt);
|
||||
|
@ -105,8 +122,8 @@ public class GrantStore extends AbstractStore<Grant> {
|
|||
|
||||
protected Grant getGrant(String did, String uid, String rid) throws StoreException {
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement pstmt = conn
|
||||
.prepareStatement("SELECT * FROM GRANTS WHERE domainid = ? AND userid = ? AND roleid = ? ")) {
|
||||
PreparedStatement pstmt = conn.prepareStatement(
|
||||
"SELECT * FROM GRANTS WHERE domainid = ? AND userid = ? AND roleid = ? ")) {
|
||||
pstmt.setString(1, did);
|
||||
pstmt.setString(2, uid);
|
||||
pstmt.setString(3, rid);
|
||||
|
@ -120,11 +137,9 @@ public class GrantStore extends AbstractStore<Grant> {
|
|||
protected Grant createGrant(Grant grant) throws StoreException {
|
||||
String query = "insert into grants (grantid,domainid,userid,roleid) values(?,?,?,?)";
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
statement.setString(
|
||||
1,
|
||||
IDMStoreUtil.createGrantid(grant.getUserid(), grant.getDomainid(),
|
||||
grant.getRoleid()));
|
||||
PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
statement.setString(1, IDMStoreUtil.createGrantid(grant.getUserid(),
|
||||
grant.getDomainid(), grant.getRoleid()));
|
||||
statement.setString(2, grant.getDomainid());
|
||||
statement.setString(3, grant.getUserid());
|
||||
statement.setString(4, grant.getRoleid());
|
||||
|
@ -148,8 +163,7 @@ public class GrantStore extends AbstractStore<Grant> {
|
|||
}
|
||||
|
||||
String query = String.format("DELETE FROM GRANTS WHERE grantid = '%s'", grantid);
|
||||
try (Connection conn = dbConnect();
|
||||
Statement statement = conn.createStatement()) {
|
||||
try (Connection conn = dbConnect(); Statement statement = conn.createStatement()) {
|
||||
int deleteCount = statement.executeUpdate(query);
|
||||
LOG.debug("deleted {} records", deleteCount);
|
||||
return savedGrant;
|
||||
|
@ -158,3 +172,12 @@ public class GrantStore extends AbstractStore<Grant> {
|
|||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Cisco Systems and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import org.opendaylight.aaa.api.IDMStoreException;
|
||||
|
@ -22,6 +27,9 @@ import org.opendaylight.aaa.api.model.Users;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
*/
|
||||
public class H2Store implements IIDMStore {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(H2Store.class);
|
||||
|
@ -265,7 +273,8 @@ public class H2Store implements IIDMStore {
|
|||
}
|
||||
|
||||
public User createUser(String name, String password, String domain, String description,
|
||||
String email, boolean enabled, String salt) throws StoreException {
|
||||
String email, boolean enabled, String salt)
|
||||
throws StoreException {
|
||||
User user = new User();
|
||||
user.setName(name);
|
||||
user.setDomainid(domain);
|
||||
|
@ -277,8 +286,7 @@ public class H2Store implements IIDMStore {
|
|||
return userStore.createUser(user);
|
||||
}
|
||||
|
||||
public Role createRole(String name, String domain, String description)
|
||||
throws StoreException {
|
||||
public Role createRole(String name, String domain, String description) throws StoreException {
|
||||
Role role = new Role();
|
||||
role.setDescription(description);
|
||||
role.setName(name);
|
||||
|
@ -295,3 +303,12 @@ public class H2Store implements IIDMStore {
|
|||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,21 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Inocybe Technologies. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.Element;
|
||||
import net.sf.ehcache.config.CacheConfiguration;
|
||||
import org.opendaylight.aaa.api.Authentication;
|
||||
import org.opendaylight.aaa.api.TokenStore;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.Element;
|
||||
import net.sf.ehcache.config.CacheConfiguration;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
* 利用Ehcache缓存框架实现token的缓存
|
||||
* Ehcache缓存框架支持restart的情况
|
||||
*/
|
||||
public class H2TokenStore implements AutoCloseable, TokenStore {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(H2TokenStore.class);
|
||||
|
@ -27,6 +39,11 @@ public class H2TokenStore implements AutoCloseable, TokenStore {
|
|||
private int maxCachedTokensOnDisk = 100000;
|
||||
private final Cache tokens;
|
||||
|
||||
/**
|
||||
* 全局设置/创建 H2TokenStore
|
||||
* @param secondsToLive 全局设置token的有效期
|
||||
* @param secondsToIdle 全局设置token的闲置时间
|
||||
*/
|
||||
public H2TokenStore(long secondsToLive, long secondsToIdle) {
|
||||
// When we restart, the cache manager and token cache are already there
|
||||
CacheManager cm = CacheManager.getCacheManager(TOKEN_CACHE_MANAGER);
|
||||
|
@ -39,8 +56,7 @@ public class H2TokenStore implements AutoCloseable, TokenStore {
|
|||
tokens = existingCache;
|
||||
} else {
|
||||
tokens = new Cache(new CacheConfiguration(TOKEN_CACHE, maxCachedTokensInMemory)
|
||||
.maxEntriesLocalDisk(maxCachedTokensOnDisk)
|
||||
.timeToLiveSeconds(secondsToLive)
|
||||
.maxEntriesLocalDisk(maxCachedTokensOnDisk).timeToLiveSeconds(secondsToLive)
|
||||
.timeToIdleSeconds(secondsToIdle));
|
||||
cm.addCache(tokens);
|
||||
}
|
||||
|
@ -73,4 +89,13 @@ public class H2TokenStore implements AutoCloseable, TokenStore {
|
|||
public long tokenExpiration() {
|
||||
return tokens.getCacheConfiguration().getTimeToLiveSeconds();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import java.io.File;
|
||||
import org.immutables.value.Value;
|
||||
import org.immutables.value.Value.Default;
|
||||
import org.immutables.value.Value.Immutable;
|
||||
|
@ -16,17 +20,15 @@ import org.immutables.value.Value.Style.ImplementationVisibility;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
* Responsible for providing configuration properties for the IDMLight/H2 data
|
||||
* store implementation.
|
||||
*
|
||||
* @author peter.mellquist@hp.com - Initial contribution
|
||||
* @author Michael Vorburger.ch - Made it configurable, as Immutable with
|
||||
* Builder
|
||||
*/
|
||||
@Immutable
|
||||
@Value.Style(stagedBuilder = true, strictBuilder = true, builder = "new",
|
||||
typeImmutable = "*Impl", visibility = ImplementationVisibility.PRIVATE)
|
||||
@Value.Style(stagedBuilder = true, strictBuilder = true, builder = "new", typeImmutable = "*Impl", visibility = ImplementationVisibility.PRIVATE)
|
||||
public abstract class IdmLightConfig {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(IdmLightConfig.class);
|
||||
|
@ -129,3 +131,12 @@ public abstract class IdmLightConfig {
|
|||
return getDbConnectionString();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017 Red Hat, Inc. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
@ -12,10 +19,9 @@ import java.sql.DriverManager;
|
|||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
* Simple Provider of JDBC Connections, based on an {@link IdmLightConfig} and
|
||||
* {@link DriverManager}.
|
||||
*
|
||||
* @author Michael Vorburger
|
||||
*/
|
||||
public class IdmLightSimpleConnectionProvider implements ConnectionProvider {
|
||||
|
||||
|
@ -31,8 +37,8 @@ public class IdmLightSimpleConnectionProvider implements ConnectionProvider {
|
|||
public Connection getConnection() throws StoreException {
|
||||
try {
|
||||
if (existingConnection == null || existingConnection.isClosed()) {
|
||||
existingConnection = DriverManager.getConnection(config.getDbConnectionString(), config.getDbUser(),
|
||||
config.getDbPwd());
|
||||
existingConnection = DriverManager.getConnection(config.getDbConnectionString(),
|
||||
config.getDbUser(), config.getDbPwd());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new StoreException("Cannot connect to database server", e);
|
||||
|
@ -40,3 +46,12 @@ public class IdmLightSimpleConnectionProvider implements ConnectionProvider {
|
|||
return existingConnection;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
@ -23,11 +27,11 @@ import org.opendaylight.aaa.api.model.Roles;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
* Store for roles.
|
||||
*
|
||||
* @author peter.mellquist@hp.com
|
||||
*
|
||||
*/
|
||||
public class RoleStore extends AbstractStore<Role> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RoleStore.class);
|
||||
|
@ -64,15 +68,27 @@ public class RoleStore extends AbstractStore<Role> {
|
|||
return role;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的角色
|
||||
* @return 所有的角色
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
public Roles getRoles() throws StoreException {
|
||||
Roles roles = new Roles();
|
||||
roles.setRoles(listAll());
|
||||
return roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据id获取指定的角色
|
||||
* @param id 角色的id
|
||||
* @return id对应的角色
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
protected Role getRole(String id) throws StoreException {
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM ROLES WHERE roleid = ? ")) {
|
||||
PreparedStatement pstmt = conn
|
||||
.prepareStatement("SELECT * FROM ROLES WHERE roleid = ? ")) {
|
||||
pstmt.setString(1, id);
|
||||
LOG.debug("query string: {}", pstmt.toString());
|
||||
return firstFromStatement(pstmt);
|
||||
|
@ -81,12 +97,19 @@ public class RoleStore extends AbstractStore<Role> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建角色
|
||||
* @param role 准备被创建的角色对象
|
||||
* @return 被创建的角色
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
protected Role createRole(Role role) throws StoreException {
|
||||
Preconditions.checkNotNull(role);
|
||||
Preconditions.checkNotNull(role.getName());
|
||||
Preconditions.checkNotNull(role.getDomainid());
|
||||
String query = "insert into roles (roleid,domainid,name,description) values(?,?,?,?)";
|
||||
try (Connection conn = dbConnect(); PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
role.setRoleid(IDMStoreUtil.createRoleid(role.getName(), role.getDomainid()));
|
||||
statement.setString(1, role.getRoleid());
|
||||
statement.setString(2, role.getDomainid());
|
||||
|
@ -102,6 +125,12 @@ public class RoleStore extends AbstractStore<Role> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改角色
|
||||
* @param role 准备被修改的角色对象
|
||||
* @return 被修改的角色
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
protected Role putRole(Role role) throws StoreException {
|
||||
|
||||
Role savedRole = this.getRole(role.getRoleid());
|
||||
|
@ -117,7 +146,8 @@ public class RoleStore extends AbstractStore<Role> {
|
|||
}
|
||||
|
||||
String query = "UPDATE roles SET description = ? WHERE roleid = ?";
|
||||
try (Connection conn = dbConnect(); PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
statement.setString(1, savedRole.getDescription());
|
||||
statement.setString(2, savedRole.getRoleid());
|
||||
statement.executeUpdate();
|
||||
|
@ -128,6 +158,12 @@ public class RoleStore extends AbstractStore<Role> {
|
|||
return savedRole;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定的角色
|
||||
* @param roleid 准备被删除的角色id
|
||||
* @return 被删除的角色
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
protected Role deleteRole(String roleid) throws StoreException {
|
||||
roleid = StringEscapeUtils.escapeHtml4(roleid);
|
||||
Role savedRole = this.getRole(roleid);
|
||||
|
@ -145,3 +181,12 @@ public class RoleStore extends AbstractStore<Role> {
|
|||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,30 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2016 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
* 自定义的异常类型
|
||||
* Exception indicating an error in an H2 data store.
|
||||
*
|
||||
* @author peter.mellquist@hp.com
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class StoreException extends Exception {
|
||||
|
||||
/**
|
||||
* 重载的构造方法
|
||||
* @param message message
|
||||
*/
|
||||
public StoreException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载的构造方法
|
||||
* @param message message
|
||||
* @param cause cause
|
||||
*/
|
||||
public StoreException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载的构造方法
|
||||
* @param cause cause
|
||||
*/
|
||||
public StoreException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
@ -24,11 +28,11 @@ import org.opendaylight.aaa.api.model.Users;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
* Store for users.
|
||||
*
|
||||
* @author peter.mellquist@hp.com
|
||||
*
|
||||
*/
|
||||
public class UserStore extends AbstractStore<User> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UserStore.class);
|
||||
|
@ -50,9 +54,12 @@ public class UserStore extends AbstractStore<User> {
|
|||
@Override
|
||||
protected String getTableCreationStatement() {
|
||||
return "CREATE TABLE users " + "(userid VARCHAR(128) PRIMARY KEY,"
|
||||
+ "name VARCHAR(128) NOT NULL, " + "domainid VARCHAR(128) NOT NULL, "
|
||||
+ "email VARCHAR(128) NOT NULL, " + "password VARCHAR(128) NOT NULL, "
|
||||
+ "description VARCHAR(128) NOT NULL, " + "salt VARCHAR(15) NOT NULL, "
|
||||
+ "name VARCHAR(128) NOT NULL, "
|
||||
+ "domainid VARCHAR(128) NOT NULL, "
|
||||
+ "email VARCHAR(128) NOT NULL, "
|
||||
+ "password VARCHAR(128) NOT NULL, "
|
||||
+ "description VARCHAR(128) NOT NULL, "
|
||||
+ "salt VARCHAR(15) NOT NULL, "
|
||||
+ "enabled INTEGER NOT NULL)";
|
||||
}
|
||||
|
||||
|
@ -75,18 +82,31 @@ public class UserStore extends AbstractStore<User> {
|
|||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的用户
|
||||
* @return 当前系统中所有的用户
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
public Users getUsers() throws StoreException {
|
||||
Users users = new Users();
|
||||
users.setUsers(listAll());
|
||||
return users;
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据域名和用户名获取用户
|
||||
* @param username username的字符串
|
||||
* @param domain domain的字符串
|
||||
* @return 对应的Users
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
protected Users getUsers(String username, String domain) throws StoreException {
|
||||
LOG.debug("getUsers for: {} in domain {}", username, domain);
|
||||
|
||||
Users users = new Users();
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM USERS WHERE userid = ? ")) {
|
||||
PreparedStatement pstmt = conn
|
||||
.prepareStatement("SELECT * FROM USERS WHERE userid = ? ")) {
|
||||
pstmt.setString(1, IDMStoreUtil.createUserid(username, domain));
|
||||
LOG.debug("query string: {}", pstmt.toString());
|
||||
users.setUsers(listFromStatement(pstmt));
|
||||
|
@ -96,9 +116,16 @@ public class UserStore extends AbstractStore<User> {
|
|||
return users;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定id的用户
|
||||
* @param id 指定的id
|
||||
* @return 对应的User
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
public User getUser(String id) throws StoreException {
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM USERS WHERE userid = ? ")) {
|
||||
PreparedStatement pstmt = conn
|
||||
.prepareStatement("SELECT * FROM USERS WHERE userid = ? ")) {
|
||||
pstmt.setString(1, id);
|
||||
LOG.debug("query string: {}", pstmt.toString());
|
||||
return firstFromStatement(pstmt);
|
||||
|
@ -107,22 +134,28 @@ public class UserStore extends AbstractStore<User> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
* @param user 准备被创建的用户对象
|
||||
* @return 被创建的用户
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
protected User createUser(User user) throws StoreException {
|
||||
Preconditions.checkNotNull(user);
|
||||
Preconditions.checkNotNull(user.getName());
|
||||
Preconditions.checkNotNull(user.getDomainid());
|
||||
|
||||
user.setSalt(SHA256Calculator.generateSALT());
|
||||
String query =
|
||||
"insert into users"
|
||||
String query = "insert into users"
|
||||
+ " (userid,domainid,name,email,password,description,enabled,salt) values(?,?,?,?,?,?,?,?)";
|
||||
try (Connection conn = dbConnect(); PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
user.setUserid(IDMStoreUtil.createUserid(user.getName(), user.getDomainid()));
|
||||
statement.setString(1, user.getUserid());
|
||||
statement.setString(2, user.getDomainid());
|
||||
statement.setString(3, user.getName());
|
||||
statement.setString(4, user.getEmail());
|
||||
statement.setString(5, SHA256Calculator.getSHA256(user.getPassword(), user.getSalt()));
|
||||
statement.setString(5, SHA256Calculator.getSHA256(user.getPassword(), user.getSalt()));//存储的是密码的SHA256的hash值
|
||||
statement.setString(6, user.getDescription());
|
||||
statement.setInt(7, user.isEnabled() ? 1 : 0);
|
||||
statement.setString(8, user.getSalt());
|
||||
|
@ -136,6 +169,12 @@ public class UserStore extends AbstractStore<User> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
* @param user 准备被修改的用户对象
|
||||
* @return 被修改的用户
|
||||
* @throws StoreException 被修改的用户
|
||||
*/
|
||||
public User putUser(User user) throws StoreException {
|
||||
|
||||
User savedUser = this.getUser(user.getUserid());
|
||||
|
@ -166,7 +205,8 @@ public class UserStore extends AbstractStore<User> {
|
|||
}
|
||||
|
||||
String query = "UPDATE users SET email = ?, password = ?, description = ?, enabled = ? WHERE userid = ?";
|
||||
try (Connection conn = dbConnect(); PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
try (Connection conn = dbConnect();
|
||||
PreparedStatement statement = conn.prepareStatement(query)) {
|
||||
statement.setString(1, savedUser.getEmail());
|
||||
statement.setString(2, savedUser.getPassword());
|
||||
statement.setString(3, savedUser.getDescription());
|
||||
|
@ -180,6 +220,12 @@ public class UserStore extends AbstractStore<User> {
|
|||
return savedUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
* @param userid 准备被删除的用户id
|
||||
* @return 被删除的用户
|
||||
* @throws StoreException StoreException
|
||||
*/
|
||||
protected User deleteUser(String userid) throws StoreException {
|
||||
userid = StringEscapeUtils.escapeHtml4(userid);
|
||||
User savedUser = this.getUser(userid);
|
||||
|
@ -197,3 +243,12 @@ public class UserStore extends AbstractStore<User> {
|
|||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,26 +1,20 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.shiro.idm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.opendaylight.aaa.AAAShiroProvider;
|
||||
import org.opendaylight.aaa.api.IDMStoreException;
|
||||
import org.opendaylight.aaa.api.model.Claim;
|
||||
import org.opendaylight.aaa.api.model.Domain;
|
||||
|
@ -33,19 +27,31 @@ import org.opendaylight.aaa.api.model.Roles;
|
|||
import org.opendaylight.aaa.api.model.User;
|
||||
import org.opendaylight.aaa.api.model.UserPwd;
|
||||
import org.opendaylight.aaa.api.model.Users;
|
||||
import org.opendaylight.aaa.AAAShiroProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
*
|
||||
* REST application used to manipulate the H2 database domains table. The REST
|
||||
* endpoint is <code>/auth/v1/domains</code>.
|
||||
*
|
||||
* <p>
|
||||
* A wrapper script called <code>idmtool</code> is provided to manipulate AAA
|
||||
* data.
|
||||
*
|
||||
* @author peter.mellquist@hp.com
|
||||
*/
|
||||
@Path("/v1/domains")
|
||||
public class DomainHandler {
|
||||
|
@ -167,7 +173,8 @@ public class DomainHandler {
|
|||
@Path("/{id}")
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public Response putDomain(@Context UriInfo info, Domain domain, @PathParam("id") String domainId) {
|
||||
public Response putDomain(@Context UriInfo info, Domain domain,
|
||||
@PathParam("id") String domainId) {
|
||||
LOG.info("Put /domains/{}", domainId);
|
||||
try {
|
||||
domain.setDomainid(domainId);
|
||||
|
@ -241,7 +248,7 @@ public class DomainHandler {
|
|||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public Response createGrant(@Context UriInfo info, @PathParam("did") String domainId,
|
||||
@PathParam("uid") String userId, Grant grant) {
|
||||
@PathParam("uid") String userId, Grant grant) {
|
||||
LOG.info("Post /domains/{}/users/{}/roles", domainId, userId);
|
||||
|
||||
// Bug 8382: grant id is an implementation detail and isn't specifiable
|
||||
|
@ -317,10 +324,12 @@ public class DomainHandler {
|
|||
|
||||
// see if grant already exists for this
|
||||
try {
|
||||
Grant existingGrant = AAAShiroProvider.getInstance().getIdmStore().readGrant(domainId, userId, roleId);
|
||||
Grant existingGrant = AAAShiroProvider.getInstance().getIdmStore().readGrant(domainId,
|
||||
userId, roleId);
|
||||
if (existingGrant != null) {
|
||||
IDMError idmerror = new IDMError();
|
||||
idmerror.setMessage("Grant already exists for did:" + domainId + " uid:" + userId + " rid:" + roleId);
|
||||
idmerror.setMessage("Grant already exists for did:" + domainId + " uid:" + userId
|
||||
+ " rid:" + roleId);
|
||||
return Response.status(403).entity(idmerror).build();
|
||||
}
|
||||
} catch (IDMStoreException e) {
|
||||
|
@ -361,7 +370,8 @@ public class DomainHandler {
|
|||
@Path("/{did}/users/roles")
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public Response validateUser(@Context UriInfo info, @PathParam("did") String domainId, UserPwd userpwd) {
|
||||
public Response validateUser(@Context UriInfo info, @PathParam("did") String domainId,
|
||||
UserPwd userpwd) {
|
||||
LOG.info("GET /domains/{}/users", domainId);
|
||||
Domain domain = null;
|
||||
Claim claim = new Claim();
|
||||
|
@ -417,11 +427,13 @@ public class DomainHandler {
|
|||
claim.setUsername(username);
|
||||
claim.setUserid(user.getUserid());
|
||||
try {
|
||||
Grants grants = AAAShiroProvider.getInstance().getIdmStore().getGrants(domainId, user.getUserid());
|
||||
Grants grants = AAAShiroProvider.getInstance().getIdmStore().getGrants(domainId,
|
||||
user.getUserid());
|
||||
List<Grant> grantsList = grants.getGrants();
|
||||
for (int i = 0; i < grantsList.size(); i++) {
|
||||
Grant grant = grantsList.get(i);
|
||||
Role role = AAAShiroProvider.getInstance().getIdmStore().readRole(grant.getRoleid());
|
||||
Role role = AAAShiroProvider.getInstance().getIdmStore()
|
||||
.readRole(grant.getRoleid());
|
||||
roleList.add(role);
|
||||
}
|
||||
} catch (IDMStoreException e) {
|
||||
|
@ -458,7 +470,7 @@ public class DomainHandler {
|
|||
@Path("/{did}/users/{uid}/roles")
|
||||
@Produces("application/json")
|
||||
public Response getRoles(@Context UriInfo info, @PathParam("did") String domainId,
|
||||
@PathParam("uid") String userId) {
|
||||
@PathParam("uid") String userId) {
|
||||
LOG.info("GET /domains/{}/users/{}/roles", domainId, userId);
|
||||
Domain domain = null;
|
||||
User user;
|
||||
|
@ -495,11 +507,13 @@ public class DomainHandler {
|
|||
}
|
||||
|
||||
try {
|
||||
Grants grants = AAAShiroProvider.getInstance().getIdmStore().getGrants(domainId, userId);
|
||||
Grants grants = AAAShiroProvider.getInstance().getIdmStore().getGrants(domainId,
|
||||
userId);
|
||||
List<Grant> grantsList = grants.getGrants();
|
||||
for (int i = 0; i < grantsList.size(); i++) {
|
||||
Grant grant = grantsList.get(i);
|
||||
Role role = AAAShiroProvider.getInstance().getIdmStore().readRole(grant.getRoleid());
|
||||
Role role = AAAShiroProvider.getInstance().getIdmStore()
|
||||
.readRole(grant.getRoleid());
|
||||
roleList.add(role);
|
||||
}
|
||||
} catch (IDMStoreException e) {
|
||||
|
@ -530,7 +544,7 @@ public class DomainHandler {
|
|||
@DELETE
|
||||
@Path("/{did}/users/{uid}/roles/{rid}")
|
||||
public Response deleteGrant(@Context UriInfo info, @PathParam("did") String domainId,
|
||||
@PathParam("uid") String userId, @PathParam("rid") String roleId) {
|
||||
@PathParam("uid") String userId, @PathParam("rid") String roleId) {
|
||||
Domain domain = null;
|
||||
User user;
|
||||
Role role;
|
||||
|
@ -582,13 +596,16 @@ public class DomainHandler {
|
|||
|
||||
// see if grant already exists
|
||||
try {
|
||||
Grant existingGrant = AAAShiroProvider.getInstance().getIdmStore().readGrant(domainId, userId, roleId);
|
||||
Grant existingGrant = AAAShiroProvider.getInstance().getIdmStore().readGrant(domainId,
|
||||
userId, roleId);
|
||||
if (existingGrant == null) {
|
||||
IDMError idmerror = new IDMError();
|
||||
idmerror.setMessage("Grant does not exist for did:" + domainId + " uid:" + userId + " rid:" + roleId);
|
||||
idmerror.setMessage("Grant does not exist for did:" + domainId + " uid:" + userId
|
||||
+ " rid:" + roleId);
|
||||
return Response.status(404).entity(idmerror).build();
|
||||
}
|
||||
existingGrant = AAAShiroProvider.getInstance().getIdmStore().deleteGrant(existingGrant.getGrantid());
|
||||
existingGrant = AAAShiroProvider.getInstance().getIdmStore()
|
||||
.deleteGrant(existingGrant.getGrantid());
|
||||
} catch (IDMStoreException e) {
|
||||
LOG.error("StoreException", e);
|
||||
IDMError idmerror = new IDMError();
|
||||
|
@ -600,3 +617,12 @@ public class DomainHandler {
|
|||
return Response.status(204).build();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,22 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.shiro.idm;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.ws.rs.core.Application;
|
||||
import org.opendaylight.aaa.provider.GsonProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.ws.rs.core.Application;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
*
|
||||
* A JAX-RS application for IdmLight. The REST endpoints delivered by this
|
||||
* application are in the form: <code>http://{HOST}:{PORT}/auth/v1/</code>
|
||||
*
|
||||
|
@ -28,10 +37,9 @@ import org.slf4j.LoggerFactory;
|
|||
* This application is responsible for interaction with the backing h2 database
|
||||
* store.
|
||||
*
|
||||
* @author liemmn
|
||||
* @see <code>org.opendaylight.aaa.shiro.idm.rest.DomainHandler</code>
|
||||
* @see <code>org.opendaylight.aaa.shiro.idm.rest.UserHandler</code>
|
||||
* @see <code>org.opendaylight.aaa.shiro.idm.rest.RoleHandler</code>
|
||||
* @see <code>org.opendaylight.aaa.shiro.idm.DomainHandler</code>
|
||||
* @see <code>org.opendaylight.aaa.shiro.idm.UserHandler</code>
|
||||
* @see <code>org.opendaylight.aaa.shiro.idm.RoleHandler</code>
|
||||
*/
|
||||
public class IdmLightApplication extends Application {
|
||||
|
||||
|
@ -49,7 +57,16 @@ public class IdmLightApplication extends Application {
|
|||
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return new HashSet<>(Arrays.asList(GsonProvider.class,
|
||||
DomainHandler.class, RoleHandler.class, UserHandler.class));
|
||||
return new HashSet<>(Arrays.asList(GsonProvider.class, DomainHandler.class,
|
||||
RoleHandler.class, UserHandler.class));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2015 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.shiro.idm;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.opendaylight.aaa.AAAShiroProvider;
|
||||
import org.opendaylight.aaa.api.AuthenticationException;
|
||||
import org.opendaylight.aaa.api.Claim;
|
||||
|
@ -35,7 +35,14 @@ import org.opendaylight.aaa.shiro.tokenauthrealm.auth.ClaimBuilder;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
*
|
||||
* An OSGi proxy for the IdmLight server.
|
||||
*/
|
||||
public class IdmLightProxy implements CredentialAuth<PasswordCredentials>, IdMService {
|
||||
|
@ -60,7 +67,7 @@ public class IdmLightProxy implements CredentialAuth<PasswordCredentials>, IdMSe
|
|||
Preconditions.checkNotNull(creds);
|
||||
Preconditions.checkNotNull(creds.username());
|
||||
Preconditions.checkNotNull(creds.password());
|
||||
String domain = creds.domain() == null ? IIDMStore.DEFAULT_DOMAIN : creds.domain();
|
||||
String domain = (creds.domain() == null ? IIDMStore.DEFAULT_DOMAIN : creds.domain());
|
||||
// FIXME: Add cache invalidation
|
||||
Map<PasswordCredentials, Claim> cache = claimCache.get(domain);
|
||||
if (cache == null) {
|
||||
|
@ -92,10 +99,15 @@ public class IdmLightProxy implements CredentialAuth<PasswordCredentials>, IdMSe
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据凭证,获取Claim,会访问IIDMStore,验证密码
|
||||
* @param creds 凭证
|
||||
* @return 获取的Claim
|
||||
*/
|
||||
private static Claim dbAuthenticate(PasswordCredentials creds) {
|
||||
Domain domain = null;
|
||||
User user = null;
|
||||
String credsDomain = creds.domain() == null ? IIDMStore.DEFAULT_DOMAIN : creds.domain();
|
||||
String credsDomain = (creds.domain() == null ? IIDMStore.DEFAULT_DOMAIN : creds.domain());
|
||||
// check to see domain exists
|
||||
// TODO: ensure domain names are unique change to 'getDomain'
|
||||
LOG.debug("get domain");
|
||||
|
@ -111,15 +123,16 @@ public class IdmLightProxy implements CredentialAuth<PasswordCredentials>, IdMSe
|
|||
// check to see user exists and passes cred check
|
||||
try {
|
||||
LOG.debug("check user / pwd");
|
||||
Users users = AAAShiroProvider.getInstance().getIdmStore().getUsers(creds.username(), credsDomain);
|
||||
Users users = AAAShiroProvider.getInstance().getIdmStore().getUsers(creds.username(),
|
||||
credsDomain);
|
||||
List<User> userList = users.getUsers();
|
||||
if (userList.size() == 0) {
|
||||
throw new AuthenticationException("User :" + creds.username()
|
||||
+ " does not exist in domain " + credsDomain);
|
||||
throw new AuthenticationException(
|
||||
"User :" + creds.username() + " does not exist in domain " + credsDomain);
|
||||
}
|
||||
user = userList.get(0);
|
||||
if (!SHA256Calculator.getSHA256(creds.password(), user.getSalt()).equals(
|
||||
user.getPassword())) {
|
||||
if (!SHA256Calculator.getSHA256(creds.password(), user.getSalt())
|
||||
.equals(user.getPassword())) {
|
||||
throw new AuthenticationException("UserName / Password not found");
|
||||
}
|
||||
if (!user.isEnabled()) {
|
||||
|
@ -129,12 +142,13 @@ public class IdmLightProxy implements CredentialAuth<PasswordCredentials>, IdMSe
|
|||
// get all grants & roles for this domain and user
|
||||
LOG.debug("get grants");
|
||||
List<String> roles = new ArrayList<>();
|
||||
Grants grants = AAAShiroProvider.getInstance().getIdmStore().getGrants(domain.getDomainid(),
|
||||
user.getUserid());
|
||||
Grants grants = AAAShiroProvider.getInstance().getIdmStore()
|
||||
.getGrants(domain.getDomainid(), user.getUserid());
|
||||
List<Grant> grantList = grants.getGrants();
|
||||
for (int z = 0; z < grantList.size(); z++) {
|
||||
Grant grant = grantList.get(z);
|
||||
Role role = AAAShiroProvider.getInstance().getIdmStore().readRole(grant.getRoleid());
|
||||
Role role = AAAShiroProvider.getInstance().getIdmStore()
|
||||
.readRole(grant.getRoleid());
|
||||
if (role != null) {
|
||||
roles.add(role.getName());
|
||||
}
|
||||
|
@ -162,7 +176,8 @@ public class IdmLightProxy implements CredentialAuth<PasswordCredentials>, IdMSe
|
|||
|
||||
@Override
|
||||
public List<String> listRoles(String userId, String domainName) {
|
||||
return new IdMServiceImpl(AAAShiroProvider.getInstance().getIdmStore()).listRoles(userId, domainName);
|
||||
return new IdMServiceImpl(AAAShiroProvider.getInstance().getIdmStore()).listRoles(userId,
|
||||
domainName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,3 +185,12 @@ public class IdmLightProxy implements CredentialAuth<PasswordCredentials>, IdMSe
|
|||
return new IdMServiceImpl(AAAShiroProvider.getInstance().getIdmStore()).listUserIDs();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,13 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.shiro.idm;
|
||||
|
||||
import org.opendaylight.aaa.AAAShiroProvider;
|
||||
import org.opendaylight.aaa.api.IDMStoreException;
|
||||
import org.opendaylight.aaa.api.model.IDMError;
|
||||
import org.opendaylight.aaa.api.model.Role;
|
||||
import org.opendaylight.aaa.api.model.Roles;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
|
@ -20,15 +34,9 @@ import javax.ws.rs.core.Context;
|
|||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.opendaylight.aaa.AAAShiroProvider;
|
||||
import org.opendaylight.aaa.api.IDMStoreException;
|
||||
import org.opendaylight.aaa.api.model.IDMError;
|
||||
import org.opendaylight.aaa.api.model.Role;
|
||||
import org.opendaylight.aaa.api.model.Roles;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
*
|
||||
* REST application used to manipulate the H2 database roles table. The REST
|
||||
* endpoint is <code>/auth/v1/roles</code>.
|
||||
*
|
||||
|
@ -36,7 +44,6 @@ import org.slf4j.LoggerFactory;
|
|||
* A wrapper script called <code>idmtool</code> is provided to manipulate AAA
|
||||
* data.
|
||||
*
|
||||
* @author peter.mellquist@hp.com
|
||||
*/
|
||||
@Path("/v1/roles")
|
||||
public class RoleHandler {
|
||||
|
@ -227,3 +234,12 @@ public class RoleHandler {
|
|||
return Response.status(204).build();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,14 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.shiro.idm;
|
||||
|
||||
import java.util.Collection;
|
||||
import org.opendaylight.aaa.AAAShiroProvider;
|
||||
import org.opendaylight.aaa.api.IDMStoreException;
|
||||
import org.opendaylight.aaa.api.model.IDMError;
|
||||
import org.opendaylight.aaa.api.model.User;
|
||||
import org.opendaylight.aaa.api.model.Users;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
|
@ -21,15 +33,11 @@ import javax.ws.rs.Produces;
|
|||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.opendaylight.aaa.api.IDMStoreException;
|
||||
import org.opendaylight.aaa.api.model.IDMError;
|
||||
import org.opendaylight.aaa.api.model.User;
|
||||
import org.opendaylight.aaa.api.model.Users;
|
||||
import org.opendaylight.aaa.AAAShiroProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
*
|
||||
* REST application used to manipulate the H2 database users table. The REST
|
||||
* endpoint is <code>/auth/v1/users</code>.
|
||||
*
|
||||
|
@ -37,7 +45,6 @@ import org.slf4j.LoggerFactory;
|
|||
* A wrapper script called <code>idmtool</code> is provided to manipulate AAA
|
||||
* data.
|
||||
*
|
||||
* @author peter.mellquist@hp.com
|
||||
*/
|
||||
@Path("/v1/users")
|
||||
public class UserHandler {
|
||||
|
@ -409,3 +416,12 @@ public class UserHandler {
|
|||
return inputField != null && inputField.length() > IdmLightApplication.MAX_FIELD_LEN;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.opendaylight.aaa.api.model.Domain;
|
||||
import org.opendaylight.aaa.api.model.Domains;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
|
@ -21,11 +25,18 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.opendaylight.aaa.api.model.Domain;
|
||||
import org.opendaylight.aaa.api.model.Domains;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* @author Dong Xiancun
|
||||
*
|
||||
*/
|
||||
public class DomainStoreTest {
|
||||
|
||||
private final Connection connectionMock = mock(Connection.class);
|
||||
|
@ -61,7 +72,8 @@ public class DomainStoreTest {
|
|||
|
||||
@Test
|
||||
public void deleteDomainsTest() throws SQLException, Exception {
|
||||
DomainStore ds = new DomainStore(new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
DomainStore ds = new DomainStore(
|
||||
new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
String domainId = "Testing12345";
|
||||
|
||||
// Run Test
|
||||
|
@ -70,6 +82,7 @@ public class DomainStoreTest {
|
|||
testDomain.setName(domainId);
|
||||
testDomain.setEnabled(Boolean.TRUE);
|
||||
ds.createDomain(testDomain);
|
||||
assertNotNull(ds.getDomains(domainId));
|
||||
assertEquals(ds.getDomain(domainId).getDomainid(), domainId);
|
||||
ds.deleteDomain(domainId);
|
||||
assertNull(ds.getDomain(domainId));
|
||||
|
@ -85,3 +98,12 @@ public class DomainStoreTest {
|
|||
return rsMock;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2016 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.opendaylight.aaa.api.model.Grants;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
|
@ -19,9 +24,10 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.opendaylight.aaa.api.model.Grants;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class GrantStoreTest {
|
||||
|
||||
|
@ -71,3 +77,12 @@ public class GrantStoreTest {
|
|||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017 Cisco Systems, Inc. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
@ -23,6 +26,9 @@ import org.opendaylight.aaa.api.model.Grant;
|
|||
import org.opendaylight.aaa.api.model.Role;
|
||||
import org.opendaylight.aaa.api.model.User;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class H2StoreTest {
|
||||
|
||||
@BeforeClass
|
||||
|
@ -53,13 +59,17 @@ public class H2StoreTest {
|
|||
|
||||
@Before
|
||||
public void before() throws StoreException, SQLException {
|
||||
UserStore us = new UserStore(new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
UserStore us = new UserStore(
|
||||
new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
us.dbClean();
|
||||
DomainStore ds = new DomainStore(new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
DomainStore ds = new DomainStore(
|
||||
new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
ds.dbClean();
|
||||
RoleStore rs = new RoleStore(new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
RoleStore rs = new RoleStore(
|
||||
new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
rs.dbClean();
|
||||
GrantStore gs = new GrantStore(new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
GrantStore gs = new GrantStore(
|
||||
new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
gs.dbClean();
|
||||
|
||||
h2Store = new H2Store();
|
||||
|
@ -69,7 +79,8 @@ public class H2StoreTest {
|
|||
public void testCreateDefaultDomain() throws StoreException {
|
||||
Domain domain = new Domain();
|
||||
Assert.assertEquals(true, domain != null);
|
||||
DomainStore ds = new DomainStore(new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
DomainStore ds = new DomainStore(
|
||||
new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
domain.setName(IIDMStore.DEFAULT_DOMAIN);
|
||||
domain.setEnabled(true);
|
||||
domain = ds.createDomain(domain);
|
||||
|
@ -99,9 +110,11 @@ public class H2StoreTest {
|
|||
|
||||
@Test
|
||||
public void testUpdatingUserEmail() throws StoreException {
|
||||
UserStore us = new UserStore(new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
UserStore us = new UserStore(
|
||||
new IdmLightSimpleConnectionProvider(new IdmLightConfigBuilder().build()));
|
||||
Domain domain = h2Store.createDomain("sdn", true);
|
||||
User user = h2Store.createUser("test", "pass", domain.getDomainid(), "desc", "email", true, "SALT");
|
||||
User user = h2Store.createUser("test", "pass", domain.getDomainid(), "desc", "email", true,
|
||||
"SALT");
|
||||
|
||||
user.setName("test");
|
||||
user = us.putUser(user);
|
||||
|
@ -190,3 +203,12 @@ public class H2StoreTest {
|
|||
* Assert.assertEquals(true, hash.equals(u.getPassword())); }
|
||||
*/
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,22 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017 Inocybe Technologies. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.opendaylight.aaa.api.Authentication;
|
||||
import org.opendaylight.aaa.shiro.tokenauthrealm.auth.AuthenticationBuilder;
|
||||
import org.opendaylight.aaa.shiro.tokenauthrealm.auth.ClaimBuilder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Unit Test for H2TokenStore.
|
||||
*
|
||||
|
@ -35,10 +41,20 @@ public class H2TokenStoreTest {
|
|||
public void testTokenStore() throws InterruptedException {
|
||||
final String fooToken = "foo_token";
|
||||
Authentication auth = new AuthenticationBuilder(
|
||||
new ClaimBuilder().setUser("foo").setUserId("1234").addRole("admin").build()).build();
|
||||
new ClaimBuilder().setUser("foo").setUserId("1234").addRole("admin").build())
|
||||
.build();
|
||||
h2TokenStore.put(fooToken, auth);
|
||||
assertEquals(auth, h2TokenStore.get(fooToken));
|
||||
h2TokenStore.delete(fooToken);
|
||||
assertNull(h2TokenStore.get(fooToken));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
/**
|
||||
* Unit test for IdmLightConfig.
|
||||
*
|
||||
|
@ -45,3 +52,12 @@ public class IdmLightConfigTest {
|
|||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,26 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.opendaylight.aaa.api.model.Roles;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.opendaylight.aaa.api.model.Roles;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class RoleStoreTest {
|
||||
|
||||
|
@ -64,3 +71,12 @@ public class RoleStoreTest {
|
|||
return rsMock;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,26 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.datastore.h2;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.opendaylight.aaa.api.model.Users;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.opendaylight.aaa.api.model.Users;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class UserStoreTest {
|
||||
|
||||
|
@ -67,3 +74,12 @@ public class UserStoreTest {
|
|||
return rsMock;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.shiro.idm.persistence;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
@ -27,6 +30,10 @@ import org.opendaylight.aaa.api.model.User;
|
|||
import org.opendaylight.aaa.api.model.Users;
|
||||
import org.opendaylight.aaa.shiro.idm.IdmLightProxy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @Author - Sharon Aicler (saichler@cisco.com)
|
||||
*/
|
||||
|
@ -93,3 +100,12 @@ public class PasswordHashTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,23 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017 Inocybe Technologies and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.shiro.idm.rest.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.UniformInterfaceException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.opendaylight.aaa.api.model.Domain;
|
||||
|
@ -25,6 +23,15 @@ import org.opendaylight.aaa.api.model.Domains;
|
|||
import org.opendaylight.aaa.api.model.IDMError;
|
||||
import org.opendaylight.aaa.api.model.Roles;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@Ignore
|
||||
public class DomainHandlerTest extends HandlerTest {
|
||||
|
||||
|
@ -48,7 +55,8 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
} catch (UniformInterfaceException e) {
|
||||
ClientResponse resp = e.getResponse();
|
||||
assertEquals(404, resp.getStatus());
|
||||
assertTrue(resp.getEntity(IDMError.class).getMessage().contains("Not found! domain id"));
|
||||
assertTrue(
|
||||
resp.getEntity(IDMError.class).getMessage().contains("Not found! domain id"));
|
||||
}
|
||||
|
||||
// check create domain
|
||||
|
@ -56,14 +64,14 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
domainData.put("name", "dom1");
|
||||
domainData.put("description", "test dom");
|
||||
domainData.put("enabled", "true");
|
||||
ClientResponse clientResponse = resource().path("/v1/domains").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, domainData);
|
||||
ClientResponse clientResponse = resource().path("/v1/domains")
|
||||
.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, domainData);
|
||||
assertEquals(201, clientResponse.getStatus());
|
||||
|
||||
// check update domain data
|
||||
domainData.put("name", "dom1Update");
|
||||
clientResponse = resource().path("/v1/domains/1").type(MediaType.APPLICATION_JSON).put(ClientResponse.class,
|
||||
domainData);
|
||||
clientResponse = resource().path("/v1/domains/1").type(MediaType.APPLICATION_JSON)
|
||||
.put(ClientResponse.class, domainData);
|
||||
assertEquals(200, clientResponse.getStatus());
|
||||
domain = resource().path("/v1/domains/1").get(Domain.class);
|
||||
assertNotNull(domain);
|
||||
|
@ -72,32 +80,32 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
// check create grant
|
||||
Map<String, String> grantData = new HashMap<String, String>();
|
||||
grantData.put("roleid", "1");
|
||||
clientResponse = resource().path("/v1/domains/1/users/0/roles").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, grantData);
|
||||
clientResponse = resource().path("/v1/domains/1/users/0/roles")
|
||||
.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, grantData);
|
||||
assertEquals(201, clientResponse.getStatus());
|
||||
|
||||
// check create existing grant
|
||||
clientResponse = resource().path("/v1/domains/1/users/0/roles").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, grantData);
|
||||
clientResponse = resource().path("/v1/domains/1/users/0/roles")
|
||||
.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, grantData);
|
||||
assertEquals(403, clientResponse.getStatus());
|
||||
|
||||
// check create grant with invalid domain id
|
||||
clientResponse = resource().path("/v1/domains/5/users/0/roles").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, grantData);
|
||||
clientResponse = resource().path("/v1/domains/5/users/0/roles")
|
||||
.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, grantData);
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
// check validate user (admin)
|
||||
Map<String, String> usrPwdData = new HashMap<String, String>();
|
||||
usrPwdData.put("username", "admin");
|
||||
usrPwdData.put("userpwd", "admin");
|
||||
clientResponse = resource().path("/v1/domains/0/users/roles").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, usrPwdData);
|
||||
clientResponse = resource().path("/v1/domains/0/users/roles")
|
||||
.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, usrPwdData);
|
||||
assertEquals(200, clientResponse.getStatus());
|
||||
|
||||
// check validate user (admin) with wrong password
|
||||
usrPwdData.put("userpwd", "1234");
|
||||
clientResponse = resource().path("/v1/domains/0/users/roles").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, usrPwdData);
|
||||
clientResponse = resource().path("/v1/domains/0/users/roles")
|
||||
.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, usrPwdData);
|
||||
assertEquals(401, clientResponse.getStatus());
|
||||
|
||||
// check get user (admin) roles
|
||||
|
@ -115,11 +123,13 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
}
|
||||
|
||||
// check delete grant
|
||||
clientResponse = resource().path("/v1/domains/0/users/0/roles/0").delete(ClientResponse.class);
|
||||
clientResponse = resource().path("/v1/domains/0/users/0/roles/0")
|
||||
.delete(ClientResponse.class);
|
||||
assertEquals(204, clientResponse.getStatus());
|
||||
|
||||
// check delete grant for invalid domain
|
||||
clientResponse = resource().path("/v1/domains/3/users/0/roles/0").delete(ClientResponse.class);
|
||||
clientResponse = resource().path("/v1/domains/3/users/0/roles/0")
|
||||
.delete(ClientResponse.class);
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
// check delete domain
|
||||
|
@ -133,7 +143,8 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
} catch (UniformInterfaceException e) {
|
||||
ClientResponse resp = e.getResponse();
|
||||
assertEquals(404, resp.getStatus());
|
||||
assertTrue(resp.getEntity(IDMError.class).getMessage().contains("Not found! Domain id"));
|
||||
assertTrue(
|
||||
resp.getEntity(IDMError.class).getMessage().contains("Not found! Domain id"));
|
||||
}
|
||||
|
||||
// Bug 8382: if a domain id is specified, 400 is returned
|
||||
|
@ -142,16 +153,25 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
domainData.put("description", "test dom");
|
||||
domainData.put("domainid", "dom1");
|
||||
domainData.put("enabled", "true");
|
||||
clientResponse = resource().path("/v1/domains").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,
|
||||
domainData);
|
||||
clientResponse = resource().path("/v1/domains").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, domainData);
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
|
||||
// Bug 8382: if a grant id is specified, 400 is returned
|
||||
grantData = new HashMap<>();
|
||||
grantData.put("roleid", "1");
|
||||
grantData.put("grantid", "grantid");
|
||||
clientResponse = resource().path("/v1/domains/1/users/0/roles").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, grantData);
|
||||
clientResponse = resource().path("/v1/domains/1/users/0/roles")
|
||||
.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, grantData);
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,22 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017 Inocybe Technologies and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.shiro.idm.rest.test;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.opendaylight.aaa.AAAShiroProvider;
|
||||
import org.opendaylight.aaa.api.StoreBuilder;
|
||||
import org.opendaylight.aaa.shiro.idm.IdmLightApplication;
|
||||
import org.slf4j.bridge.SLF4JBridgeHandler;
|
||||
|
||||
import com.sun.jersey.spi.container.servlet.WebComponent;
|
||||
import com.sun.jersey.test.framework.AppDescriptor;
|
||||
import com.sun.jersey.test.framework.JerseyTest;
|
||||
import com.sun.jersey.test.framework.WebAppDescriptor;
|
||||
import org.junit.Before;
|
||||
import org.opendaylight.aaa.api.StoreBuilder;
|
||||
import org.opendaylight.aaa.shiro.idm.IdmLightApplication;
|
||||
import org.opendaylight.aaa.AAAShiroProvider;
|
||||
import org.slf4j.bridge.SLF4JBridgeHandler;
|
||||
|
||||
public abstract class HandlerTest extends JerseyTest {
|
||||
|
||||
|
@ -28,7 +35,7 @@ public abstract class HandlerTest extends JerseyTest {
|
|||
.initParam(WebComponent.RESOURCE_CONFIG_CLASS, IdmLightApplication.class.getName())
|
||||
.initParam("com.sun.jersey.config.feature.Trace", "true")
|
||||
.initParam("com.sun.jersey.spi.container.ContainerResponseFilters",
|
||||
"com.sun.jersey.api.container.filter.LoggingFilter")
|
||||
"com.sun.jersey.api.container.filter.LoggingFilter")
|
||||
.initParam("jersey.config.server.provider.packages",
|
||||
"org.opendaylight.aaa.impl.provider")
|
||||
.build();
|
||||
|
@ -44,3 +51,12 @@ public abstract class HandlerTest extends JerseyTest {
|
|||
AAAShiroProvider.setIdmStore(testStore);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017 Inocybe Technologies and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.shiro.idm.rest.test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.opendaylight.aaa.api.IDMStoreException;
|
||||
import org.opendaylight.aaa.api.IIDMStore;
|
||||
import org.opendaylight.aaa.api.model.Domain;
|
||||
|
@ -21,6 +25,9 @@ import org.opendaylight.aaa.api.model.Roles;
|
|||
import org.opendaylight.aaa.api.model.User;
|
||||
import org.opendaylight.aaa.api.model.Users;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class IDMTestStore implements IIDMStore {
|
||||
|
||||
private List<Domain> domains = new ArrayList<Domain>();
|
||||
|
@ -194,7 +201,8 @@ public class IDMTestStore implements IIDMStore {
|
|||
return usrs;
|
||||
}
|
||||
for (Grant grant : grants) {
|
||||
if (grant.getUserid().equals(user.getUserid()) && grant.getDomainid().equals(domain.getDomainid())) {
|
||||
if (grant.getUserid().equals(user.getUserid())
|
||||
&& grant.getDomainid().equals(domain.getDomainid())) {
|
||||
List<User> usrList = new ArrayList<User>();
|
||||
usrList.add(user);
|
||||
usrs.setUsers(usrList);
|
||||
|
@ -270,3 +278,12 @@ public class IDMTestStore implements IIDMStore {
|
|||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,30 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017 Inocybe Technologies and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.shiro.idm.rest.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.UniformInterfaceException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.opendaylight.aaa.api.model.IDMError;
|
||||
import org.opendaylight.aaa.api.model.Role;
|
||||
import org.opendaylight.aaa.api.model.Roles;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@Ignore
|
||||
public class RoleHandlerTest extends HandlerTest {
|
||||
|
||||
|
@ -59,15 +66,15 @@ public class RoleHandlerTest extends HandlerTest {
|
|||
roleData.put("name", "role1");
|
||||
roleData.put("description", "test Role");
|
||||
roleData.put("domainid", "0");
|
||||
ClientResponse clientResponse = resource().path("/v1/roles").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, roleData);
|
||||
ClientResponse clientResponse = resource().path("/v1/roles")
|
||||
.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, roleData);
|
||||
assertEquals(201, clientResponse.getStatus());
|
||||
|
||||
// check create Role missing name data
|
||||
roleData.remove("name");
|
||||
try {
|
||||
clientResponse = resource().path("/v1/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,
|
||||
roleData);
|
||||
clientResponse = resource().path("/v1/roles").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, roleData);
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
} catch (UniformInterfaceException e) {
|
||||
ClientResponse resp = e.getResponse();
|
||||
|
@ -76,8 +83,8 @@ public class RoleHandlerTest extends HandlerTest {
|
|||
|
||||
// check update Role data
|
||||
roleData.put("name", "role1Update");
|
||||
clientResponse = resource().path("/v1/roles/2").type(MediaType.APPLICATION_JSON).put(ClientResponse.class,
|
||||
roleData);
|
||||
clientResponse = resource().path("/v1/roles/2").type(MediaType.APPLICATION_JSON)
|
||||
.put(ClientResponse.class, roleData);
|
||||
assertEquals(200, clientResponse.getStatus());
|
||||
role = resource().path("/v1/roles/2").get(Role.class);
|
||||
assertNotNull(role);
|
||||
|
@ -103,8 +110,17 @@ public class RoleHandlerTest extends HandlerTest {
|
|||
roleData.put("description", "test Role");
|
||||
roleData.put("domainid", "0");
|
||||
roleData.put("roleid", "roleid");
|
||||
clientResponse = resource().path("/v1/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,
|
||||
roleData);
|
||||
clientResponse = resource().path("/v1/roles").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, roleData);
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
|
@ -1,30 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017 Inocybe Technologies and others. All rights reserved.
|
||||
* Project: aaa.project
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/epl-v10.html
|
||||
* File Created at 2019/7/3
|
||||
*
|
||||
* Copyright 2018 CMCC Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of
|
||||
* ZYHY Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
* accordance with the terms of the license.
|
||||
*/
|
||||
|
||||
package org.opendaylight.aaa.shiro.idm.rest.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.UniformInterfaceException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.opendaylight.aaa.api.model.IDMError;
|
||||
import org.opendaylight.aaa.api.model.User;
|
||||
import org.opendaylight.aaa.api.model.Users;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@Ignore
|
||||
public class UserHandlerTest extends HandlerTest {
|
||||
|
||||
|
@ -62,15 +69,15 @@ public class UserHandlerTest extends HandlerTest {
|
|||
usrData.put("email", "user1@usr.org");
|
||||
usrData.put("password", "ChangeZbadPa$$w0rd");
|
||||
usrData.put("domainid", "0");
|
||||
ClientResponse clientResponse = resource().path("/v1/users").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, usrData);
|
||||
ClientResponse clientResponse = resource().path("/v1/users")
|
||||
.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, usrData);
|
||||
assertEquals(201, clientResponse.getStatus());
|
||||
|
||||
// check create user missing name data
|
||||
usrData.remove("name");
|
||||
try {
|
||||
clientResponse = resource().path("/v1/users").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,
|
||||
usrData);
|
||||
clientResponse = resource().path("/v1/users").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, usrData);
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
} catch (UniformInterfaceException e) {
|
||||
ClientResponse resp = e.getResponse();
|
||||
|
@ -79,8 +86,8 @@ public class UserHandlerTest extends HandlerTest {
|
|||
|
||||
// check update user data
|
||||
usrData.put("name", "usr1Update");
|
||||
clientResponse = resource().path("/v1/users/1").type(MediaType.APPLICATION_JSON).put(ClientResponse.class,
|
||||
usrData);
|
||||
clientResponse = resource().path("/v1/users/1").type(MediaType.APPLICATION_JSON)
|
||||
.put(ClientResponse.class, usrData);
|
||||
assertEquals(200, clientResponse.getStatus());
|
||||
usr = resource().path("/v1/users/1").get(User.class);
|
||||
assertNotNull(usr);
|
||||
|
@ -109,8 +116,17 @@ public class UserHandlerTest extends HandlerTest {
|
|||
usrData.put("password", "ChangeZbadPa$$w0rd");
|
||||
usrData.put("userid", "userid");
|
||||
usrData.put("domainid", "0");
|
||||
clientResponse = resource().path("/v1/users").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,
|
||||
usrData);
|
||||
clientResponse = resource().path("/v1/users").type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, usrData);
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* Date Author Note
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
* 2019/7/3 Dong Xiancun creat
|
||||
*/
|
||||
|
|
13
Makefile
13
Makefile
|
@ -28,9 +28,9 @@ MAKE_FLAGS += -j$(shell cat /proc/cpuinfo | grep processor | wc -l)
|
|||
endif
|
||||
endif
|
||||
|
||||
.PHONY : demo conntrack netlink trace openrpc configm redismq
|
||||
.PHONY : demo conntrack netlink trace openrpc usermanager configm redismq
|
||||
|
||||
all: demo conntrack netlink trace openrpc configm redismq
|
||||
all: demo conntrack netlink trace openrpc usermanager configm redismq
|
||||
|
||||
ifeq ($(OPT), install)
|
||||
#$(shell `find ../release -name "*.zip" -delete`)
|
||||
|
@ -123,6 +123,15 @@ else
|
|||
$(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f user.openrpc.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=openrpc
|
||||
endif
|
||||
|
||||
usermanager:
|
||||
ifeq ($(OPT), clean)
|
||||
$(MLOG)make $(MAKE_FLAGS) -C Product/build -f user.usermanager.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=usermanager
|
||||
else ifeq ($(OPT), install)
|
||||
$(MLOG)make $(MAKE_FLAGS) -C Product/build -f user.usermanager.Makefile install DIR=$(DIR) MLOG=$(MLOG) MAKE_TARGET=usermanager
|
||||
else
|
||||
$(MLOG)make all $(MAKE_FLAGS) -C Product/build -f user.usermanager.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=usermanager
|
||||
endif
|
||||
|
||||
configm:
|
||||
ifeq ($(OPT), clean)
|
||||
$(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.configm.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=configm
|
||||
|
|
|
@ -27,7 +27,7 @@ VPATH = ../user/configm/config-server
|
|||
|
||||
# set the source file, don't used .o because of ...
|
||||
|
||||
COMMON_SRCS = configserver.c ipconfig/ipconfig.c ipconfig/parsefile.c
|
||||
COMMON_SRCS = configserver.c ipconfig/ipconfig.c ipconfig/parsefile.c authfree_config/authfree.c localportal_config/localportal.c userlock_config/userlock.c jumppage_config/jumppage.c user_manager_config/user_group_config.c agingtime_config/agingtime.c
|
||||
|
||||
# MRS Board Source Files
|
||||
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
||||
|
@ -42,17 +42,17 @@ PLAT_ARM64_LDFLAGS :=
|
|||
PLAT_LINUX_LDFLAGS :=
|
||||
|
||||
#gcc libs
|
||||
ARM64_LIBS := ../thirdparty/arm64/libev-arm64.so ./libopenrpc-arm64.so -lpthread -lm
|
||||
LINUX_LIBS := ../thirdparty/x86_64/libev-linux.so ./libopenrpc-linux.so -lpthread -lm
|
||||
ARM64_LIBS := -lcjson ../thirdparty/arm64/libev-arm64.so ./libopenrpc-arm64.so ./libnetlinku-arm64.so ../../Product/build/debug/usermanager-arm64.so -lpthread -lm
|
||||
LINUX_LIBS := -lcjson ../thirdparty/x86_64/libev-linux.so ./libopenrpc-linux.so ./libnetlinku-linux.so ../../Product/build/debug/usermanager-linux.so -lpthread -lm
|
||||
|
||||
ifeq ($(PLAT_ARM64), TRUE)
|
||||
DEPEND_LIB += ../thirdparty/arm64/libev-arm64.so ./debug/libopenrpc-arm64.so
|
||||
USER_CLEAN_ITEMS += ./libopenrpc-arm64.so
|
||||
DEPEND_LIB += ../thirdparty/arm64/libev-arm64.so ./debug/libopenrpc-arm64.so ./debug/libnetlinku-arm64.so
|
||||
USER_CLEAN_ITEMS += ./libopenrpc-arm64.so ./libnetlinku-arm64.so
|
||||
endif
|
||||
|
||||
ifeq ($(PLAT_LINUX), TRUE)
|
||||
DEPEND_LIB += ../thirdparty/x86_64/libev-linux.so ./debug/libopenrpc-linux.so
|
||||
USER_CLEAN_ITEMS += ./libopenrpc-linux.so
|
||||
DEPEND_LIB += ../thirdparty/x86_64/libev-linux.so ./debug/libopenrpc-linux.so ./libnetlinku-linux.so
|
||||
USER_CLEAN_ITEMS += ./libopenrpc-linux.so ./libnetlinku-linux.so
|
||||
endif
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,253 @@
|
|||
#include "../include/parsefile.h"
|
||||
#include "../include/configm.h"
|
||||
#include "../../../netlink_uapi/libnetlinku.h"
|
||||
#include "../../../../common/rpc/rpc.h"
|
||||
#include "../include/agingtime.h"
|
||||
#include <cjson/cJSON.h>
|
||||
#include "../../../../../Common/s2j/s2j.h"
|
||||
#include "../../../../../Common/commuapinl.h"
|
||||
|
||||
#ifdef AGINGTIME_ACK_COOKIES
|
||||
#define CFG_AGINGTIME_ACK_COOKIES
|
||||
#endif
|
||||
|
||||
/*全局变量,存放配置的用户老化时间 */
|
||||
int *aging_time = NULL;
|
||||
|
||||
/*下发用户老化时间配置到内核态 */
|
||||
int set_agingtimecfg_waitack(int *agingtime)
|
||||
{
|
||||
int agingtime_len = 0;
|
||||
struct nlmsghdr *ack = NULL;
|
||||
struct nlmsghdr **answer = &ack;
|
||||
|
||||
struct{
|
||||
struct nlmsghdr n;
|
||||
char buf[1024];
|
||||
} req ={
|
||||
.n.nlmsg_len = NLMSG_LENGTH(0),
|
||||
#ifdef CFG_AGINGTIME_ACK_COOKIES
|
||||
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,/*set NLM_F_ACK:use kernel auto ack*/
|
||||
#else
|
||||
.n.nlmsg_flags = NLM_F_REQUEST, /*not use kernel auto ack */
|
||||
#endif
|
||||
.n.nlmsg_type = AGINGTIME_CFG, /*用户态发送给内核态的用户老化时间消息 */
|
||||
.n.nlmsg_pid = getpid(),
|
||||
};
|
||||
|
||||
/*判断要发送的数据是否为NULL,不为NULL,打印出来 */
|
||||
if (agingtime == NULL)
|
||||
{
|
||||
printf("set_agingtimecfg_waitack is error: input struct_agingtime is NULL.\r\n");
|
||||
return -1;
|
||||
}else
|
||||
{
|
||||
printf("set_freeauthcfg_waitack :agingtime %d\n", *agingtime);
|
||||
}
|
||||
|
||||
/*计算需要发送的数据的长度 */
|
||||
agingtime_len = sizeof(int);
|
||||
printf("%d\n", agingtime_len);
|
||||
|
||||
/*可选属性 */
|
||||
commnl_addattr_l(&req.n, sizeof(req), 1, agingtime, agingtime_len);
|
||||
|
||||
/*发送组装好的netlink消息 */
|
||||
if(pdeliv_talk(1, &req.n, answer) < 0)
|
||||
{
|
||||
printf("set_user_agingtime_waitack rcv ack msg faild.\r\n");
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("set_user_agingtime_waitack rcv ack msg success.\r\n");
|
||||
}
|
||||
|
||||
if(*answer != NULL)
|
||||
{
|
||||
printf("set_user_agingtime_waitack rcv answer.\r\n");
|
||||
}
|
||||
else{
|
||||
printf("set_user_agingtime_waitack rcv answer error.\r\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
#ifdef CFG_AGINGTIME_ACK_COOKIES
|
||||
/*recv answer*/
|
||||
if((*answer)->nlmsg_type == NLMSG_ERROR){
|
||||
nl_debugfs_extack(*answer);
|
||||
}
|
||||
#else
|
||||
/*recv answer*/
|
||||
if((*answer)->nlmsg_type == AGINGTIME_CFG)
|
||||
{
|
||||
nl_debugfs(*answer);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*判断配置的老化时间是否有效,老化时间大于0 */
|
||||
/*input格式 '{\"type\":0, \"time\":24}' */
|
||||
ret_code agingtime_config_chk(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
|
||||
cJSON *cjson, *time, *res;
|
||||
char * ret_char = NULL;
|
||||
int * ret_int = NULL;
|
||||
|
||||
|
||||
/*JSON字符串到JSON格式 */
|
||||
cjson = cJSON_Parse(input);
|
||||
if(!cjson)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*获取键值内容 */
|
||||
time = cJSON_GetObjectItem(cjson , "time");
|
||||
if(!time)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
ASSERT_RET(ret);
|
||||
cJSON_Delete(cjson);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(time->valueint < 0)
|
||||
{
|
||||
ret = RET_ERR;
|
||||
ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*创建json对象 */
|
||||
res = cJSON_CreateObject();
|
||||
if(!res)
|
||||
{
|
||||
ret = RET_ERR;
|
||||
ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
cJSON_AddNumberToObject(res, "time", time->valueint);
|
||||
|
||||
/*将json对象转换成json字符串 */
|
||||
ret_char = cJSON_PrintUnformatted(res);
|
||||
ret_int = (int*)ret_char;
|
||||
memcpy(output, ret_int, sizeof(ret_int)+1);
|
||||
|
||||
cJSON_Delete(res);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
/*系统管理模块将配置的用户老化时间通过netlink下发到内核态 */
|
||||
/*输入和输出的参数形式都为JSON字符串 '{"time": 30}' */
|
||||
ret_code agingtime_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
cJSON *cjson, *time, *res;
|
||||
int * agingtime = NULL;
|
||||
char * ret_char = NULL;
|
||||
int * ret_int = NULL;
|
||||
|
||||
/*JSON字符串到JSON格式 */
|
||||
cjson = cJSON_Parse(input);
|
||||
if(!cjson)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*获取键值内容 */
|
||||
time = cJSON_GetObjectItem(cjson , "time");
|
||||
if(!time)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
ASSERT_RET(ret);
|
||||
cJSON_Delete(cjson);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
int a = time->valueint;
|
||||
agingtime = &a;
|
||||
}
|
||||
|
||||
rpc_log_info("agingtime configure: agingtime %d\n", time->valueint);
|
||||
|
||||
/*用户态下发到内核态auth_hook */
|
||||
int r = -1;
|
||||
printf("cfgchannel main begin:\r\n");
|
||||
|
||||
/*创建通道 */
|
||||
r = commcfgnl_open();
|
||||
if(r < 0)
|
||||
{
|
||||
printf(" pdlivnl_open fail, exit.\r\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
/*下发配置到内核态 */
|
||||
r = set_agingtimecfg_waitack(agingtime);
|
||||
if(r < 0)
|
||||
{
|
||||
printf("set_cfg_debug_waitack failed.\r\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
/*关闭netlink通道 */
|
||||
commcfgnl_close();
|
||||
|
||||
printf("cfgchannel main exit!\r\n");
|
||||
|
||||
|
||||
/*创建json对象 */
|
||||
res = cJSON_CreateObject();
|
||||
if(!res)
|
||||
{
|
||||
ret = RET_ERR;
|
||||
ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
cJSON_AddNumberToObject(res, "result", r);
|
||||
|
||||
/*将json对象转换成json字符串 */
|
||||
ret_char = cJSON_PrintUnformatted(res);
|
||||
ret_int =(int*)ret_char;
|
||||
memcpy(output, ret_int, sizeof(ret_int)+1);
|
||||
|
||||
cJSON_Delete(res);
|
||||
|
||||
/*把免认证规则的配置信息存入全局变量 */
|
||||
aging_time = agingtime;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_code agingtime_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_code agingtime_config_get_all(uint source, uint64 config_id,
|
||||
pointer output, short *single_len,
|
||||
int *cnt)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
return ret;
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
#include "../../../../common/rpc/rpc.h"
|
||||
#include "../include/authfree.h"
|
||||
#include <cjson/cJSON.h>
|
||||
#include "s2j/s2j.h"
|
||||
#include "../../../../../Common/s2j/s2j.h"
|
||||
#include "../../../../../Common/commuapinl.h"
|
||||
|
||||
#ifdef FREEAUTH_ACK_COOKIES
|
||||
|
@ -15,7 +15,7 @@
|
|||
freeauth_configure_t *localuser;
|
||||
|
||||
/*全局变量初始化 失败为1 成功为0*/
|
||||
int Init(freeauth_configure_t *localuser)
|
||||
int authfreeInit(freeauth_configure_t *localuser)
|
||||
{
|
||||
localuser = (freeauth_configure_t *)malloc(sizeof * localuser);
|
||||
if (NULL == localuser)
|
||||
|
@ -177,7 +177,7 @@ ret_code freeauth_config_chk(uint source, uint config_type,
|
|||
|
||||
|
||||
/*免认证规则有效,将免认证规则通过netlink下发到内核态 */
|
||||
int freeauth_config_proc(uint source, uint config_type,
|
||||
ret_code freeauth_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
|
@ -205,7 +205,7 @@ int freeauth_config_proc(uint source, uint config_type,
|
|||
if(ret1 < 0)
|
||||
{
|
||||
printf(" pdlivnl_open fail, exit.\r\n");
|
||||
return -1;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
/*下发配置到内核态 */
|
||||
|
@ -213,7 +213,7 @@ int freeauth_config_proc(uint source, uint config_type,
|
|||
if(ret1 < 0)
|
||||
{
|
||||
printf("set_cfg_debug_waitack failed.\r\n");
|
||||
return -1;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
/*关闭netlink通道 */
|
||||
|
@ -223,14 +223,9 @@ int freeauth_config_proc(uint source, uint config_type,
|
|||
|
||||
/*把免认证规则的配置信息存入全局变量 */
|
||||
localuser = struct_freeauth;
|
||||
return 0;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef AGINGTIME_H_
|
||||
#define AGINGTIME_H_
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include "../../../../common/rpc/rpc_common.h"
|
||||
|
||||
|
||||
/*判断配置的老化时间是否有效,老化时间大于0 */
|
||||
ret_code agingtime_config_chk(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
/*系统管理模块将配置的用户老化时间通过netlink下发到内核态 */
|
||||
ret_code agingtime_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
ret_code agingtime_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
ret_code agingtime_config_get_all(uint source, uint64 config_id,
|
||||
pointer output, short *single_len,
|
||||
int *cnt);
|
||||
|
||||
#endif
|
|
@ -26,7 +26,7 @@ typedef struct {
|
|||
|
||||
|
||||
/*全局变量初始化 失败为1 成功为0*/
|
||||
int Init(freeauth_configure_t *localuser);
|
||||
int authfreeInit(freeauth_configure_t *localuser);
|
||||
|
||||
|
||||
/* 判断IPv4格式是否正确*/
|
||||
|
@ -43,7 +43,7 @@ ret_code freeauth_config_chk(uint source, uint config_type,
|
|||
|
||||
|
||||
/*免认证规则有效,将免认证规则通过netlink下发到内核态 */
|
||||
int freeauth_config_proc(uint source, uint config_type,
|
||||
ret_code freeauth_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
|
|
|
@ -5,6 +5,12 @@
|
|||
#include "ipconfig.h"
|
||||
#include "../../../../../Common/commuapinl.h"
|
||||
#include "user_group_config.h"
|
||||
#include "authfree.h"
|
||||
#include "localportal.h"
|
||||
#include "jumppage.h"
|
||||
#include "userlock.h"
|
||||
#include "agingtime.h"
|
||||
|
||||
/* 类型定义 */
|
||||
|
||||
/* IP CONFIG */
|
||||
|
@ -14,11 +20,7 @@
|
|||
#define USER_MANAGER_CONFIG_MODULE 0x00000002
|
||||
|
||||
/*PORTAL SERVER CONFIG */
|
||||
#define PORTAL_CONFIG_MODULE 0x00000003
|
||||
|
||||
/* AUTHFREE CONFIG*/
|
||||
#define AUTHFREE_CONFIG_MODULE 0x00000004
|
||||
|
||||
#define LOCALAUTH_CONFIG_MODULE 0x00000003
|
||||
|
||||
|
||||
/* config id define*/
|
||||
|
@ -27,9 +29,13 @@
|
|||
#define USER_MANAGER_CONFIG_GROUP (uint64)((uint64)USER_MANAGER_CONFIG_MODULE<<32|1)
|
||||
#define USER_MANAGER_CONFIG_USER (uint64)((uint64)USER_MANAGER_CONFIG_MODULE<<32|2)
|
||||
|
||||
#define PORTALSERVER_CONFIG (uint64)((uint64)PORTAL_CONFIG_MODULE<<32|1)
|
||||
#define PORTALSERVER_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|1)
|
||||
#define AUTHFREE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|2)
|
||||
#define USERLOCK_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|3)
|
||||
#define JUMPPAGE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|4)
|
||||
#define AGINGTIME_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|5)
|
||||
|
||||
|
||||
#define AUTHFREE_CONFIG (uint64)((uint64)AUTHFREE_CONFIG_MODULE<<32|1)
|
||||
/*
|
||||
1、配置ID,全局唯一,用于寻找对应的配置业务
|
||||
2、配置源检查,全局唯一,用于寻找对应的配置业务,
|
||||
|
@ -70,19 +76,50 @@
|
|||
FALSE, \
|
||||
portalserver_config_chk, \
|
||||
portalserver_config_proc, \
|
||||
portalserver_config_get, \
|
||||
portalserver_get_all \
|
||||
},\
|
||||
{\
|
||||
NULL, \
|
||||
NULL \
|
||||
}, \
|
||||
{ \
|
||||
AUTHFREE_CONFIG, \
|
||||
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
||||
FALSE, \
|
||||
FALSE, \
|
||||
freeauth_config_chk, \
|
||||
freeauth_config_proc, \
|
||||
freeauth_config_get, \
|
||||
freeauth_config_get_all \
|
||||
NULL, \
|
||||
NULL \
|
||||
},\
|
||||
{\
|
||||
USERLOCK_CONFIG, \
|
||||
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
||||
FALSE, \
|
||||
FALSE, \
|
||||
userlock_config_chk, \
|
||||
userlock_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
},\
|
||||
{\
|
||||
JUMPPAGE_CONFIG, \
|
||||
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
||||
FALSE, \
|
||||
FALSE, \
|
||||
NULL, \
|
||||
jumppage_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
}, \
|
||||
{\
|
||||
AGINGTIME_CONFIG, \
|
||||
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
||||
FALSE, \
|
||||
FALSE, \
|
||||
agingtime_config_chk, \
|
||||
agingtime_config_proc, \
|
||||
agingtime_config_get, \
|
||||
agingtime_config_get_all \
|
||||
} \
|
||||
\
|
||||
}
|
||||
|
||||
typedef ret_code (*cm_config_chk)(uint source, uint config_type,
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef JUMPPAGE_H_
|
||||
#define JUMPPAGE_H_
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include "../../../../common/rpc/rpc_common.h"
|
||||
|
||||
|
||||
/*系统管理模块将数据内容(URL地址)发送给web server */
|
||||
ret_code jumppage_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
#endif
|
|
@ -21,7 +21,7 @@ typedef struct {
|
|||
}localportal_configure_t;
|
||||
|
||||
/*全局变量初始化 失败为1 成功为0*/
|
||||
int Init(localportal_configure_t *localportal);
|
||||
int localportalInit(localportal_configure_t *localportal);
|
||||
|
||||
|
||||
/*检查IP地址是否有效,端口号是否被占用 */
|
||||
|
@ -35,7 +35,7 @@ ret_code portalserver_config_chk(uint source, uint config_type,
|
|||
|
||||
|
||||
/*系统管理模块将数据内容(IP地址、端口号)发送给web server */
|
||||
int portalserver_config_proc(uint source, uint config_type,
|
||||
ret_code portalserver_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#define IFCONFIG_PATH "/etc/network/interfaces"
|
||||
#define IF_BUFF_LEN 128
|
||||
|
||||
void set_if_config(char *if_name, char *conf_name, char *conf_buff);
|
||||
void del_if_config(char *if_name, char *conf_buff);
|
||||
void ip_conf_file_set(char *if_name, char *conf_name, char *conf_buff);
|
||||
void ip_conf_file_del(char *if_name, char *conf_buff);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,12 +14,19 @@
|
|||
#include <cjson/cJSON.h>
|
||||
|
||||
|
||||
#include "../../../../common/configm/configmapi.h"
|
||||
#include "../../../../common/rpc/rpc_common.h"
|
||||
#include "../../../../../Product/user/user_manager/user_group.h"
|
||||
|
||||
#include "configmapi.h"
|
||||
#include "rpc_common.h"
|
||||
#include "sg/user/user_manager/user_group.h"
|
||||
|
||||
typedef ret_code (*usergroup_config)(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
|
||||
/* 新增用户组 */
|
||||
ret_code usergroup_config_add_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
/* user group config */
|
||||
ret_code usergroup_config_chk(uint source, uint config_type,
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef USERLOCK_H_
|
||||
#define USERLOCK_H_
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include "../../../../common/rpc/rpc_common.h"
|
||||
|
||||
|
||||
#define FAIL_MIN_NUM 0 /*失败次数的最小值*/
|
||||
#define LOCK_MIN_TIME 0 /*锁定的最小时间 */
|
||||
#define HORIZON_MIN_VALUE 0 /*认证时间范围的最小值 */
|
||||
|
||||
/*配置消息 */
|
||||
typedef struct {
|
||||
time_t logintime;
|
||||
int timehorizon;
|
||||
int failcount;
|
||||
int locktime;
|
||||
}userlock_configure_t;
|
||||
|
||||
|
||||
/*全局变量初始化 失败为1 成功为0*/
|
||||
int Init(userlock_configure_t *userlock);
|
||||
|
||||
|
||||
/*判断锁定配置信息是否有效,时间范围大于0,失败的次数大于0,锁定时间大于0 */
|
||||
ret_code userlock_config_chk(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
|
||||
/*系统管理模块将数据内容(IP地址、端口号)发送给web server */
|
||||
ret_code userlock_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
#endif
|
|
@ -51,13 +51,13 @@ void ip_save_file(ip_config_t *ip_conf, uint config_type)
|
|||
sprintf(mask_buff, "netmask %s\n", inet_ntoa(netmask));
|
||||
rpc_log_info("%s %s",addr_buff, mask_buff);
|
||||
|
||||
set_if_config(ip_conf->ifname, addr_name, addr_buff);
|
||||
set_if_config(ip_conf->ifname, mask_name, mask_buff);
|
||||
ip_conf_file_set(ip_conf->ifname, addr_name, addr_buff);
|
||||
ip_conf_file_set(ip_conf->ifname, mask_name, mask_buff);
|
||||
}
|
||||
else if(config_type == CM_CONFIG_DEL)
|
||||
{
|
||||
del_if_config(ip_conf->ifname, addr_name);
|
||||
del_if_config(ip_conf->ifname, mask_name);
|
||||
ip_conf_file_del(ip_conf->ifname, addr_name);
|
||||
ip_conf_file_del(ip_conf->ifname, mask_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,292 +9,82 @@
|
|||
#include "parsefile.h"
|
||||
#include "rpc.h"
|
||||
|
||||
#if 0
|
||||
/*
|
||||
*从配置文件中读取相应的值
|
||||
*输入参数:1,配置文件路径 2,匹配标记 3,输出存储空间
|
||||
*并且排除了空行,“=”前后无内容,无“=”的情况
|
||||
*/
|
||||
void read_config(char *conf_path,char *conf_name,char *config_buff)
|
||||
/* 缓存字符串保存到配置文件中 */
|
||||
int conf_file_write(char *conf_path, char *sum_buf)
|
||||
{
|
||||
char config_linebuf[256];
|
||||
char line_name[40];
|
||||
char exchange_buf[256];
|
||||
char *config_sign = "=";
|
||||
char *leave_line;
|
||||
FILE *f;
|
||||
f = fopen(conf_path,"r");
|
||||
if(f == NULL)
|
||||
{
|
||||
printf("OPEN CONFIG FALID/n");
|
||||
return 0;
|
||||
}
|
||||
fseek(f,0,SEEK_SET);
|
||||
while(fgets(config_linebuf,256,f) != NULL)
|
||||
{
|
||||
if(strlen(config_linebuf) < 3) //判断是否是空行
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (config_linebuf[strlen(config_linebuf)-1] == 10) //去除最后一位是/n的情况
|
||||
{
|
||||
|
||||
memset(exchange_buf,0,sizeof(exchange_buf));
|
||||
strncpy(exchange_buf,config_linebuf,strlen(config_linebuf)-1);
|
||||
memset(config_linebuf,0,sizeof(config_linebuf));
|
||||
strcpy(config_linebuf,exchange_buf);
|
||||
}
|
||||
memset(line_name,0,sizeof(line_name));
|
||||
leave_line = strstr(config_linebuf,config_sign);
|
||||
if(leave_line == NULL) //去除无"="的情况
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int leave_num = leave_line - config_linebuf;
|
||||
strncpy(line_name,config_linebuf,leave_num);
|
||||
if(strcmp(line_name,conf_name) ==0)
|
||||
{
|
||||
strncpy(config_buff,config_linebuf+(leave_num+1),strlen(config_linebuf)-leave_num-1);
|
||||
break;
|
||||
}
|
||||
if(fgetc(f)==EOF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
fseek(f,-1,SEEK_CUR);
|
||||
memset(config_linebuf,0,sizeof(config_linebuf));
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
/*
|
||||
*添加修改文件(当配置文件中存在标记字段,则进行修改,若不存在则进行添加)
|
||||
*
|
||||
*输入参数:1,配置文件路径 2,匹配标记 3,替换或添加的内容
|
||||
*
|
||||
*/
|
||||
void add_set_config(char *conf_path,char *conf_name,char *config_buff)
|
||||
{
|
||||
|
||||
char config_linebuf[256];
|
||||
char line_name[40];
|
||||
char *config_sign = "=";
|
||||
char *leave_line;
|
||||
int alter_sign = 0;
|
||||
|
||||
FILE *f;
|
||||
f = fopen(conf_path,"r+");
|
||||
if(f == NULL)
|
||||
{
|
||||
printf("OPEN CONFIG FALID/n");
|
||||
return 0;
|
||||
}
|
||||
fseek(f,0,SEEK_END);
|
||||
long congig_lenth = ftell(f);
|
||||
int configbuf_lenth = strlen(config_buff);
|
||||
configbuf_lenth = configbuf_lenth + 5;
|
||||
char sum_buf[congig_lenth+configbuf_lenth];
|
||||
memset(sum_buf,0,sizeof(sum_buf));
|
||||
fseek(f,0,SEEK_SET);
|
||||
while(fgets(config_linebuf,256,f) != NULL)
|
||||
{
|
||||
if(strlen(config_linebuf) < 3) //判断是否是空行
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
continue;
|
||||
}
|
||||
leave_line = NULL;
|
||||
leave_line = strstr(config_linebuf,config_sign);
|
||||
if(leave_line == NULL) //去除无"="的情况
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
continue;
|
||||
}
|
||||
int leave_num = leave_line - config_linebuf;
|
||||
memset(line_name,0,sizeof(line_name));
|
||||
strncpy(line_name,config_linebuf,leave_num);
|
||||
if(strcmp(line_name,conf_name) ==0)
|
||||
{
|
||||
strcat(sum_buf,config_buff);
|
||||
strcat(sum_buf,"/n");
|
||||
alter_sign = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
}
|
||||
if(fgetc(f)==EOF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
fseek(f,-1,SEEK_CUR);
|
||||
memset(config_linebuf,0,sizeof(config_linebuf));
|
||||
}
|
||||
if(alter_sign == 0)
|
||||
{
|
||||
strcat(sum_buf,config_buff);
|
||||
strcat(sum_buf,"/n");
|
||||
}
|
||||
printf("---sum_buf---->%s<----------/n",sum_buf);
|
||||
remove(conf_path);
|
||||
fclose(f);
|
||||
FILE *fp;
|
||||
fp = fopen(conf_path,"w+");
|
||||
if(fp == NULL)
|
||||
{
|
||||
printf("OPEN CONFIG FALID/n");
|
||||
return 2;
|
||||
}
|
||||
fseek(fp,0,SEEK_SET);
|
||||
fputs(sum_buf,fp);
|
||||
fclose(fp);
|
||||
}
|
||||
/*
|
||||
*删除配置文件内容
|
||||
*
|
||||
*输入参数:1,匹配标记
|
||||
*
|
||||
*/
|
||||
void del_if_config(char *conf_name)
|
||||
{
|
||||
char *conf_path = "/etc/network/interface";
|
||||
char config_linebuf[256];
|
||||
char line_name[40];
|
||||
char *config_sign = "=";
|
||||
char *leave_line;
|
||||
|
||||
FILE *f;
|
||||
f = fopen(conf_path,"r+");
|
||||
if(f == NULL)
|
||||
{
|
||||
printf("OPEN CONFIG FALID/n");
|
||||
return 0;
|
||||
}
|
||||
fseek(f,0,SEEK_END);
|
||||
long congig_lenth = ftell(f);
|
||||
char sum_buf[congig_lenth+2];
|
||||
memset(sum_buf,0,sizeof(sum_buf));
|
||||
fseek(f,0,SEEK_SET);
|
||||
while(fgets(config_linebuf,256,f) != NULL)
|
||||
{
|
||||
if(strlen(config_linebuf) < 3) //判断是否是空行
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
continue;
|
||||
}
|
||||
leave_line = NULL;
|
||||
leave_line = strstr(config_linebuf,config_sign);
|
||||
if(leave_line == NULL) //去除无"="的情况
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
continue;
|
||||
}
|
||||
int leave_num = leave_line - config_linebuf;
|
||||
memset(line_name,0,sizeof(line_name));
|
||||
strncpy(line_name,config_linebuf,leave_num);
|
||||
if(strcmp(line_name,conf_name) !=0)
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
}
|
||||
|
||||
if(fgetc(f)==EOF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
fseek(f,-1,SEEK_CUR);
|
||||
memset(config_linebuf,0,sizeof(config_linebuf));
|
||||
}
|
||||
printf("---sum_buf---->%s<----------/n",sum_buf);
|
||||
remove(conf_path);
|
||||
fclose(f);
|
||||
FILE *fp;
|
||||
fp = fopen(conf_path,"w+");
|
||||
if(fp == NULL)
|
||||
{
|
||||
printf("OPEN CONFIG FALID/n");
|
||||
return 2;
|
||||
}
|
||||
fseek(fp,0,SEEK_SET);
|
||||
fputs(sum_buf,fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
*添加修改文件(当配置文件中存在标记字段,则进行修改,若不存在则进行添加)
|
||||
*
|
||||
*输入参数:1,接口名 2,匹配标记 3,替换或添加的内容
|
||||
*
|
||||
*/
|
||||
|
||||
void set_if_config(char *if_name, char *conf_name, char *conf_buff)
|
||||
{
|
||||
char *conf_path = IFCONFIG_PATH;
|
||||
char config_linebuf[IF_BUFF_LEN];
|
||||
char static_name[IF_BUFF_LEN] = {0};
|
||||
char iface_str[IF_BUFF_LEN] = {0};
|
||||
char auto_str[IF_BUFF_LEN] = {0};
|
||||
char *auto_line = NULL;
|
||||
char *iface_line = NULL;
|
||||
char *config_line = NULL;
|
||||
boolean next_flag = FALSE;
|
||||
|
||||
FILE *f;
|
||||
f = fopen(conf_path,"r+");
|
||||
if(f == NULL)
|
||||
{
|
||||
rpc_log_error("OPEN CONFIG FALID\n");
|
||||
return;
|
||||
return RET_ERR;
|
||||
}
|
||||
fseek(fp,0,SEEK_SET);
|
||||
fputs(sum_buf,fp);
|
||||
fclose(fp);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
/* 设置指定配置块中的配置 */
|
||||
int conf_value_in_block_set(char *conf_path,
|
||||
char *start_str, char *end_str,
|
||||
char *conf_name, char *conf_buff)
|
||||
{
|
||||
char config_linebuf[IF_BUFF_LEN];
|
||||
int configbuf_lenth = strlen(conf_buff) + 5;
|
||||
long config_lenth = 0;
|
||||
boolean next_flag = FALSE;
|
||||
char *start_line = NULL;
|
||||
char *config_line = NULL;
|
||||
FILE *f;
|
||||
|
||||
f = fopen(conf_path,"r+");
|
||||
if(f == NULL)
|
||||
{
|
||||
rpc_log_error("OPEN CONFIG %s FALID\n", conf_path);
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
fseek(f,0,SEEK_END);
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
||||
config_lenth = ftell(f);
|
||||
|
||||
long config_lenth = ftell(f);
|
||||
int configbuf_lenth = strlen(conf_buff);
|
||||
configbuf_lenth = configbuf_lenth + 5;
|
||||
char sum_buf[config_lenth + configbuf_lenth];
|
||||
|
||||
memset(sum_buf,0,sizeof(sum_buf));
|
||||
fseek(f,0,SEEK_SET);
|
||||
memset(sum_buf, 0, sizeof(sum_buf));
|
||||
|
||||
sprintf(auto_str, "auto %s", if_name);
|
||||
sprintf(iface_str, "iface %s inet", if_name);
|
||||
sprintf(static_name, "iface %s inet static\n", if_name);
|
||||
|
||||
memset(config_linebuf,0,sizeof(config_linebuf));
|
||||
|
||||
while(fgets(config_linebuf,IF_BUFF_LEN,f) != NULL)
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
memset(config_linebuf, 0, sizeof(config_linebuf));
|
||||
|
||||
while(fgets(config_linebuf, IF_BUFF_LEN, f) != NULL)
|
||||
{
|
||||
/* 该做的事情已经做完 */
|
||||
if(next_flag == TRUE)
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
strcat(sum_buf, config_linebuf);
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
/* 判断是否是空行 */
|
||||
if(strlen(config_linebuf) < 3)
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
strcat(sum_buf, config_linebuf);
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
/* 没有找到接口配置块,则继续循环 */
|
||||
if(auto_line == NULL)
|
||||
/* 没有找到配置块,则继续循环 */
|
||||
if(start_line == NULL)
|
||||
{
|
||||
auto_line = strstr(config_linebuf, auto_str);
|
||||
start_line = strstr(config_linebuf, start_str);
|
||||
strcat(sum_buf, config_linebuf);
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
/* 已经是下一个接口了*/
|
||||
if(strstr(config_linebuf, "auto"))
|
||||
/* 配置块结束 */
|
||||
if(strstr(config_linebuf, end_str))
|
||||
{
|
||||
if(iface_line == NULL)
|
||||
{
|
||||
strcat(sum_buf, static_name);
|
||||
}
|
||||
if(config_line == NULL)
|
||||
{
|
||||
strcat(sum_buf, conf_buff);
|
||||
|
@ -305,22 +95,12 @@ void set_if_config(char *if_name, char *conf_name, char *conf_buff)
|
|||
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
/* 找到接口IP配置方式 */
|
||||
if(iface_line == NULL)
|
||||
{
|
||||
iface_line = strstr(config_linebuf, iface_str);
|
||||
if(iface_line)
|
||||
{
|
||||
strcat(sum_buf, static_name);
|
||||
goto next_while;
|
||||
}
|
||||
}
|
||||
|
||||
/* 找到配置行 */
|
||||
if(config_line == NULL)
|
||||
{
|
||||
config_line = strstr(config_linebuf, conf_name);
|
||||
|
||||
/* 找到配置行 */
|
||||
if(config_line)
|
||||
{
|
||||
next_flag = TRUE;
|
||||
|
@ -341,112 +121,94 @@ next_while:
|
|||
|
||||
memset(config_linebuf, 0, sizeof(config_linebuf));
|
||||
}
|
||||
|
||||
|
||||
/* 整个配置块都没有,则新创建该配置块 */
|
||||
if( next_flag == FALSE )
|
||||
{
|
||||
if(auto_line == NULL)
|
||||
if(start_line == NULL)
|
||||
{
|
||||
strcat(sum_buf, auto_str);
|
||||
strcat(sum_buf, start_str);
|
||||
strcat(sum_buf, "\n");
|
||||
}
|
||||
|
||||
if(iface_line == NULL)
|
||||
{
|
||||
strcat(sum_buf, static_name);
|
||||
}
|
||||
|
||||
if(config_line == NULL)
|
||||
{
|
||||
strcat(sum_buf, conf_buff);
|
||||
}
|
||||
}
|
||||
|
||||
rpc_log_dbg("---sum_buf---->%s<----------\n",sum_buf);
|
||||
|
||||
remove(conf_path);
|
||||
fclose(f);
|
||||
|
||||
FILE *fp;
|
||||
fp = fopen(conf_path,"w+");
|
||||
if(fp == NULL)
|
||||
{
|
||||
rpc_log_error("OPEN CONFIG FALID\n");
|
||||
return;
|
||||
}
|
||||
fseek(fp,0,SEEK_SET);
|
||||
fputs(sum_buf,fp);
|
||||
fclose(fp);
|
||||
|
||||
return;
|
||||
rpc_log_dbg("---sum_buf---->%s<----------\n",sum_buf);
|
||||
|
||||
return conf_file_write(conf_path, sum_buf);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*删除配置文件内容
|
||||
*
|
||||
*输入参数:1,匹配标记
|
||||
*
|
||||
*/
|
||||
void del_if_config(char *if_name, char *conf_buff)
|
||||
/* 删除指定配置块中的配置 */
|
||||
int conf_value_in_block_del(char *conf_path, char *start_str,
|
||||
char *end_str, char *conf_buff)
|
||||
{
|
||||
char *conf_path = IFCONFIG_PATH;
|
||||
char config_linebuf[IF_BUFF_LEN];
|
||||
char auto_str[IF_BUFF_LEN] = {0};
|
||||
int configbuf_lenth = strlen(conf_buff) + 5;
|
||||
long congig_lenth = 0;
|
||||
|
||||
boolean next_flag = FALSE;
|
||||
char *auto_line = NULL;
|
||||
FILE *f;
|
||||
f = fopen(conf_path,"r+");
|
||||
char *start_line = NULL;
|
||||
FILE *f = fopen(conf_path, "r+");
|
||||
|
||||
if(f == NULL)
|
||||
{
|
||||
printf("OPEN CONFIG FALID\n");
|
||||
return;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
fseek(f,0,SEEK_END);
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
||||
long congig_lenth = ftell(f);
|
||||
int configbuf_lenth = strlen(conf_buff);
|
||||
configbuf_lenth = configbuf_lenth + 5;
|
||||
char sum_buf[congig_lenth+configbuf_lenth];
|
||||
congig_lenth = ftell(f);
|
||||
|
||||
memset(sum_buf,0,sizeof(sum_buf));
|
||||
fseek(f,0,SEEK_SET);
|
||||
char sum_buf[congig_lenth + configbuf_lenth];
|
||||
|
||||
sprintf(auto_str, "auto %s", if_name);
|
||||
memset(sum_buf, 0, sizeof(sum_buf));
|
||||
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
while(fgets(config_linebuf,IF_BUFF_LEN,f) != NULL)
|
||||
memset(config_linebuf, 0, sizeof(config_linebuf));
|
||||
|
||||
while(fgets(config_linebuf, IF_BUFF_LEN,f) != NULL)
|
||||
{
|
||||
/* 该做的事情已经做完 */
|
||||
if(next_flag == TRUE)
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
strcat(sum_buf, config_linebuf);
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
/* 判断是否是空行 */
|
||||
if(strlen(config_linebuf) < 3)
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
strcat(sum_buf, config_linebuf);
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
/* 没有找到接口配置块,则继续循环 */
|
||||
if(auto_line == NULL)
|
||||
if(start_line == NULL)
|
||||
{
|
||||
auto_line = strstr(config_linebuf, auto_str);
|
||||
strcat(sum_buf,config_linebuf);
|
||||
start_line = strstr(config_linebuf, start_str);
|
||||
strcat(sum_buf, config_linebuf);
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
/* 已经是下一个接口了, 则表示无法找到*/
|
||||
if(strstr(config_linebuf, "auto"))
|
||||
if(strstr(config_linebuf, end_str))
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
strcat(sum_buf, config_linebuf);
|
||||
next_flag = TRUE;
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
/* 找到配置行 */
|
||||
if(strstr(config_linebuf,conf_buff))
|
||||
if(strstr(config_linebuf, conf_buff))
|
||||
{
|
||||
next_flag = TRUE;
|
||||
}
|
||||
|
@ -463,23 +225,57 @@ void del_if_config(char *if_name, char *conf_buff)
|
|||
}
|
||||
fseek(f,-1,SEEK_CUR);
|
||||
|
||||
memset(config_linebuf,0,sizeof(config_linebuf));
|
||||
memset(config_linebuf, 0, sizeof(config_linebuf));
|
||||
}
|
||||
|
||||
printf("---sum_buf---->%s<----------/n",sum_buf);
|
||||
remove(conf_path);
|
||||
fclose(f);
|
||||
|
||||
FILE *fp;
|
||||
fp = fopen(conf_path,"w+");
|
||||
if(fp == NULL)
|
||||
{
|
||||
printf("OPEN CONFIG FALID/n");
|
||||
return;
|
||||
}
|
||||
fseek(fp,0,SEEK_SET);
|
||||
fputs(sum_buf,fp);
|
||||
fclose(fp);
|
||||
rpc_log_dbg("---sum_buf---->%s<----------\n",sum_buf);
|
||||
|
||||
return conf_file_write(conf_path, sum_buf);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*添加修改文件(当配置文件中存在标记字段,则进行修改,若不存在则进行添加)
|
||||
*
|
||||
*输入参数:1,接口名 2,匹配标记 3,替换或添加的内容
|
||||
*
|
||||
*/
|
||||
|
||||
void ip_conf_file_set(char *if_name, char *conf_name, char *conf_buff)
|
||||
{
|
||||
char auto_str[IF_BUFF_LEN] = {0};
|
||||
char iface_str[IF_BUFF_LEN] = {0};
|
||||
char static_name[IF_BUFF_LEN] = {0};
|
||||
|
||||
sprintf(auto_str, "auto %s", if_name);
|
||||
sprintf(iface_str, "iface %s inet", if_name);
|
||||
sprintf(static_name, "iface %s inet static\n", if_name);
|
||||
|
||||
conf_value_in_block_set(IFCONFIG_PATH, auto_str, "auto", iface_str, static_name);
|
||||
conf_value_in_block_set(IFCONFIG_PATH, auto_str, "auto", conf_name, conf_buff);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*删除配置文件内容
|
||||
*
|
||||
*输入参数:1,匹配标记
|
||||
*
|
||||
*/
|
||||
void ip_conf_file_del(char *if_name, char *conf_buff)
|
||||
{
|
||||
char auto_str[IF_BUFF_LEN] = {0};
|
||||
|
||||
sprintf(auto_str, "auto %s", if_name);
|
||||
|
||||
conf_value_in_block_del(IFCONFIG_PATH, auto_str, "auto", conf_buff);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
#include "../../../../common/rpc/rpc.h"
|
||||
#include "../include/parsefile.h"
|
||||
#include "../include/configm.h"
|
||||
#include "../../../netlink_uapi/libnetlinku.h"
|
||||
#include "../include/jumppage.h"
|
||||
#include <cjson/cJSON.h>
|
||||
#include "../../../../../Common/s2j/s2j.h"
|
||||
#include "../../../../../Common/commuapinl.h"
|
||||
|
||||
/*全局变量,存放用户跳转的页面 */
|
||||
char *jumpurl = NULL;
|
||||
|
||||
/*系统管理模块将数据内容(URL地址)发送给web server */
|
||||
/*input格式:"{\"type\":0,\"url\":\"http://www.baidu.com\"}"*/
|
||||
ret_code jumppage_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
cJSON *cjson, *url, *res;
|
||||
char * ret_char = NULL;
|
||||
char * jump_url;
|
||||
|
||||
/*JSON字符串到JSON格式 */
|
||||
cjson = cJSON_Parse(input);
|
||||
if(!cjson)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*获取键值内容 */
|
||||
url= cJSON_GetObjectItem(cjson , "url");
|
||||
if(!url)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
ASSERT_RET(ret);
|
||||
cJSON_Delete(cjson);
|
||||
return ret;
|
||||
}
|
||||
|
||||
rpc_log_info("jumppage configure: url %s\n", url->valuestring);
|
||||
|
||||
char i = url->valuestring;
|
||||
jump_url = &i;
|
||||
cJSON_Delete(cjson);
|
||||
|
||||
/*将配置信息发送到web server 发送结果int表示,0表示发送成功,-1表示发送失败*/
|
||||
int r;
|
||||
|
||||
|
||||
/*创建json对象 */
|
||||
res = cJSON_CreateObject();
|
||||
if(!res)
|
||||
{
|
||||
ret = RET_ERR;
|
||||
ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
cJSON_AddNumberToObject(res, "result", r);
|
||||
|
||||
/*将json对象转换成json字符串 */
|
||||
ret_char = cJSON_PrintUnformatted(res);
|
||||
memcpy(output, ret_char, sizeof(ret_char)+1);
|
||||
|
||||
cJSON_Delete(res);
|
||||
return RET_OK;
|
||||
|
||||
/*把本地Portal server的配置信息存入全局变量 */
|
||||
jumpurl = jump_url;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
localportal_configure_t *localportal;
|
||||
|
||||
/*全局变量初始化 失败为1 成功为0*/
|
||||
int Init(localportal_configure_t *localportal)
|
||||
int localportalInit(localportal_configure_t *localportal)
|
||||
{
|
||||
localportal = (localportal_configure_t *)malloc(sizeof * localportal);
|
||||
if (NULL == localportal)
|
||||
|
@ -107,7 +107,7 @@ ret_code portalserver_config_chk(uint source, uint config_type,
|
|||
|
||||
|
||||
/*系统管理模块将数据内容(IP地址、端口号)发送给web server */
|
||||
int portalserver_config_proc(uint source, uint config_type,
|
||||
ret_code portalserver_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
|
@ -120,14 +120,15 @@ int portalserver_config_proc(uint source, uint config_type,
|
|||
inet_ntop(AF_INET, (void *)&struct_portal->ip, str, 32);
|
||||
char *ip_addr = str;
|
||||
rpc_log_info("portalserver configure: ip: %s port: %d\n",
|
||||
struct_portal->ip, struct_portal->port);
|
||||
ip_addr, struct_portal->port);
|
||||
|
||||
/*将配置信息发送到web server */
|
||||
|
||||
/*把本地Portal server的配置信息存入全局变量 */
|
||||
localportal = struct_portal;
|
||||
|
||||
return 0;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
#include <cjson/cJSON.h>
|
||||
#include "configm.h"
|
||||
#include "user_group_config.h"
|
||||
#include "rpc.h"
|
||||
#include "parsefile.h"
|
||||
|
||||
/* 用户组处理函数数组 */
|
||||
static usergroup_config gs_usergroup_fun_table[] = {
|
||||
usergroup_config_add_proc
|
||||
};
|
||||
|
||||
/* check暂时不做操作,所有的检查在业务接口中完成 */
|
||||
ret_code usergroup_config_chk(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
|
@ -54,26 +60,31 @@ ret_code usergroup_config_chk(uint source, uint config_type,
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* 新增用户组-处理 */
|
||||
/*
|
||||
* 新增用户组-处理
|
||||
* input格式:{"type": 0,"data": {"gname": "xxx","gdescription": "xxx"}}
|
||||
*/
|
||||
ret_code usergroup_config_add_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
unsigned short result;
|
||||
cJSON *root, *name, *description, *res;
|
||||
cJSON *root, *data, *name, *description, *res;
|
||||
char *des = NULL;
|
||||
char *ret_char = NULL;
|
||||
|
||||
root = cJSON_Parse(input);
|
||||
if(!root)
|
||||
data = cJSON_GetObjectItem(root, "data");
|
||||
if(!data)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
ASSERT_RET(ret);
|
||||
cJSON_Delete(root);
|
||||
return ret;
|
||||
}
|
||||
|
||||
name = cJSON_GetObjectItem(root, "gname");
|
||||
name = cJSON_GetObjectItem(data, "gname");
|
||||
if(!name)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
|
@ -82,7 +93,7 @@ ret_code usergroup_config_add_proc(uint source, uint config_type,
|
|||
return ret;
|
||||
}
|
||||
|
||||
description = cJSON_GetObjectItem(root, "gdescription");
|
||||
description = cJSON_GetObjectItem(data, "gdescription");
|
||||
if(description)
|
||||
{
|
||||
des = description->valuestring;
|
||||
|
@ -107,39 +118,54 @@ ret_code usergroup_config_add_proc(uint source, uint config_type,
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*用户组配置处理
|
||||
*input格式:{"type": 0,"data": {xxx}}
|
||||
*output格式:{"result": 0}
|
||||
*/
|
||||
ret_code usergroup_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
int code;
|
||||
int fun_type;
|
||||
int usergroup_fun_table_len;
|
||||
cJSON *root, *type, *data;
|
||||
|
||||
switch(config_type)
|
||||
//获取函数数组的长度
|
||||
usergroup_fun_table_len = sizeof(gs_usergroup_fun_table)/sizeof(gs_usergroup_fun_table[0]);
|
||||
|
||||
//解析input,获取type
|
||||
root = cJSON_Parse(input);
|
||||
if(!root)
|
||||
{
|
||||
case CM_CONFIG_ADD:
|
||||
ret = usergroup_config_add_proc(source, config_type,
|
||||
input, input_len,
|
||||
output, output_len);
|
||||
break;
|
||||
case CM_CONFIG_DEL:
|
||||
ret = usergroup_config_del_proc(source, config_type,
|
||||
input, input_len,
|
||||
output, output_len);
|
||||
break;
|
||||
case CM_CONFIG_GET:
|
||||
ret = usergroup_config_get_proc(source, config_type,
|
||||
input, input_len,
|
||||
output, output_len);
|
||||
break;
|
||||
case CM_CONFIG_GET_ALL:
|
||||
ret = usergroup_config_getall_proc(source, config_type,
|
||||
input, input_len,
|
||||
output, output_len);
|
||||
break;
|
||||
default:
|
||||
ret = RET_NOTSUPPORT;
|
||||
ret = RET_INPUTERR;
|
||||
ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
type = cJSON_GetObjectItem(root, "type");
|
||||
if(!type)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
ASSERT_RET(ret);
|
||||
cJSON_Delete(root);
|
||||
return ret;
|
||||
}
|
||||
fun_type = type->valueint;
|
||||
|
||||
//type在数组长度的范围内,执行数组内的函数,否则 ret = RET_NOTSUPPORT;
|
||||
if(fun_type < 0 || fun_type >= usergroup_fun_table_len)
|
||||
{
|
||||
ret = RET_NOTSUPPORT;
|
||||
ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = gs_usergroup_fun_table[fun_type](source, config_type,
|
||||
input, input_len,
|
||||
output, output_len);
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
#include "../../../../common/rpc/rpc.h"
|
||||
#include "../include/parsefile.h"
|
||||
#include "../include/configm.h"
|
||||
#include "../../../netlink_uapi/libnetlinku.h"
|
||||
#include <cjson/cJSON.h>
|
||||
#include "../../../../../Common/s2j/s2j.h"
|
||||
#include "../../../../../Common/commuapinl.h"
|
||||
#include "../include/userlock.h"
|
||||
|
||||
|
||||
/*全局变量,存放锁定功能的信息 */
|
||||
userlock_configure_t *userlock;
|
||||
|
||||
|
||||
/*全局变量初始化 失败为1 成功为0*/
|
||||
int Init(userlock_configure_t *userlock)
|
||||
{
|
||||
userlock = (userlock_configure_t *)malloc(sizeof * userlock);
|
||||
if (NULL == userlock)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*判断锁定配置信息是否有效,时间范围大于0,失败的次数大于0,锁定时间大于0 */
|
||||
ret_code userlock_config_chk(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
userlock_configure_t *struct_userlock;
|
||||
struct_userlock = (userlock_configure_t *)input;
|
||||
|
||||
if(input_len < sizeof(userlock_configure_t) )
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
}
|
||||
|
||||
/*配置的用户失败次数如果小于0,则配置错误 */
|
||||
if(struct_userlock->failcount < FAIL_MIN_NUM )
|
||||
{
|
||||
ret = RET_ERR;
|
||||
printf("userlock configure error\n");
|
||||
}
|
||||
|
||||
/*配置的用户锁定时间如果小于0,则配置错误 */
|
||||
if(struct_userlock->locktime < LOCK_MIN_TIME )
|
||||
{
|
||||
ret = RET_ERR;
|
||||
printf("locktime configure error\n");
|
||||
}
|
||||
|
||||
/*配置的用户认证时间范围如果小于0,则配置错误 */
|
||||
if(struct_userlock->timehorizon < HORIZON_MIN_VALUE )
|
||||
{
|
||||
ret = RET_ERR;
|
||||
printf("timehorizon configure error\n");
|
||||
}
|
||||
|
||||
ASSERT_RET(ret);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
/*系统管理模块将数据内容(IP地址、端口号)发送给web server */
|
||||
ret_code userlock_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
userlock_configure_t *struct_userlock;
|
||||
struct_userlock = (userlock_configure_t *)input;
|
||||
|
||||
rpc_log_info("userlock configure: 登录时间: %d 用户认证失败次数: %d 用户认证的时间范围: %d 用户锁定时间: %ld\n",
|
||||
struct_userlock->logintime, struct_userlock->failcount,
|
||||
struct_userlock->timehorizon, struct_userlock->locktime);
|
||||
|
||||
|
||||
/*将配置信息struct_userlock发送到数据库 */
|
||||
|
||||
/*把本地Portal server的配置信息存入全局变量 */
|
||||
userlock = struct_userlock;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
# target name, the target name must have the same name of c source file
|
||||
TARGET_NAME=demo
|
||||
|
||||
# target
|
||||
# target
|
||||
# for linux module driver: KO
|
||||
# for application: EXE
|
||||
# for dynamic library: DLL
|
||||
|
@ -14,7 +14,7 @@ TARGET_OBJ = APP
|
|||
|
||||
# custom install dir
|
||||
TARGET_BOX =
|
||||
|
||||
|
||||
#debug mode or release mode
|
||||
DEBUG = TRUE
|
||||
|
||||
|
@ -42,7 +42,7 @@ COMMON_LIBS := -lcjson
|
|||
LINUX_LIBS := $(COMMON_LIBS)
|
||||
ARM64_LIBS := $(COMMON_LIBS)
|
||||
|
||||
# this line must be at below of thus, because of...
|
||||
# this line must be at below of thus, because of...
|
||||
include ../../Common/common.Makefile
|
||||
|
||||
ifneq ($(MAKECMDGOALS), clean)
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
# target name, the target name must have the same name of c source file
|
||||
TARGET_NAME=usermanager
|
||||
|
||||
# target
|
||||
# for linux module driver: KO
|
||||
# for application: EXE
|
||||
# for dynamic library: DLL
|
||||
TARGET_TYPE = DLL
|
||||
|
||||
# target object
|
||||
# for application: APP
|
||||
# for device driver: DRV
|
||||
TARGET_OBJ = APP
|
||||
|
||||
# custom install dir
|
||||
TARGET_BOX =
|
||||
|
||||
#debug mode or release mode
|
||||
DEBUG = TRUE
|
||||
|
||||
PLAT_LINUX ?= TRUE
|
||||
PLAT_ARM64 ?= TRUE
|
||||
|
||||
VPATH = ../user/user_manager/
|
||||
|
||||
# source code
|
||||
|
||||
# set the source file, don't used .o because of ...
|
||||
|
||||
COMMON_SRCS = array_index.c user_group.c user.c user_mod.c
|
||||
|
||||
# MRS Board Source Files
|
||||
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
||||
PLAT_ARM64_SRCS = $(COMMON_SRCS)
|
||||
|
||||
# gcc CFLAGS
|
||||
PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common
|
||||
PLAT_LINUX_CFLAGS := -fPIC -I../../Common -I../common
|
||||
|
||||
PLAT_ARM64_LDFLAGS := -fPIC -shared -lpthread
|
||||
PLAT_LINUX_LDFLAGS := $(PLAT_ARM64_LDFLAGS)
|
||||
|
||||
|
||||
# this line must be at below of thus, because of...
|
||||
include ../../Common/common.Makefile
|
||||
|
||||
ifneq ($(MAKECMDGOALS), clean)
|
||||
ifneq ($(MAKECMDGOALS), cleanall)
|
||||
ifneq ($(notdir $(DEPEND_LIB)), $(wildcard $(DEPEND_LIB)))
|
||||
$(shell $(CP) $(DEPEND_LIB) ./)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(MAKECMDGOALS), )
|
||||
$(shell find ./ -name "$(TARGET)-*.ko" -delete)
|
||||
else
|
||||
ifeq ($(MAKECMDGOALS), all)
|
||||
$(shell find ./ -name "$(TARGET)-*.ko" -delete)
|
||||
endif
|
||||
endif
|
||||
|
|
@ -5,6 +5,8 @@
|
|||
#define GETID(ID, NAME1, NAME2) ((((ID) != 0) && (strcmp((NAME1), (NAME2)) == 0)) ? (ID) : 0) //根据name查询ID
|
||||
#define CHECKOUTARG(element) ((NULL == (element) || "" == (element) || SPECHAR(element)) ? true : false) //校验参数
|
||||
#define INVALID_INDEX (0)
|
||||
#define INIT_FAIL -1
|
||||
#define INIT_SUCCESS 0
|
||||
|
||||
#define TIME_T2STRING(time_int, time_char) (strftime((time_char), 20, "%Y-%m-%d %H:%M:%S", (localtime(&time_int))))
|
||||
#define STRING2TIME_T(time_char,time_int) \
|
||||
|
@ -19,4 +21,12 @@ do { \
|
|||
time_int = mktime(&tm_time); \
|
||||
} while (0)
|
||||
|
||||
#define MULTI_MASK 0x0002
|
||||
#define VALID_MASK 0x0001
|
||||
|
||||
#define MULTI_GET(element) ((element) >> 1)
|
||||
#define MULTI_SET(element, value) (((element) & VALID_MASK) | (((value) << 1) & MULTI_MASK))
|
||||
#define VALID_GET(element) ((element) & VALID_MASK)
|
||||
#define VALID_SET(element, value) (((element) & MULTI_MASK) | ((value) & VALID_MASK))
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include<stdlib.h>
|
||||
#include<stdbool.h>
|
||||
#include "array_index.h"
|
||||
#include "../../common/common_user.h"
|
||||
#include "common_user.h"
|
||||
|
||||
ARRAY g_user_index_head = { 0 };
|
||||
ARRAY g_group_index_head = { 0 };
|
||||
|
@ -36,7 +36,7 @@ int init_array(ARRAY* head, int index_size)
|
|||
head->array = malloc(sizeof(head->array) * index_size);
|
||||
if (NULL == head->array)
|
||||
{
|
||||
return 1;
|
||||
return INIT_FAIL;
|
||||
}
|
||||
|
||||
//head->cur = 1;
|
||||
|
@ -57,7 +57,7 @@ int init_array(ARRAY* head, int index_size)
|
|||
/*初始化最后一个值*/
|
||||
head->array[i] = HI_ELEMENT_SET(head->array[i], i - 1);
|
||||
head->array[i] = LOW_ELEMENT_SET(head->array[i], 0);
|
||||
return 0;
|
||||
return INIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* 顺序分配index */
|
||||
|
|
|
@ -1,28 +1,21 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "../../common/common_user.h"
|
||||
#include <string.h>
|
||||
#include "common_user.h"
|
||||
#include "array_index.h"
|
||||
#include "user_group.h"
|
||||
#include "user.h"
|
||||
|
||||
#define MULTI_MASK 0x0002
|
||||
#define VALID_MASK 0x0001
|
||||
|
||||
#define MULTI_GET(element) ((element) >> 1)
|
||||
#define MULTI_SET(element, value) (((element) & VALID_MASK) | (((value) << 1) & MULTI_MASK))
|
||||
#define VALID_GET(element) ((element) & VALID_MASK)
|
||||
#define VALID_SET(element, value) (((element) & MULTI_MASK) | ((value) & VALID_MASK))
|
||||
#include "user_mod.h"
|
||||
#include "sg/user/user_manager/user_group.h"
|
||||
#include "sg/user/user_manager/user.h"
|
||||
|
||||
extern ARRAY g_user_index_head;
|
||||
extern USERGROUP g_group_table[GROUP_INDEX_MAX];
|
||||
extern USERGROUP g_group_table[];
|
||||
extern exce_mod_user g_user_modfunc_table[];
|
||||
USERACCOUNT g_user_table[USER_INDEX_MAX];
|
||||
|
||||
/*初始化参数*/
|
||||
int init_user()
|
||||
{
|
||||
const int INIT_FAIL = 1;
|
||||
const int INIT_SUCCESS = 0;
|
||||
/* 初始化用户的index */
|
||||
int init_result = init_array(&g_user_index_head, USER_INDEX_MAX);
|
||||
if (INIT_FAIL == init_result)
|
||||
|
@ -35,19 +28,11 @@ int init_user()
|
|||
}
|
||||
|
||||
/*添加元素-新增用户*/
|
||||
USERADD* add_user(char* uname, char* gname, USERADD* uaddres)
|
||||
void usermanager_add_user(char* uname, char* gname, USERADD* uaddres)
|
||||
{
|
||||
const int ADD_FAIL_NOGROUP = 1;
|
||||
const int ADD_FAIL_NAMELEN = 2;
|
||||
const int ADD_FAIL_NAMESPE = 3;
|
||||
const int ADD_FAIL_NAMEDUP = 4;
|
||||
const int ADD_FAIL_USERFULL = 5;
|
||||
const int ADD_SUCCESS = 0;
|
||||
const char DEFAULT_PWD[8] = "123456";
|
||||
|
||||
if (NULL == uaddres)
|
||||
{
|
||||
return NULL;
|
||||
return;
|
||||
}
|
||||
uaddres->userID = INVALID_INDEX;
|
||||
|
||||
|
@ -55,22 +40,27 @@ USERADD* add_user(char* uname, char* gname, USERADD* uaddres)
|
|||
if (NULL == uname || (UNAMESIZE) < strlen(uname) || 0 >= strlen(uname))
|
||||
{
|
||||
uaddres->result = ADD_FAIL_NAMELEN;
|
||||
return uaddres;
|
||||
return;
|
||||
}
|
||||
|
||||
/* 校验用户名中不含特殊字符 */
|
||||
if (SPECHAR(uname))
|
||||
{
|
||||
uaddres->result = ADD_FAIL_NAMESPE;
|
||||
return uaddres;
|
||||
return;
|
||||
}
|
||||
|
||||
/* 根据用户组名查询用户组ID */
|
||||
unsigned short GID_temp = get_groupid_by_name(gname);
|
||||
if (CHECKOUTARG(gname) || INVALID_INDEX == GID_temp)
|
||||
if(NULL == gname)
|
||||
{
|
||||
uaddres->result = ADD_FAIL_NOGROUP;
|
||||
return uaddres;
|
||||
return;
|
||||
}
|
||||
unsigned short GID_temp = get_groupid_by_name(gname);
|
||||
if(INVALID_INDEX == GID_temp)
|
||||
{
|
||||
uaddres->result = ADD_FAIL_NOGROUP;
|
||||
return;
|
||||
}
|
||||
|
||||
/* 校验重名 */
|
||||
|
@ -79,7 +69,7 @@ USERADD* add_user(char* uname, char* gname, USERADD* uaddres)
|
|||
if (0 == strcmp(uname, g_user_table[i].uname))
|
||||
{
|
||||
uaddres->result = ADD_FAIL_NAMEDUP;
|
||||
return uaddres;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,14 +78,14 @@ USERADD* add_user(char* uname, char* gname, USERADD* uaddres)
|
|||
if (INVALID_INDEX == ID)
|
||||
{
|
||||
uaddres->result = ADD_FAIL_USERFULL;
|
||||
return uaddres;
|
||||
return;
|
||||
}
|
||||
|
||||
/* 存内存 */
|
||||
g_user_table[ID].ID = ID;
|
||||
g_user_table[ID].GID = GID_temp;
|
||||
strcpy(g_user_table[ID].uname, uname);
|
||||
strcpy(g_user_table[ID].passwd, DEFAULT_PWD);
|
||||
strcpy(g_user_table[ID].passwd, "123456");
|
||||
|
||||
/* 连接数据库,存user表 */
|
||||
/* INSERT INTO `user` SET id = , group_id = , user_name = "", password = "", multi_player = , valid_always = */
|
||||
|
@ -103,5 +93,179 @@ USERADD* add_user(char* uname, char* gname, USERADD* uaddres)
|
|||
uaddres->result = ADD_SUCCESS;
|
||||
uaddres->userID = ID;
|
||||
|
||||
return uaddres;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* 按用户ID查询用户 */
|
||||
void get_user_by_id(unsigned short ID, USERLIST* ulist)
|
||||
{
|
||||
unsigned short temp_multi, temp_valid;
|
||||
char temp_begin_time[UTIME] = { 0 };
|
||||
char temp_end_time[UTIME] = { 0 };
|
||||
|
||||
if (NULL == ulist || INVALID_INDEX >= ID || (USER_INDEX_MAX - 1) <= ID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
memset(ulist, 0, sizeof(ulist));
|
||||
|
||||
/* 内存查询用户 */
|
||||
temp_multi = MULTI_GET(g_user_table[ID].multi_valid);
|
||||
temp_valid = VALID_GET(g_user_table[ID].multi_valid);
|
||||
|
||||
ulist->ID = ID;
|
||||
ulist->GID = g_user_table[ID].GID;
|
||||
ulist->multi = temp_multi;
|
||||
ulist->valid = temp_valid;
|
||||
strcpy(ulist->uname, g_user_table[ID].uname);
|
||||
strcpy(ulist->gname, g_group_table[ulist->GID].gname);
|
||||
strcpy(ulist->udescription, g_user_table[ID].udescription);
|
||||
strcpy(ulist->passwd, g_user_table[ID].passwd);
|
||||
|
||||
if (1 == temp_valid)
|
||||
{
|
||||
TIME_T2STRING(g_user_table[ID].valid_begin_time, temp_begin_time);
|
||||
TIME_T2STRING(g_user_table[ID].valid_end_time, temp_end_time);
|
||||
}
|
||||
|
||||
strcpy(ulist->valid_begin_time, temp_begin_time);
|
||||
strcpy(ulist->valid_end_time, temp_end_time);
|
||||
|
||||
/* 查数据库,这里查数据库没上面快 */
|
||||
/* SELECT id, group_id, multi_player, valid_always, user_name, udescription,valid_begin_time,valid_end_time FROM `user`WHERE id = */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* 修改用户-web */
|
||||
bool mod_user_web(USERLIST* ulist)
|
||||
{
|
||||
USERLIST* temp_user;
|
||||
time_t cur_time;
|
||||
/* 可以修改的数据:用户组ID、描述、密码、公用账号、永久有效、有效期开始时间、有效期结束时间 */
|
||||
if (NULL == ulist || INVALID_INDEX == ulist->ID || INVALID_INDEX == ulist->GID)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 校验描述长度 */
|
||||
if (NULL != ulist->udescription)
|
||||
{
|
||||
if (UDESIZE < strlen(ulist->udescription))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* 校验密码长度 */
|
||||
if (NULL != ulist->passwd)
|
||||
{
|
||||
if (8 >= strlen(ulist->passwd) || 24 <= strlen(ulist->passwd))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
temp_user = (USERLIST*)malloc(sizeof(USERLIST));
|
||||
if (NULL == temp_user)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
get_user_by_id(ulist->ID, temp_user);
|
||||
|
||||
/* 更新内存数据 */
|
||||
strcpy(g_user_table[ulist->ID].udescription, ulist->udescription);
|
||||
strcpy(g_user_table[ulist->ID].passwd, ulist->passwd);
|
||||
|
||||
g_user_table[ulist->ID].GID = ulist->GID;
|
||||
g_user_table[ulist->ID].multi_valid = MULTI_SET(g_user_table[ulist->ID].multi_valid, ulist->multi);
|
||||
g_user_table[ulist->ID].multi_valid = VALID_SET(g_user_table[ulist->ID].multi_valid, ulist->valid);
|
||||
/* 更新有效日期时间 */
|
||||
if (1 == ulist->valid)
|
||||
{
|
||||
//if(判断是否符合格式)
|
||||
|
||||
STRING2TIME_T(ulist->valid_begin_time, g_user_table[ulist->ID].valid_begin_time);
|
||||
STRING2TIME_T(ulist->valid_end_time, g_user_table[ulist->ID].valid_end_time);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* 连接数据库,更显user表 */
|
||||
/* UPDATE `user` u SET u.group_id = ,u.udescription = "", u.`password` = "", u.multi_player = , u.valid_always = , u.valid_begin_time = "", u.valid_end_time = "" WHERE u.id = ; */
|
||||
|
||||
/* 调用接口,查询该用户是否有在线IP */
|
||||
/* 如果没有,直接return */
|
||||
|
||||
/* 密码发生改变,下线用户 */
|
||||
if (0 != strcmp(ulist->passwd, temp_user->passwd))
|
||||
{
|
||||
/* 下线用户,return */
|
||||
}
|
||||
|
||||
/* 公用账号改为单用户登陆,下线用户 */
|
||||
if (1 == ulist->multi && 0 == temp_user->multi)
|
||||
{
|
||||
/* 下线用户,return */
|
||||
}
|
||||
|
||||
/* 当前时间不在有效期内,下线用户 */
|
||||
if (1 == VALID_GET(g_user_table[ulist->ID].multi_valid))
|
||||
{
|
||||
cur_time = time(NULL);
|
||||
if (cur_time < g_user_table[ulist->ID].valid_begin_time || cur_time > g_user_table[ulist->ID].valid_end_time)
|
||||
{
|
||||
/* 下线用户,return */
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned short get_userid_by_name(char* uname)
|
||||
{
|
||||
/* 内存查询数据 */
|
||||
unsigned short UID_temp = INVALID_INDEX;
|
||||
if (NULL == uname)
|
||||
{
|
||||
return UID_temp;
|
||||
}
|
||||
for (int i = 0; i < USER_INDEX_MAX && UID_temp == INVALID_INDEX; i++)
|
||||
{
|
||||
UID_temp = GETID(g_user_table[i].ID, uname, g_user_table[i].uname);
|
||||
}
|
||||
|
||||
/* 连接数据库,根据用户组名查询user表中的id */
|
||||
/* SELECT id FROM user WHERE user_name = "" */
|
||||
|
||||
return UID_temp;
|
||||
}
|
||||
|
||||
/* 修改用户-命令行 */
|
||||
bool mod_user_line(char* uname, const int intype, char* in)
|
||||
{
|
||||
unsigned short uid;
|
||||
bool result = true;
|
||||
if (NULL == uname || NULL == in)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 检查修改类型 */
|
||||
if (intype < 0 || intype >= USER_ATTRIBUTE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 根据用户名查询用户ID */
|
||||
uid = get_userid_by_name(uname);
|
||||
if (INVALID_INDEX == uid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*(0)描述、(1)所属组名、(2)登陆密码、(3)公用账号、(4)永久有效、(5)有效期开始时间、(6)有效期结束时间 */
|
||||
result = g_user_modfunc_table[intype](uid, in);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
#ifndef USER_H_
|
||||
#define USER_H_
|
||||
#include <time.h>
|
||||
#include "user_group.h"
|
||||
|
||||
#define UNAMESIZE (127 + 1)
|
||||
#define UDESIZE (127 + 1)
|
||||
#define UPWDSIZE (63 + 1)
|
||||
#define UTIME 20
|
||||
|
||||
typedef struct user
|
||||
{
|
||||
unsigned short ID; //用户id
|
||||
char uname[UNAMESIZE]; //用户名
|
||||
char udescription[UDESIZE]; //用户描述
|
||||
int GID; //用户组ID
|
||||
char passwd[UPWDSIZE]; //密码
|
||||
unsigned short multi_valid; //多人登陆、永久有效
|
||||
time_t valid_begin_time; //有效期开始时间
|
||||
time_t valid_end_time; //有效期结束时间
|
||||
}USERACCOUNT;
|
||||
|
||||
typedef struct result_user_add
|
||||
{
|
||||
int result;
|
||||
int userID;
|
||||
}USERADD;
|
||||
|
||||
/*初始化参数*/
|
||||
int init_user();
|
||||
|
||||
/*添加元素-新增用户*/
|
||||
USERADD* add_user(char* UNAME, char* UGNAME, USERADD* UADDRES);
|
||||
|
||||
#endif
|
|
@ -1,9 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "array_index.h"
|
||||
#include "user_group.h"
|
||||
#include "../../common/common_user.h"
|
||||
#include "sg/user/user_manager/user_group.h"
|
||||
#include "common_user.h"
|
||||
|
||||
extern ARRAY g_group_index_head;
|
||||
USERGROUP g_group_table[GROUP_INDEX_MAX];
|
||||
|
@ -11,9 +12,6 @@ USERGROUP g_group_table[GROUP_INDEX_MAX];
|
|||
/* 初始化参数 */
|
||||
int init_group()
|
||||
{
|
||||
const int INIT_FAIL = 1;
|
||||
const int INIT_SUCCESS = 0;
|
||||
|
||||
/* 初始化用户组的index */
|
||||
int init_result = init_array(&g_group_index_head, GROUP_INDEX_MAX);
|
||||
if (INIT_FAIL == init_result)
|
||||
|
@ -27,12 +25,6 @@ int init_group()
|
|||
/* 添加元素 */
|
||||
unsigned short add_group(char* name, char* description)
|
||||
{
|
||||
const int ADD_SUCCESS = 0;
|
||||
const int ADD_FAIL_FULL = 1;
|
||||
const int ADD_FAIL_LENGTH = 2;
|
||||
const int ADD_FAIL_SPECHARS = 3;
|
||||
const int ADD_FAIL_DUP = 4;
|
||||
|
||||
/* 校验用户组名和描述的长度 */
|
||||
if (NULL == description)
|
||||
{
|
||||
|
@ -176,10 +168,6 @@ unsigned short get_groupid_by_name(char* gname)
|
|||
/*删除元素*/
|
||||
unsigned short del_group_by_name(char* gname)
|
||||
{
|
||||
const int DEL_SUCCESS = 0;
|
||||
const int DEL_FAIL_NOTEXIST = 1;
|
||||
const int DEL_FAIL_STRTEGY = 2;
|
||||
|
||||
if (CHECKOUTARG(gname))
|
||||
{
|
||||
return DEL_FAIL_NOTEXIST;
|
||||
|
|
|
@ -0,0 +1,153 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "user_mod.h"
|
||||
#include "sg/user/user_manager/user_group.h"
|
||||
#include "sg/user/user_manager/user.h"
|
||||
#include "array_index.h"
|
||||
#include "common_user.h"
|
||||
|
||||
/* 修改用户函数数组 */
|
||||
exce_mod_user g_user_modfunc_table[USER_ATTRIBUTE_NUM] = {mod_user_des,
|
||||
mod_user_group,
|
||||
mod_user_passwd,
|
||||
mod_user_multi,
|
||||
mod_user_valid,
|
||||
mod_user_valid_begin_time,
|
||||
mod_user_valid_end_time};
|
||||
|
||||
extern USERACCOUNT g_user_table[USER_INDEX_MAX];
|
||||
|
||||
bool mod_user_des(unsigned short uid, char* des)
|
||||
{
|
||||
if (UDESIZE < strlen(des))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
strcpy(g_user_table[uid].udescription, des);
|
||||
|
||||
/* 连接数据库,修改user表中的描述 */
|
||||
/* UPDATE `user` u SET u.udescription = "" WHERE u.id = ; */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mod_user_group(unsigned short uid, char* gname)
|
||||
{
|
||||
unsigned short gid = get_groupid_by_name(gname);
|
||||
if (INVALID_INDEX == gid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
g_user_table[uid].GID = gid;
|
||||
|
||||
/* 连接数据库,修改user表中的用户组id */
|
||||
/* UPDATE `user` u SET u.group_id = WHERE u.id = ; */
|
||||
|
||||
/* 强制用户下线 */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mod_user_passwd(unsigned short uid, char* passwd)
|
||||
{
|
||||
if (8 >= strlen(passwd) || 24 <= strlen(passwd))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
strcpy(g_user_table[uid].passwd, passwd);
|
||||
|
||||
/* 连接数据库,修改user表中的密码 */
|
||||
/* UPDATE `user` u SET u.password = WHERE u.id = ; */
|
||||
|
||||
/* 强制用户下线 */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mod_user_multi(unsigned short uid, char* multi)
|
||||
{
|
||||
unsigned short multi_old;
|
||||
unsigned short multi_new = atoi(multi);
|
||||
if (0 != multi_new && 1 != multi_new)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
multi_old = MULTI_GET(g_user_table[uid].multi_valid);
|
||||
g_user_table[uid].multi_valid = MULTI_SET(g_user_table[uid].multi_valid, multi_new);
|
||||
|
||||
/* 连接数据库,修改user表中的multi_player */
|
||||
/* UPDATE `user` u SET u.multi_player = WHERE u.id = ; */
|
||||
|
||||
if (0 == multi_old && 1 == multi_new)
|
||||
{
|
||||
/* 强制用户下线 */
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void mod_user_valid_offline(unsigned short uid)
|
||||
{
|
||||
time_t cur_time;
|
||||
|
||||
if (1 == VALID_GET(g_user_table[uid].multi_valid))
|
||||
{
|
||||
cur_time = time(NULL);
|
||||
if (cur_time < g_user_table[uid].valid_begin_time || cur_time > g_user_table[uid].valid_end_time)
|
||||
{
|
||||
/* 强制用户下线 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool mod_user_valid(unsigned short uid, char* valid)
|
||||
{
|
||||
unsigned short valid_new = atoi(valid);
|
||||
//校验数据
|
||||
if (0 != valid_new && 1 != valid_new)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
g_user_table[uid].multi_valid = VALID_SET(g_user_table[uid].multi_valid, valid_new);
|
||||
|
||||
/* 连接数据库,修改user表中的valid_always */
|
||||
/* UPDATE `user` u SET u.valid_always = WHERE u.id = ; */
|
||||
|
||||
mod_user_valid_offline(uid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mod_user_valid_begin_time(unsigned short uid, char* valid_start_time)
|
||||
{
|
||||
time_t temp_time;
|
||||
|
||||
/* 校验vaild是否符合"%Y-%m-%d %H:%M:%S"格式,不符合直接return */
|
||||
|
||||
STRING2TIME_T(valid_start_time, temp_time);
|
||||
g_user_table[uid].valid_begin_time = temp_time;
|
||||
|
||||
/* 连接数据库,修改user表中的valid_begin_time */
|
||||
/* UPDATE `user` u SET u.valid_begin_time = WHERE u.id = ; */
|
||||
|
||||
mod_user_valid_offline(uid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mod_user_valid_end_time(unsigned short uid, char* valid_end_time)
|
||||
{
|
||||
time_t temp_time;
|
||||
/* 校验vaild是否符合"%Y-%m-%d %H:%M:%S"格式,不符合直接return */
|
||||
|
||||
STRING2TIME_T(valid_end_time, temp_time);
|
||||
g_user_table[uid].valid_end_time = temp_time;
|
||||
|
||||
/* 连接数据库,修改user表中的valid_end_time */
|
||||
/* UPDATE `user` u SET u.valid_end_time = WHERE u.id = ; */
|
||||
|
||||
mod_user_valid_offline(uid);
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef USER_MOD_H_
|
||||
#define USER_MOD_H_
|
||||
#include <stdbool.h>
|
||||
|
||||
/* 修改用户属性的函数指针 */
|
||||
typedef bool (*exce_mod_user)(unsigned short, char*);
|
||||
/* 修改用户描述 */
|
||||
bool mod_user_des(unsigned short uid, char *in);
|
||||
/* 修改用户组 */
|
||||
bool mod_user_group(unsigned short uid, char* in);
|
||||
/* 修改用户密码 */
|
||||
bool mod_user_passwd(unsigned short uid, char* in);
|
||||
/* 修改多用户登陆 */
|
||||
bool mod_user_multi(unsigned short uid, char* in);
|
||||
/* 修改用户永久有效 */
|
||||
bool mod_user_valid(unsigned short uid, char* in);
|
||||
/* 修改有效期开始时间 */
|
||||
bool mod_user_valid_begin_time(unsigned short uid, char* valid);
|
||||
/* 修改有效期结束时间 */
|
||||
bool mod_user_valid_end_time(unsigned short uid, char* valid);
|
||||
|
||||
|
||||
#endif
|
|
@ -40,9 +40,11 @@
|
|||
|
||||
## **编译方法**
|
||||
#### 1. 从仓库获取最新代码
|
||||
<code>git clone git@git.komect.net:ISG/secogateway.git</code>
|
||||
<code>git clone --recursive git@git.komect.net:ISG/secogateway.git
|
||||
git submodule update --init --recursive</code>
|
||||
或
|
||||
<code>git pull</code>
|
||||
<code>git submodule update --init --recursive
|
||||
git pull</code>
|
||||
|
||||
#### 2. 安装必要软件(UBuntu)
|
||||
<code>sudo ./fsl-qoriq-glibc-x86_64-fsl-toolchain-aarch64-toolchain-2.4.1.sh
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#ifndef __S2J_H__
|
||||
#define __S2J_H__
|
||||
|
||||
#include <cJSON/cJSON.h>
|
||||
#include <cjson/cJSON.h>
|
||||
#include <string.h>
|
||||
#include "s2jdef.h"
|
||||
|
||||
|
@ -80,10 +80,6 @@ extern "C" {
|
|||
#define s2j_struct_get_struct_element(child_struct, to_struct, child_json, from_json, type, element) \
|
||||
S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, element)
|
||||
|
||||
/* s2j.c */
|
||||
extern S2jHook s2jHook;
|
||||
void s2j_init(S2jHook *hook);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -29,8 +29,9 @@
|
|||
#ifndef __S2JDEF_H__
|
||||
#define __S2JDEF_H__
|
||||
|
||||
#include <cJSON/cJSON.h>
|
||||
#include <cjson/cJSON.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -116,11 +117,11 @@ typedef struct {
|
|||
|
||||
#define S2J_CREATE_STRUCT_OBJECT(struct_obj, type) \
|
||||
cJSON *json_temp; \
|
||||
type *struct_obj = s2jHook.malloc_fn(sizeof(type)); \
|
||||
type *struct_obj = malloc(sizeof(type)); \
|
||||
if (struct_obj) memset(struct_obj, 0, sizeof(type));
|
||||
|
||||
#define S2J_DELETE_STRUCT_OBJECT(struct_obj) \
|
||||
s2jHook.free_fn(struct_obj);
|
||||
free(struct_obj);
|
||||
|
||||
#define S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, _element) \
|
||||
S2J_STRUCT_GET_##type##_ELEMENT(to_struct, from_json, _element)
|
||||
|
|
Loading…
Reference in New Issue