Mod aaa-12 按照公司checkstyle修改自研代码,完善测试用例
RCA: SOL: 修改人:dongxiancun 检视人:dongxiancun
This commit is contained in:
parent
944512546a
commit
242a1b35a1
ControlPlatform/aaa/aaa-shiro/impl/src
main/java/org/opendaylight/aaa
AAAShiroProvider.java
datastore/h2
AbstractStore.javaConnectionProvider.javaDomainStore.javaGrantStore.javaH2Store.javaH2TokenStore.javaIdmLightConfig.javaIdmLightSimpleConnectionProvider.javaRoleStore.javaStoreException.javaUserStore.java
shiro/idm
test/java/org/opendaylight/aaa
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue