use of org.apache.directory.fortress.core.model.Session in project directory-fortress-core by apache.
the class TestAccelerator method testAddActiveRole.
// @Test
public void testAddActiveRole() {
LOG.info("testAddActiveRole...");
try {
AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
Session session;
User user = new User();
// positive test case:
user.setUserId("rbacuser1");
user.setPassword("secret");
user.setRoleName("rbacrole1");
// user.setRole( "rbacrole2" );
session = accelMgr.createSession(user, false);
assertNotNull(session);
assertTrue(session.isAuthenticated());
UserRole userRole = new UserRole(user.getUserId(), "rbacrole2");
accelMgr.addActiveRole(session, userRole);
} catch (SecurityException se) {
se.printStackTrace();
fail();
}
}
use of org.apache.directory.fortress.core.model.Session in project directory-fortress-core by apache.
the class TestAccelerator method testSessionRoles.
@Test
public void testSessionRoles() {
LOG.info("testSessionRoles...");
User user = new User();
user.setUserId("rbacuser1");
user.setPassword("secret");
try {
AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
Session session;
session = accelMgr.createSession(user, false);
assertNotNull(session);
accelMgr.sessionRoles(session);
} catch (org.apache.directory.fortress.core.SecurityException se) {
se.printStackTrace();
}
}
use of org.apache.directory.fortress.core.model.Session in project directory-fortress-core by apache.
the class TestAccelerator method testDropActiveRole.
@Test
public void testDropActiveRole() {
LOG.info("testDropActiveRole...");
// AcceleratorDAO aDao = new org.apache.directory.fortress.core.impl.AcceleratorDAO();
try {
AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
Session session;
User user = new User();
// positive test case:
user.setUserId("rbacuser1");
user.setPassword("secret");
// user.setRole( "rbacrole1" );
// user.setRole( "rbacrole2" );
session = accelMgr.createSession(user, false);
assertNotNull(session);
assertTrue(session.isAuthenticated());
UserRole userRole = new UserRole(user.getUserId(), "rbacrole2");
accelMgr.dropActiveRole(session, userRole);
} catch (SecurityException se) {
se.printStackTrace();
fail();
}
}
use of org.apache.directory.fortress.core.model.Session in project directory-fortress-core by apache.
the class AccelCreateSession method runTest.
/**
* Description of the Method
*
* @param samplerContext Description of the Parameter
* @return Description of the Return Value
*/
public SampleResult runTest(JavaSamplerContext samplerContext) {
SampleResult sampleResult = new SampleResult();
try {
sampleResult.sampleStart();
// String message = "FT CreateSession TID: " + getThreadId() + " UID:" + userId + " CTR:" + ctr++;
// LOG.info( message );
// System.out.println( message );
assertNotNull(accelMgr);
Session session;
User user = new User();
// positive test case:
user.setUserId(userId);
user.setPassword("secret");
session = accelMgr.createSession(user, false);
assertNotNull(session);
assertTrue(session.isAuthenticated());
sampleResult.sampleEnd();
sampleResult.setBytes(1);
sampleResult.setResponseMessage("AC test completed TID: " + getThreadId() + " UID: " + userId);
sampleResult.setSuccessful(true);
} catch (org.apache.directory.fortress.core.SecurityException se) {
System.out.println("ThreadId:" + getThreadId() + "Error running test: " + se);
se.printStackTrace();
sampleResult.setSuccessful(false);
}
return sampleResult;
}
use of org.apache.directory.fortress.core.model.Session in project cas by apereo.
the class FortressAuthenticationHandlerTests method verifyAuthenticateSuccessfully.
@Test
public void verifyAuthenticateSuccessfully() throws Exception {
val sessionId = UUID.randomUUID();
val session = new Session(new User(CoreAuthenticationTestUtils.CONST_USERNAME), sessionId.toString());
session.setAuthenticated(true);
when(accessManager.createSession(ArgumentMatchers.any(User.class), ArgumentMatchers.anyBoolean())).thenReturn(session);
val handlerResult = fortressAuthenticationHandler.authenticateUsernamePasswordInternal(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), null);
assertEquals(CoreAuthenticationTestUtils.CONST_USERNAME, handlerResult.getPrincipal().getId());
val jaxbContext = JAXBContext.newInstance(Session.class);
val marshaller = jaxbContext.createMarshaller();
val writer = new StringWriter();
marshaller.marshal(session, writer);
assertEquals(writer.toString(), handlerResult.getPrincipal().getAttributes().get(FortressAuthenticationHandler.FORTRESS_SESSION_KEY).get(0));
}
Aggregations