提交 4cdc0ab5 编写于 作者: T tombaeyens

ACT-162 making the identity component pluggable

上级 dc6d9110
......@@ -155,6 +155,7 @@ public class ProcessEngineBuilder {
ConfigurationParser cfgParser = new ConfigurationParser();
ConfigurationParse cfgParse = cfgParser.createParse()
// .processEngineConfiguration(processEngineConfiguration)
.sourceInputStream(inputStream)
.execute();
......
......@@ -18,7 +18,11 @@ import org.activiti.engine.identity.GroupQuery;
import org.activiti.engine.identity.User;
import org.activiti.engine.identity.UserQuery;
import org.activiti.engine.impl.cmd.CheckPassword;
import org.activiti.engine.impl.cmd.CreateGroupCmd;
import org.activiti.engine.impl.cmd.CreateGroupQueryCmd;
import org.activiti.engine.impl.cmd.CreateMembershipCmd;
import org.activiti.engine.impl.cmd.CreateUserCmd;
import org.activiti.engine.impl.cmd.CreateUserQueryCmd;
import org.activiti.engine.impl.cmd.DeleteGroupCmd;
import org.activiti.engine.impl.cmd.DeleteMembershipCmd;
import org.activiti.engine.impl.cmd.DeleteUserCmd;
......@@ -36,11 +40,11 @@ import org.activiti.engine.impl.interceptor.CommandExecutor;
public class IdentityServiceImpl extends ServiceImpl implements IdentityService {
public Group newGroup(String groupId) {
return new GroupEntity(groupId);
return commandExecutor.execute(new CreateGroupCmd(groupId));
}
public User newUser(String userId) {
return new UserEntity(userId);
return commandExecutor.execute(new CreateUserCmd(userId));
}
public void saveGroup(Group group) {
......@@ -52,11 +56,11 @@ public class IdentityServiceImpl extends ServiceImpl implements IdentityService
}
public UserQuery createUserQuery() {
return new UserQueryImpl(commandExecutor);
return commandExecutor.execute(new CreateUserQueryCmd());
}
public GroupQuery createGroupQuery() {
return new GroupQueryImpl(commandExecutor);
return commandExecutor.execute(new CreateGroupQueryCmd());
}
public void createMembership(String userId, String groupId) {
......
......@@ -18,7 +18,7 @@ import java.util.Date;
import java.util.List;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.identity.GroupEntity;
import org.activiti.engine.identity.Group;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.CommandExecutor;
import org.activiti.engine.task.Task;
......@@ -168,12 +168,12 @@ public class TaskQueryImpl extends AbstractQuery<TaskQuery, Task> implements Tas
}
protected List<String> getGroupsForCandidateUser(String candidateUser) {
List<GroupEntity> groups = CommandContext
List<Group> groups = CommandContext
.getCurrent()
.getIdentitySession()
.findGroupsByUser(candidateUser);
List<String> groupIds = new ArrayList<String>();
for (GroupEntity group : groups) {
for (Group group : groups) {
groupIds.add(group.getId());
}
return groupIds;
......
......@@ -16,10 +16,11 @@ package org.activiti.engine.impl.cfg;
import java.util.List;
import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.GroupQuery;
import org.activiti.engine.identity.User;
import org.activiti.engine.identity.UserQuery;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.identity.GroupEntity;
import org.activiti.engine.impl.identity.UserEntity;
import org.activiti.engine.impl.interceptor.CommandExecutor;
/**
......@@ -28,19 +29,25 @@ import org.activiti.engine.impl.identity.UserEntity;
public interface IdentitySession {
/* User */
void insertUser(UserEntity user);
User createNewUser(String userId);
void insertUser(User user);
void updateUser(User updatedUser);
void deleteUser(String userId);
UserEntity findUserById(String userId);
List<UserEntity> findUsersByGroupId(String groupId);
User findUserById(String userId);
List<User> findUsersByGroupId(String groupId);
boolean isValidUser(String userId);
UserQuery createNewUserQuery(CommandExecutor commandExecutor);
List<User> findUserByQueryCriteria(Object query, Page page);
long findUserCountByQueryCriteria(Object query);
/* Group */
void insertGroup(GroupEntity group);
GroupEntity findGroupById(String groupId);
List<GroupEntity> findGroupsByUser(String userId);
Group createNewGroup(String groupId);
void insertGroup(Group group);
void updateGroup(Group updatedGroup);
void deleteGroup(String groupId);
Group findGroupById(String groupId);
List<Group> findGroupsByUser(String userId);
GroupQuery createNewGroupQuery(CommandExecutor commandExecutor);
List<Group> findGroupByQueryCriteria(Object query, Page page);
long findGroupCountByQueryCriteria(Object query);
......
......@@ -12,8 +12,8 @@
*/
package org.activiti.engine.impl.cmd;
import org.activiti.engine.identity.User;
import org.activiti.engine.impl.cfg.IdentitySession;
import org.activiti.engine.impl.identity.UserEntity;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
......@@ -34,7 +34,7 @@ public class CheckPassword implements Command<Boolean> {
public Boolean execute(CommandContext commandContext) {
IdentitySession identitySession = commandContext.getIdentitySession();
UserEntity user = identitySession.findUserById(userId);
User user = identitySession.findUserById(userId);
if ( (user!=null)
&& (password!=null)
&& (password.equals(user.getPassword()))
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.cmd;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.identity.Group;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
/**
* @author Tom Baeyens
*/
public class CreateGroupCmd implements Command<Group> {
protected String groupId;
public CreateGroupCmd(String groupId) {
if(groupId == null) {
throw new ActivitiException("groupId is null");
}
this.groupId = groupId;
}
public Group execute(CommandContext commandContext) {
return commandContext
.getIdentitySession()
.createNewGroup(groupId);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.cmd;
import org.activiti.engine.identity.GroupQuery;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.CommandExecutor;
/**
* @author Tom Baeyens
*/
public class CreateGroupQueryCmd implements Command<GroupQuery> {
public GroupQuery execute(CommandContext commandContext) {
CommandExecutor commandExecutor = commandContext.getProcessEngineConfiguration().getCommandExecutorTxRequired();
return commandContext
.getIdentitySession()
.createNewGroupQuery(commandExecutor);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.cmd;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.identity.User;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
/**
* @author Tom Baeyens
*/
public class CreateUserCmd implements Command<User> {
protected String userId;
public CreateUserCmd(String userId) {
if(userId == null) {
throw new ActivitiException("userId is null");
}
this.userId = userId;
}
public User execute(CommandContext commandContext) {
return commandContext
.getIdentitySession()
.createNewUser(userId);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.cmd;
import org.activiti.engine.identity.UserQuery;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.CommandExecutor;
/**
* @author Tom Baeyens
*/
public class CreateUserQueryCmd implements Command<UserQuery> {
public UserQuery execute(CommandContext commandContext) {
CommandExecutor commandExecutor = commandContext.getProcessEngineConfiguration().getCommandExecutorTxRequired();
return commandContext
.getIdentitySession()
.createNewUserQuery(commandExecutor);
}
}
......@@ -13,6 +13,7 @@
package org.activiti.engine.impl.cmd;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.identity.Group;
import org.activiti.engine.impl.identity.GroupEntity;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
......@@ -38,11 +39,9 @@ public class SaveGroupCmd implements Command<Void> {
.getIdentitySession()
.insertGroup(group);
} else {
GroupEntity persistentGroup = commandContext
commandContext
.getIdentitySession()
.findGroupById(group.getId());
persistentGroup.update(group);
.updateGroup(group);
}
return null;
......
......@@ -39,11 +39,9 @@ public class SaveUserCmd implements Command<Void> {
.getIdentitySession()
.insertUser(user);
} else {
UserEntity persistentUser = commandContext
commandContext
.getIdentitySession()
.findUserById(user.getId());
persistentUser.update(user);
.updateUser(user);
}
return null;
......
......@@ -18,12 +18,17 @@ import java.util.List;
import java.util.Map;
import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.GroupQuery;
import org.activiti.engine.identity.User;
import org.activiti.engine.identity.UserQuery;
import org.activiti.engine.impl.GroupQueryImpl;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.UserQueryImpl;
import org.activiti.engine.impl.cfg.IdentitySession;
import org.activiti.engine.impl.identity.GroupEntity;
import org.activiti.engine.impl.identity.UserEntity;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.CommandExecutor;
import org.activiti.engine.impl.interceptor.Session;
......@@ -38,8 +43,8 @@ public class DbIdentitySession implements IdentitySession, Session {
this.dbSqlSession = CommandContext.getCurrentSession(DbSqlSession.class);
}
public void insertUser(UserEntity user) {
dbSqlSession.insert(user);
public void insertUser(User user) {
dbSqlSession.insert((PersistentObject) user);
}
public UserEntity findUserById(String userId) {
......@@ -47,7 +52,7 @@ public class DbIdentitySession implements IdentitySession, Session {
}
@SuppressWarnings("unchecked")
public List<UserEntity> findUsersByGroupId(String groupId) {
public List<User> findUsersByGroupId(String groupId) {
return dbSqlSession.selectList("selectUsersByGroupId", groupId);
}
......@@ -60,8 +65,8 @@ public class DbIdentitySession implements IdentitySession, Session {
dbSqlSession.delete("deleteUser", userId);
}
public void insertGroup(GroupEntity group) {
dbSqlSession.insert(group);
public void insertGroup(Group group) {
dbSqlSession.insert((PersistentObject) group);
}
public GroupEntity findGroupById(String groupId) {
......@@ -69,7 +74,7 @@ public class DbIdentitySession implements IdentitySession, Session {
}
@SuppressWarnings("unchecked")
public List<GroupEntity> findGroupsByUser(String userId) {
public List<Group> findGroupsByUser(String userId) {
return dbSqlSession.selectList("selectGroupsByUserId", userId);
}
......@@ -110,6 +115,32 @@ public class DbIdentitySession implements IdentitySession, Session {
return (Long) dbSqlSession.selectOne("selectGroupCountByQueryCriteria", query);
}
public Group createNewGroup(String groupId) {
return new GroupEntity(groupId);
}
public GroupQuery createNewGroupQuery(CommandExecutor commandExecutor) {
return new GroupQueryImpl(commandExecutor);
}
public User createNewUser(String userId) {
return new UserEntity(userId);
}
public UserQuery createNewUserQuery(CommandExecutor commandExecutor) {
return new UserQueryImpl(commandExecutor);
}
public void updateGroup(Group updatedGroup) {
GroupEntity persistentGroup = findGroupById(updatedGroup.getId());
persistentGroup.update((GroupEntity) updatedGroup);
}
public void updateUser(User updatedUser) {
UserEntity persistentUser = findUserById(updatedUser.getId());
persistentUser.update((UserEntity) updatedUser);
}
public void close() {
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册