|
|
|
|
@@ -50,236 +50,236 @@ import org.springframework.mock.web.portlet.MockRenderResponse;
|
|
|
|
|
*/
|
|
|
|
|
public class PortletProcessingInterceptorTests extends TestCase {
|
|
|
|
|
|
|
|
|
|
//~ Constructors ===================================================================================================
|
|
|
|
|
//~ Constructors ===================================================================================================
|
|
|
|
|
|
|
|
|
|
public PortletProcessingInterceptorTests() {
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
public PortletProcessingInterceptorTests() {
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PortletProcessingInterceptorTests(String arg0) {
|
|
|
|
|
super(arg0);
|
|
|
|
|
}
|
|
|
|
|
public PortletProcessingInterceptorTests(String arg0) {
|
|
|
|
|
super(arg0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//~ Methods ========================================================================================================
|
|
|
|
|
//~ Methods ========================================================================================================
|
|
|
|
|
|
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
|
super.setUp();
|
|
|
|
|
SecurityContextHolder.clearContext();
|
|
|
|
|
}
|
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
|
super.setUp();
|
|
|
|
|
SecurityContextHolder.clearContext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
|
super.tearDown();
|
|
|
|
|
SecurityContextHolder.clearContext();
|
|
|
|
|
}
|
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
|
super.tearDown();
|
|
|
|
|
SecurityContextHolder.clearContext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testRequiresAuthenticationManager() throws Exception {
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
fail("Expected IllegalArgumentException");
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void testRequiresAuthenticationManager() throws Exception {
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
|
|
|
|
|
public void testNormalRenderRequestProcessing() throws Exception {
|
|
|
|
|
try {
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
fail("Expected IllegalArgumentException");
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockRenderRequest request = PortletTestUtils.createRenderRequest();
|
|
|
|
|
MockRenderResponse response = PortletTestUtils.createRenderResponse();
|
|
|
|
|
public void testNormalRenderRequestProcessing() throws Exception {
|
|
|
|
|
|
|
|
|
|
// Prepare interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockRenderRequest request = PortletTestUtils.createRenderRequest();
|
|
|
|
|
MockRenderResponse response = PortletTestUtils.createRenderResponse();
|
|
|
|
|
|
|
|
|
|
// Execute preHandlerRender phase and verify results
|
|
|
|
|
interceptor.preHandleRender(request, response, null);
|
|
|
|
|
assertEquals(PortletTestUtils.createAuthenticatedToken(),
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
// Prepare interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
|
|
|
|
|
// Execute postHandlerRender phase and verify nothing changed
|
|
|
|
|
interceptor.postHandleRender(request, response, null, null);
|
|
|
|
|
assertEquals(PortletTestUtils.createAuthenticatedToken(),
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
// Execute preHandlerRender phase and verify results
|
|
|
|
|
interceptor.preHandleRender(request, response, null);
|
|
|
|
|
assertEquals(PortletTestUtils.createAuthenticatedToken(),
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
|
|
|
|
|
// Execute afterRenderCompletion phase and verify nothing changed
|
|
|
|
|
interceptor.afterRenderCompletion(request, response, null, null);
|
|
|
|
|
assertEquals(PortletTestUtils.createAuthenticatedToken(),
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
}
|
|
|
|
|
// Execute postHandlerRender phase and verify nothing changed
|
|
|
|
|
interceptor.postHandleRender(request, response, null, null);
|
|
|
|
|
assertEquals(PortletTestUtils.createAuthenticatedToken(),
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
|
|
|
|
|
public void testNormalActionRequestProcessing() throws Exception {
|
|
|
|
|
// Execute afterRenderCompletion phase and verify nothing changed
|
|
|
|
|
interceptor.afterRenderCompletion(request, response, null, null);
|
|
|
|
|
assertEquals(PortletTestUtils.createAuthenticatedToken(),
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockActionRequest request = PortletTestUtils.createActionRequest();
|
|
|
|
|
MockActionResponse response = PortletTestUtils.createActionResponse();
|
|
|
|
|
public void testNormalActionRequestProcessing() throws Exception {
|
|
|
|
|
|
|
|
|
|
// Prepare interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockActionRequest request = PortletTestUtils.createActionRequest();
|
|
|
|
|
MockActionResponse response = PortletTestUtils.createActionResponse();
|
|
|
|
|
|
|
|
|
|
// Execute preHandlerAction phase and verify results
|
|
|
|
|
interceptor.preHandleAction(request, response, null);
|
|
|
|
|
assertEquals(PortletTestUtils.createAuthenticatedToken(),
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
// Prepare interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
|
|
|
|
|
// Execute afterActionCompletion phase and verify nothing changed
|
|
|
|
|
interceptor.afterActionCompletion(request, response, null, null);
|
|
|
|
|
assertEquals(PortletTestUtils.createAuthenticatedToken(),
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
}
|
|
|
|
|
// Execute preHandlerAction phase and verify results
|
|
|
|
|
interceptor.preHandleAction(request, response, null);
|
|
|
|
|
assertEquals(PortletTestUtils.createAuthenticatedToken(),
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
|
|
|
|
|
public void testAuthenticationFailsWithNoCredentials()
|
|
|
|
|
throws Exception {
|
|
|
|
|
// Execute afterActionCompletion phase and verify nothing changed
|
|
|
|
|
interceptor.afterActionCompletion(request, response, null, null);
|
|
|
|
|
assertEquals(PortletTestUtils.createAuthenticatedToken(),
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockActionRequest request = new MockActionRequest();
|
|
|
|
|
MockActionResponse response = new MockActionResponse();
|
|
|
|
|
public void testAuthenticationFailsWithNoCredentials()
|
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
|
|
// Prepare and execute interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
interceptor.preHandleAction(request, response, null);
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockActionRequest request = new MockActionRequest();
|
|
|
|
|
MockActionResponse response = new MockActionResponse();
|
|
|
|
|
|
|
|
|
|
// Verify that authentication is empty
|
|
|
|
|
assertNull(SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
// Prepare and execute interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
interceptor.preHandleAction(request, response, null);
|
|
|
|
|
|
|
|
|
|
// Verify that proper exception was thrown
|
|
|
|
|
assertTrue(request.getPortletSession().getAttribute(
|
|
|
|
|
AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY,
|
|
|
|
|
PortletSession.APPLICATION_SCOPE)
|
|
|
|
|
instanceof BadCredentialsException);
|
|
|
|
|
}
|
|
|
|
|
// Verify that authentication is empty
|
|
|
|
|
assertNull(SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
|
|
|
|
|
public void testExistingAuthenticationIsLeftAlone() throws Exception {
|
|
|
|
|
// Verify that proper exception was thrown
|
|
|
|
|
assertTrue(request.getPortletSession().getAttribute(
|
|
|
|
|
AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY,
|
|
|
|
|
PortletSession.APPLICATION_SCOPE)
|
|
|
|
|
instanceof BadCredentialsException);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockActionRequest request = PortletTestUtils.createActionRequest();
|
|
|
|
|
MockActionResponse response = PortletTestUtils.createActionResponse();
|
|
|
|
|
public void testExistingAuthenticationIsLeftAlone() throws Exception {
|
|
|
|
|
|
|
|
|
|
// Prepare interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockActionRequest request = PortletTestUtils.createActionRequest();
|
|
|
|
|
MockActionResponse response = PortletTestUtils.createActionResponse();
|
|
|
|
|
|
|
|
|
|
UsernamePasswordAuthenticationToken testingToken = new UsernamePasswordAuthenticationToken("dummy", "dummy");
|
|
|
|
|
UsernamePasswordAuthenticationToken baselineToken = new UsernamePasswordAuthenticationToken("dummy", "dummy");
|
|
|
|
|
SecurityContextHolder.getContext().setAuthentication(testingToken);
|
|
|
|
|
// Prepare interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
|
|
|
|
|
// Execute preHandlerAction phase and verify results
|
|
|
|
|
interceptor.preHandleAction(request, response, null);
|
|
|
|
|
assertTrue(SecurityContextHolder.getContext().getAuthentication() == testingToken);
|
|
|
|
|
assertEquals(baselineToken, SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
UsernamePasswordAuthenticationToken testingToken = new UsernamePasswordAuthenticationToken("dummy", "dummy");
|
|
|
|
|
UsernamePasswordAuthenticationToken baselineToken = new UsernamePasswordAuthenticationToken("dummy", "dummy");
|
|
|
|
|
SecurityContextHolder.getContext().setAuthentication(testingToken);
|
|
|
|
|
|
|
|
|
|
// Execute afterActionCompletion phase and verify nothing changed
|
|
|
|
|
interceptor.afterActionCompletion(request, response, null, null);
|
|
|
|
|
assertTrue(SecurityContextHolder.getContext().getAuthentication() == testingToken);
|
|
|
|
|
assertEquals(baselineToken, SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
}
|
|
|
|
|
// Execute preHandlerAction phase and verify results
|
|
|
|
|
interceptor.preHandleAction(request, response, null);
|
|
|
|
|
assertTrue(SecurityContextHolder.getContext().getAuthentication() == testingToken);
|
|
|
|
|
assertEquals(baselineToken, SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
|
|
|
|
|
public void testUsernameFromRemoteUser() throws Exception {
|
|
|
|
|
// Execute afterActionCompletion phase and verify nothing changed
|
|
|
|
|
interceptor.afterActionCompletion(request, response, null, null);
|
|
|
|
|
assertTrue(SecurityContextHolder.getContext().getAuthentication() == testingToken);
|
|
|
|
|
assertEquals(baselineToken, SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockActionRequest request = new MockActionRequest();
|
|
|
|
|
MockActionResponse response = new MockActionResponse();
|
|
|
|
|
request.setRemoteUser(PortletTestUtils.TESTUSER);
|
|
|
|
|
request.setAuthType(PortletRequest.FORM_AUTH);
|
|
|
|
|
public void testUsernameFromRemoteUser() throws Exception {
|
|
|
|
|
|
|
|
|
|
// Prepare and execute interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
interceptor.preHandleAction(request, response, null);
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockActionRequest request = new MockActionRequest();
|
|
|
|
|
MockActionResponse response = new MockActionResponse();
|
|
|
|
|
request.setRemoteUser(PortletTestUtils.TESTUSER);
|
|
|
|
|
request.setAuthType(PortletRequest.FORM_AUTH);
|
|
|
|
|
|
|
|
|
|
// Verify username
|
|
|
|
|
assertEquals(PortletTestUtils.TESTUSER,
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication().getName());
|
|
|
|
|
}
|
|
|
|
|
// Prepare and execute interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
interceptor.preHandleAction(request, response, null);
|
|
|
|
|
|
|
|
|
|
public void testUsernameFromPrincipal() throws Exception {
|
|
|
|
|
// Verify username
|
|
|
|
|
assertEquals(PortletTestUtils.TESTUSER,
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication().getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockActionRequest request = new MockActionRequest();
|
|
|
|
|
MockActionResponse response = new MockActionResponse();
|
|
|
|
|
request.setUserPrincipal(new TestingAuthenticationToken(PortletTestUtils.TESTUSER, PortletTestUtils.TESTCRED));
|
|
|
|
|
request.setAuthType(PortletRequest.FORM_AUTH);
|
|
|
|
|
public void testUsernameFromPrincipal() throws Exception {
|
|
|
|
|
|
|
|
|
|
// Prepare and execute interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
interceptor.preHandleAction(request, response, null);
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockActionRequest request = new MockActionRequest();
|
|
|
|
|
MockActionResponse response = new MockActionResponse();
|
|
|
|
|
request.setUserPrincipal(new TestingAuthenticationToken(PortletTestUtils.TESTUSER, PortletTestUtils.TESTCRED));
|
|
|
|
|
request.setAuthType(PortletRequest.FORM_AUTH);
|
|
|
|
|
|
|
|
|
|
// Verify username
|
|
|
|
|
assertEquals(PortletTestUtils.TESTUSER,
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication().getName());
|
|
|
|
|
}
|
|
|
|
|
// Prepare and execute interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
interceptor.preHandleAction(request, response, null);
|
|
|
|
|
|
|
|
|
|
public void testUsernameFromUserInfo() throws Exception {
|
|
|
|
|
// Verify username
|
|
|
|
|
assertEquals(PortletTestUtils.TESTUSER,
|
|
|
|
|
SecurityContextHolder.getContext().getAuthentication().getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockActionRequest request = new MockActionRequest();
|
|
|
|
|
MockActionResponse response = new MockActionResponse();
|
|
|
|
|
HashMap userInfo = new HashMap();
|
|
|
|
|
userInfo.put("user.name.given", "Test");
|
|
|
|
|
userInfo.put("user.name.family", "User");
|
|
|
|
|
userInfo.put("user.id", "mytestuser");
|
|
|
|
|
request.setAttribute(PortletRequest.USER_INFO, userInfo);
|
|
|
|
|
request.setAuthType(PortletRequest.FORM_AUTH);
|
|
|
|
|
public void testUsernameFromUserInfo() throws Exception {
|
|
|
|
|
|
|
|
|
|
// Prepare and execute interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
ArrayList userNameAttributes = new ArrayList();
|
|
|
|
|
userNameAttributes.add("user.name");
|
|
|
|
|
userNameAttributes.add("user.id");
|
|
|
|
|
interceptor.setUserNameAttributes(userNameAttributes);
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
interceptor.preHandleAction(request, response, null);
|
|
|
|
|
// Build mock request and response
|
|
|
|
|
MockActionRequest request = new MockActionRequest();
|
|
|
|
|
MockActionResponse response = new MockActionResponse();
|
|
|
|
|
HashMap userInfo = new HashMap();
|
|
|
|
|
userInfo.put("user.name.given", "Test");
|
|
|
|
|
userInfo.put("user.name.family", "User");
|
|
|
|
|
userInfo.put("user.id", "mytestuser");
|
|
|
|
|
request.setAttribute(PortletRequest.USER_INFO, userInfo);
|
|
|
|
|
request.setAuthType(PortletRequest.FORM_AUTH);
|
|
|
|
|
|
|
|
|
|
// Verify username
|
|
|
|
|
assertEquals("mytestuser", SecurityContextHolder.getContext().getAuthentication().getName());
|
|
|
|
|
}
|
|
|
|
|
// Prepare and execute interceptor
|
|
|
|
|
PortletProcessingInterceptor interceptor = new PortletProcessingInterceptor();
|
|
|
|
|
interceptor.setAuthenticationManager(new MockPortletAuthenticationManager());
|
|
|
|
|
ArrayList userNameAttributes = new ArrayList();
|
|
|
|
|
userNameAttributes.add("user.name");
|
|
|
|
|
userNameAttributes.add("user.id");
|
|
|
|
|
interceptor.setUserNameAttributes(userNameAttributes);
|
|
|
|
|
interceptor.afterPropertiesSet();
|
|
|
|
|
interceptor.preHandleAction(request, response, null);
|
|
|
|
|
|
|
|
|
|
//~ Inner Classes ==================================================================================================
|
|
|
|
|
// Verify username
|
|
|
|
|
assertEquals("mytestuser", SecurityContextHolder.getContext().getAuthentication().getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class MockPortletAuthenticationManager implements AuthenticationManager {
|
|
|
|
|
//~ Inner Classes ==================================================================================================
|
|
|
|
|
|
|
|
|
|
public Authentication authenticate(Authentication token) {
|
|
|
|
|
private static class MockPortletAuthenticationManager implements AuthenticationManager {
|
|
|
|
|
|
|
|
|
|
// Make sure we got a valid token
|
|
|
|
|
if (!(token instanceof PreAuthenticatedAuthenticationToken)) {
|
|
|
|
|
TestCase.fail("Expected PreAuthenticatedAuthenticationToken object-- got: " + token);
|
|
|
|
|
}
|
|
|
|
|
public Authentication authenticate(Authentication token) {
|
|
|
|
|
|
|
|
|
|
// Make sure the token details are the PortletRequest
|
|
|
|
|
// Make sure we got a valid token
|
|
|
|
|
if (!(token instanceof PreAuthenticatedAuthenticationToken)) {
|
|
|
|
|
TestCase.fail("Expected PreAuthenticatedAuthenticationToken object-- got: " + token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the token details are the PortletRequest
|
|
|
|
|
// if (!(token.getDetails() instanceof PortletRequest)) {
|
|
|
|
|
// TestCase.fail("Expected Authentication.getDetails to be a PortletRequest object -- got: " + token.getDetails());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// Make sure it's got a principal
|
|
|
|
|
if (token.getPrincipal() == null) {
|
|
|
|
|
throw new BadCredentialsException("Mock authentication manager rejecting null principal");
|
|
|
|
|
}
|
|
|
|
|
// Make sure it's got a principal
|
|
|
|
|
if (token.getPrincipal() == null) {
|
|
|
|
|
throw new BadCredentialsException("Mock authentication manager rejecting null principal");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure it's got credentials
|
|
|
|
|
if (token.getCredentials() == null) {
|
|
|
|
|
throw new BadCredentialsException("Mock authentication manager rejecting null credentials");
|
|
|
|
|
}
|
|
|
|
|
// Make sure it's got credentials
|
|
|
|
|
if (token.getCredentials() == null) {
|
|
|
|
|
throw new BadCredentialsException("Mock authentication manager rejecting null credentials");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create resulting Authentication object
|
|
|
|
|
User user = new User(token.getName(), token.getCredentials().toString(), true, true, true, true,
|
|
|
|
|
new GrantedAuthority[] {new GrantedAuthorityImpl(PortletTestUtils.TESTROLE1), new GrantedAuthorityImpl(PortletTestUtils.TESTROLE2)});
|
|
|
|
|
PreAuthenticatedAuthenticationToken result = new PreAuthenticatedAuthenticationToken(
|
|
|
|
|
user, user.getPassword(), user.getAuthorities());
|
|
|
|
|
result.setAuthenticated(true);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
// create resulting Authentication object
|
|
|
|
|
User user = new User(token.getName(), token.getCredentials().toString(), true, true, true, true,
|
|
|
|
|
new GrantedAuthority[] {new GrantedAuthorityImpl(PortletTestUtils.TESTROLE1), new GrantedAuthorityImpl(PortletTestUtils.TESTROLE2)});
|
|
|
|
|
PreAuthenticatedAuthenticationToken result = new PreAuthenticatedAuthenticationToken(
|
|
|
|
|
user, user.getPassword(), user.getAuthorities().toArray(new GrantedAuthority[0]));
|
|
|
|
|
result.setAuthenticated(true);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|