当前位置: 首页>>代码示例>>Java>>正文


Java MessagePolicy类代码示例

本文整理汇总了Java中javax.security.auth.message.MessagePolicy的典型用法代码示例。如果您正苦于以下问题:Java MessagePolicy类的具体用法?Java MessagePolicy怎么用?Java MessagePolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MessagePolicy类属于javax.security.auth.message包,在下文中一共展示了MessagePolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testFailLoginInvalidMethod

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * Tests the login endpoint PUT operation.
 */
@Test(expected = AuthException.class)
public void testFailLoginInvalidMethod() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("PUT");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(servletRequest.getParameter("state")).thenReturn("/rooted/page");
    when(servletRequest.getParameter("nonce")).thenReturn("abc");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    module.validateRequest(messageInfo, client, null);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:28,代码来源:TestServerAuthModuleTest.java

示例2: testFailLoginInvalidState

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * Tests the login endpoint GET operation.
 */
@Test(expected = AuthException.class)
public void testFailLoginInvalidState() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(servletRequest.getParameter("state")).thenReturn("http://www.trajano.net/");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    module.validateRequest(messageInfo, client, null);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:27,代码来源:TestServerAuthModuleTest.java

示例3: testFailLoginInvalidState2

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * Tests the login endpoint GET operation.
 */
@Test(expected = AuthException.class)
public void testFailLoginInvalidState2() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(servletRequest.getParameter("state")).thenReturn("some/non/rooted/page");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    module.validateRequest(messageInfo, client, null);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:27,代码来源:TestServerAuthModuleTest.java

示例4: testFailLoginInvalidState3

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * Tests the login endpoint GET operation.
 */
@Test(expected = AuthException.class)
public void testFailLoginInvalidState3() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(servletRequest.getParameter("state")).thenReturn("/foo/../../abc");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    module.validateRequest(messageInfo, client, null);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:27,代码来源:TestServerAuthModuleTest.java

示例5: testFailLoginInvalidState4

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * Tests the login endpoint GET operation.
 */
@Test(expected = AuthException.class)
public void testFailLoginInvalidState4() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(servletRequest.getParameter("state")).thenReturn("//url.com/foo/../../abc");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    module.validateRequest(messageInfo, client, null);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:27,代码来源:TestServerAuthModuleTest.java

示例6: testFailLoginMissingNonce

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * Tests the login endpoint GET operation.
 */
@Test(expected = AuthException.class)
public void testFailLoginMissingNonce() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(servletRequest.getParameter("state")).thenReturn("/www.trajano.net/");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    module.validateRequest(messageInfo, client, null);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:27,代码来源:TestServerAuthModuleTest.java

示例7: testFailLoginMissingState

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * Tests the login endpoint GET operation.
 */
@Test(expected = AuthException.class)
public void testFailLoginMissingState() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    module.validateRequest(messageInfo, client, null);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:26,代码来源:TestServerAuthModuleTest.java

示例8: testFailLoginNotSecure

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * Tests the login endpoint GET operation.
 */
@Test(expected = AuthException.class)
public void testFailLoginNotSecure() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(false);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    module.validateRequest(messageInfo, client, null);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:26,代码来源:TestServerAuthModuleTest.java

示例9: testNoAuthNeededWithoutSSL

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * The policy has determined it is not mandatory without SSL.
 */
@Test
public void testNoAuthNeededWithoutSSL() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final CallbackHandler h = mock(CallbackHandler.class);

    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(false);

    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(false);
    when(servletRequest.getRequestURI()).thenReturn("/util/ejb2");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    assertEquals(AuthStatus.SUCCESS, module.validateRequest(messageInfo, client, null));
    verifyZeroInteractions(h);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:28,代码来源:TestServerAuthModuleTest.java

示例10: testNoAuthNeededWithSSL

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * The policy has determined it is not mandatory.
 */
@Test
public void testNoAuthNeededWithSSL() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(false);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/ejb2");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    assertEquals(AuthStatus.SUCCESS, module.validateRequest(messageInfo, client, null));
    verifyZeroInteractions(h);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:27,代码来源:TestServerAuthModuleTest.java

示例11: testSSLRequired

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
@Test
public void testSSLRequired() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    module.initialize(mockRequestPolicy, null, null, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(false);
    when(servletRequest.getRequestURI()).thenReturn("/util/ejb2");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final HttpServletResponse servletResponse = mock(HttpServletResponse.class);
    when(messageInfo.getResponseMessage()).thenReturn(servletResponse);

    final Subject client = new Subject();
    assertEquals(AuthStatus.SEND_FAILURE, module.validateRequest(messageInfo, client, null));
    verify(servletResponse).sendError(HttpURLConnection.HTTP_FORBIDDEN, "SSL Required");
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:26,代码来源:TestServerAuthModuleTest.java

示例12: testFailLoginInvalidMethod

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * Tests the login endpoint PUT operation.
 */
@Test(expected = AuthException.class)
public void testFailLoginInvalidMethod() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("PUT");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(servletRequest.getParameter("state")).thenReturn("/rooted/page");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    module.validateRequest(messageInfo, client, null);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:27,代码来源:TestServerAuthModuleTest.java

示例13: testFailLoginInvalidState4

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * Tests the login endpoint GET operation.
 */
@Test(expected = AuthException.class)
public void testFailLoginInvalidState4() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(servletRequest.getParameter("state")).thenReturn("//url.com/foo/../../../abc");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    module.validateRequest(messageInfo, client, null);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:27,代码来源:TestServerAuthModuleTest.java

示例14: testLogin

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
/**
 * Tests the login endpoint GET operation.
 */
@Test
public void testLogin() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(servletRequest.getParameter("state")).thenReturn("/");
    when(servletRequest.getRequestDispatcher(Matchers.anyString())).thenReturn(mock(RequestDispatcher.class));
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    assertEquals(AuthStatus.SEND_SUCCESS, module.validateRequest(messageInfo, client, null));
    verifyZeroInteractions(h);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:29,代码来源:TestServerAuthModuleTest.java

示例15: initialize

import javax.security.auth.message.MessagePolicy; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void initialize(MessagePolicy messagePolicyReq, MessagePolicy messagePolicyResp, 
      CallbackHandler cbh, Map options) throws AuthException
{
   this.options = options;
   try
   {
      this.validateJAASConfiguration();
      loginContext = new LoginContext(loginContextName, cbh);
   }
   catch (LoginException e)
   {
      throw new RuntimeException(e.getLocalizedMessage());
   }

}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:17,代码来源:TestServerAuthModule.java


注:本文中的javax.security.auth.message.MessagePolicy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。