本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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");
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
}