03-06-2011 11:58 PM
package org.grails.activiti.springsecurity;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.engine.ProcessEngine;
import java.util.ArrayList;
class SpringSecurityProcessEngineConfiguration extends SpringProcessEngineConfiguration {
public ProcessEngine buildProcessEngine() {
ArrayList customSessionFactories = new ArrayList(1);
customSessionFactories.add(new SpringSecurityIdentitySessionFactory());
setCustomSessionFactories(customSessionFactories);
return super.buildProcessEngine();
}
}
package org.grails.activiti.springsecurity;
import org.activiti.engine.impl.interceptor.Session;
import org.activiti.engine.impl.interceptor.SessionFactory;
class SpringSecurityIdentitySessionFactory implements SessionFactory {
public Class<?> getSessionType() {
return SpringSecurityIdentitySession.class;
}
public Session openSession() {
return new SpringSecurityIdentitySession();
}
}
03-07-2011 04:31 AM
03-07-2011 05:45 AM
What base-test class are you using? You should check how the engine is obtained in the test-class.Thanks for fast response. Is there anything wrong with my codes in previous post?
package org.grails.activiti.springsecurity
import grails.test.*
class SpringSecurityIdentitySessionTests extends GrailsUnitTestCase {
def identityService
def springSecurityService
protected void setUp() {
super.setUp()
}
protected void tearDown() {
super.tearDown()
}
void testSelectAllUsers() {
def org1 = new Organization(name: 'ProcessCanvas.com').save(failOnError: true)
def users = [
new User(organization: org1,
email: 'admin@activiti.org',
firstName: 'Admin',
lastName: 'User',
password: springSecurityService.encodePassword('admin'),
enabled: true).save(failOnError: true),
new User(organization: org1,
email: 'admin2@activiti.org',
firstName: 'Admin2',
lastName: 'User2',
password: springSecurityService.encodePassword('admin2'),
enabled: true).save(failOnError: true)
]
assertEquals users, identityService.createUserQuery().orderByUserLastName().asc().orderByUserFirstName().asc().list()
}
void testSelectAllUsersCount() {
def org1 = new Organization(name: 'ProcessCanvas.com').save(failOnError: true)
def users = [
new User(organization: org1,
email: 'admin@activiti.org',
firstName: 'Admin',
lastName: 'User',
password: springSecurityService.encodePassword('admin'),
enabled: true).save(failOnError: true),
new User(organization: org1,
email: 'admin2@activiti.org',
firstName: 'Admin2',
lastName: 'User2',
password: springSecurityService.encodePassword('admin2'),
enabled: true).save(failOnError: true)
]
assertEquals "users.size()", users.size(), identityService.createUserQuery().count()
}
void testFindGroupsByUser() {
def org1 = new Organization(name: 'ProcessCanvas.com').save(failOnError: true)
def user = new User(organization: org1,
email: 'admin@activiti.org',
firstName: 'Admin',
lastName: 'User',
password: springSecurityService.encodePassword('admin'),
enabled: true).save(failOnError: true)
def group1 = new UserGroup(name: "User Group 1", organization: org1).save(failOnError: true)
def group2 = new UserGroup(name: "User Group 2", organization: org1).save(failOnError: true)
UserUserGroup.create(user, group1)
UserUserGroup.create(user, group2)
assertEquals ([group1, group2], identityService.createGroupQuery().groupMember(user.id).orderByGroupId().asc().list())
}
void testFindGroupsByUserCount() {
def org1 = new Organization(name: 'ProcessCanvas.com').save(failOnError: true)
def user = new User(organization: org1,
email: 'admin@activiti.org',
firstName: 'Admin',
lastName: 'User',
password: springSecurityService.encodePassword('admin'),
enabled: true).save(failOnError: true)
def group1 = new UserGroup(name: "User Group 1", organization: org1).save(failOnError: true)
def group2 = new UserGroup(name: "User Group 2", organization: org1).save(failOnError: true)
UserUserGroup.create(user, group1)
UserUserGroup.create(user, group2)
assertEquals 2, identityService.createGroupQuery().groupMember(user.id).count()
}
void testFindUsersByGroup() {
def org1 = new Organization(name: 'ProcessCanvas.com').save(failOnError: true)
def users = [
new User(organization: org1,
email: 'admin@activiti.org',
firstName: 'Admin',
lastName: 'User',
password: springSecurityService.encodePassword('admin'),
enabled: true).save(failOnError: true),
new User(organization: org1,
email: 'admin2@activiti.org',
firstName: 'Admin2',
lastName: 'User2',
password: springSecurityService.encodePassword('admin2'),
enabled: true).save(failOnError: true),
new User(organization: org1,
email: 'admin3@activiti.org',
firstName: 'Admin3',
lastName: 'User3',
password: springSecurityService.encodePassword('admin3'),
enabled: true).save(failOnError: true)
]
def group1 = new UserGroup(name: "User Group 1", organization: org1).save(failOnError: true)
UserUserGroup.create(users[0], group1)
UserUserGroup.create(users[2], group1)
assertEquals ([users[0], users[2]], identityService.createUserQuery().memberOfGroup(group1.id).orderByUserId().asc().list())
}
}
03-07-2011 05:58 AM
03-07-2011 06:14 AM
The code for setting the custom session-factory should be okay (you set the customSessionFactories before init() is called, so the will be picked up). Although, can also be done using spring-wiring without actually having to override the SpringProcessEngineConfiguration.Can you show sample configuration of spring wiring?
How does the test get it's engine? Does it use the same spring-context as your normal app and uses the auto-injection stuff in grails (def identityService)?
03-08-2011 10:59 AM
The code for setting the custom session-factory should be okay (you set the customSessionFactories before init() is called, so the will be picked up). Although, can also be done using spring-wiring without actually having to override the SpringProcessEngineConfiguration.I am using the approach suggested by you. The SpringSecurityProcessEngineConfiguration class is not necessary.
03-09-2011 04:44 AM
03-09-2011 04:48 AM
Can you check if you see any difference in configuration from this and your solution:
/activiti-engine/src/test/java/org/activiti/standalone/cfg/identity/CustomIdenstitySessionTest.java
/activiti-engine/src/test/resources/org/activiti/standalone/cfg/identity/customIdentitySession-activiti.cfg.xml
This shows the plugging of the identity-session how we 'envisioned' it
03-09-2011 05:25 AM
Can you check if you see any difference in configuration from this and your solution:When looking into your implementation of CustomIdentitySessionFactory class, I found the mistake in my code below (You can compare it with the first post):
/activiti-engine/src/test/java/org/activiti/standalone/cfg/identity/CustomIdenstitySessionTest.java
/activiti-engine/src/test/resources/org/activiti/standalone/cfg/identity/customIdentitySession-activiti.cfg.xml
This shows the plugging of the identity-session how we 'envisioned' it
package org.grails.activiti.springsecurity;
import org.activiti.engine.impl.interceptor.Session;
import org.activiti.engine.impl.interceptor.SessionFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.activiti.engine.impl.cfg.IdentitySession;
class SpringSecurityIdentitySessionFactory implements SessionFactory {
static final Log LOG = LogFactory.getLog(SpringSecurityIdentitySessionFactory.class);
public Class<?> getSessionType() {
return IdentitySession.class;
}
public Session openSession() {
return new SpringSecurityIdentitySession();
}
}
getSessionType() should return IdentitySession.class instead of SpringSecurityIdentitySession.class.03-09-2011 05:26 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.