本文整理汇总了Java中javax.security.auth.message.config.ServerAuthContext类的典型用法代码示例。如果您正苦于以下问题:Java ServerAuthContext类的具体用法?Java ServerAuthContext怎么用?Java ServerAuthContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerAuthContext类属于javax.security.auth.message.config包,在下文中一共展示了ServerAuthContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAuthContext
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
/**
* {@inheritDoc}
* <p>
* Augments the options with the properties specified and initializes the
* module as mandatory or non-mandatory depending on whether the
* authContextID is <code>null</code>.
* </p>
*/
@Override
public ServerAuthContext getAuthContext(final String authContextID,
final Subject serviceSubject,
@SuppressWarnings("rawtypes") final Map properties) throws AuthException {
@SuppressWarnings("rawtypes")
final Map augmentedOptions = augmentProperties(properties);
final TestServerAuthModule context = new TestServerAuthModule();
if (authContextID == null) {
context.initialize(NON_MANDATORY, NON_MANDATORY, handler, augmentedOptions);
} else {
context.initialize(MANDATORY, MANDATORY, handler, augmentedOptions);
}
return context;
}
示例2: testContext2
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
@Test
public void testContext2() throws Exception {
final CallbackHandler h = mock(CallbackHandler.class);
final Map<String, String> options = new HashMap<>();
final AuthModuleConfigProvider provider = new AuthModuleConfigProvider(options, null);
assertNull(provider.getClientAuthConfig("HttpServlet", "server1 /", h));
final ServerAuthConfig serverAuthConfig = provider.getServerAuthConfig("HttpServlet", "server1 /", h);
assertNotNull(serverAuthConfig);
assertEquals("server1 /", serverAuthConfig.getAppContext());
assertEquals("HttpServlet", serverAuthConfig.getMessageLayer());
final Subject serviceSubject = new Subject();
assertNull(serverAuthConfig.getAuthContextID(mock(MessageInfo.class)));
final ServerAuthContext authContext = serverAuthConfig.getAuthContext(null, serviceSubject, null);
assertNotNull(authContext);
}
示例3: testSuccessfulJASPI
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
public void testSuccessfulJASPI() throws Exception
{
AuthConfigProvider provider = factory.getConfigProvider(layer, appId, null);
ServerAuthConfig serverConfig = provider.getServerAuthConfig(layer, appId, new AppCallbackHandler("jduke",
"theduke".toCharArray()));
assertNotNull("ServerAuthConfig is not null", serverConfig);
MessageInfo mi = new GenericMessageInfo(new Object(), new Object());
String authContextID = serverConfig.getAuthContextID(mi);
assertNotNull("AuthContext ID != null", authContextID);
ServerAuthContext sctx = serverConfig.getAuthContext(authContextID, new Subject(), new HashMap());
assertNotNull("ServerAuthContext != null", sctx);
Subject clientSubject = new Subject();
Subject serviceSubject = new Subject();
AuthStatus status = sctx.validateRequest(mi, clientSubject, serviceSubject);
assertEquals(AuthStatus.SUCCESS, status);
}
示例4: testUnSuccessfulJASPI
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
public void testUnSuccessfulJASPI() throws Exception
{
AuthConfigProvider provider = factory.getConfigProvider(layer, appId, null);
ServerAuthConfig serverConfig = provider.getServerAuthConfig(layer, appId, new AppCallbackHandler("jduke",
"badpwd".toCharArray()));
assertNotNull("ServerAuthConfig is not null", serverConfig);
MessageInfo mi = new GenericMessageInfo(new Object(), new Object());
String authContextID = serverConfig.getAuthContextID(mi);
assertNotNull("AuthContext ID != null", authContextID);
ServerAuthContext sctx = serverConfig.getAuthContext(authContextID, new Subject(), new HashMap());
assertNotNull("ServerAuthContext != null", sctx);
Subject clientSubject = new Subject();
Subject serviceSubject = new Subject();
try
{
AuthStatus status = sctx.validateRequest(mi, clientSubject, serviceSubject);
assertEquals(AuthStatus.FAILURE, status);
}
catch (AuthException ae)
{
// Pass
}
}
示例5: testSuccessfulJASPI
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testSuccessfulJASPI() throws Exception
{
AuthConfigProvider provider = factory.getConfigProvider(layer, appId, null);
ServerAuthConfig serverConfig = provider.getServerAuthConfig(layer, appId, new AppCallbackHandler("anil",
"anilpwd".toCharArray()));
assertNotNull("ServerAuthConfig is not null", serverConfig);
MessageInfo mi = new GenericMessageInfo(new Object(), new Object());
String authContextID = serverConfig.getAuthContextID(mi);
assertNotNull("AuthContext ID != null", authContextID);
ServerAuthContext sctx = serverConfig.getAuthContext(authContextID, new Subject(), new HashMap());
assertNotNull("ServerAuthContext != null", sctx);
Subject clientSubject = new Subject();
Subject serviceSubject = new Subject();
AuthStatus status = sctx.validateRequest(mi, clientSubject, serviceSubject);
assertEquals(AuthStatus.SUCCESS, status);
}
示例6: testUnSuccessfulJASPI
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testUnSuccessfulJASPI() throws Exception
{
AuthConfigProvider provider = factory.getConfigProvider(layer, appId, null);
ServerAuthConfig serverConfig = provider.getServerAuthConfig(layer, appId, new AppCallbackHandler("anil",
"badpwd".toCharArray()));
assertNotNull("ServerAuthConfig is not null", serverConfig);
validateJAASConfiguration();
MessageInfo mi = new GenericMessageInfo(new Object(), new Object());
String authContextID = serverConfig.getAuthContextID(mi);
assertNotNull("AuthContext ID != null", authContextID);
ServerAuthContext sctx = serverConfig.getAuthContext(authContextID, new Subject(), new HashMap());
assertNotNull("ServerAuthContext != null", sctx);
Subject clientSubject = new Subject();
Subject serviceSubject = new Subject();
try
{
AuthStatus status = sctx.validateRequest(mi, clientSubject, serviceSubject);
assertEquals(AuthStatus.FAILURE, status);
}
catch (AuthException ae)
{
//Ignore - we are fine
}
}
示例7: testServerFactoryConfig
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testServerFactoryConfig() throws Exception
{
assertNotNull("AuthConfigFactory is ! null", factory);
AuthConfigProvider provider = factory.getConfigProvider("TEST", "APP", null);
assertNotNull("AuthConfigProvider is ! null", provider);
ServerAuthConfig serverConfig =
provider.getServerAuthConfig("TEST", "APP",
new AppCallbackHandler("anil","anil".toCharArray()));
assertNotNull("ServerAuthConfig ! null", serverConfig);
MessageInfo mi = new GenericMessageInfo(new Object(), new Object());
String authContextID = serverConfig.getAuthContextID(mi);
assertNotNull("AuthContext ID != null",authContextID);
ServerAuthContext sctx = serverConfig.getAuthContext(authContextID,
new Subject(), new HashMap());
assertNotNull("ServerAuthContext != null",sctx);
}
示例8: testContext1
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
@Test
public void testContext1() throws Exception {
final CallbackHandler h = mock(CallbackHandler.class);
final Map<String, String> options = new HashMap<>();
final AuthModuleConfigProvider provider = new AuthModuleConfigProvider(options, null);
assertNull(provider.getClientAuthConfig("HttpServlet", "server1 /", h));
final ServerAuthConfig serverAuthConfig = provider.getServerAuthConfig("HttpServlet", "server1 /", h);
assertNotNull(serverAuthConfig);
assertEquals("server1 /", serverAuthConfig.getAppContext());
assertEquals("HttpServlet", serverAuthConfig.getMessageLayer());
final Subject serviceSubject = new Subject();
assertNull(serverAuthConfig.getAuthContextID(mock(MessageInfo.class)));
final MessageInfo messageInfoMandatory = mock(MessageInfo.class);
when(messageInfoMandatory.getMap()).thenReturn(Collections.singletonMap("javax.security.auth.message.MessagePolicy.isMandatory", "true"));
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(messageInfoMandatory.getRequestMessage()).thenReturn(servletRequest);
final HttpServletResponse servletResponse = mock(HttpServletResponse.class);
when(messageInfoMandatory.getResponseMessage()).thenReturn(servletResponse);
final String authContextID = serverAuthConfig.getAuthContextID(messageInfoMandatory);
assertNotNull(authContextID);
final ServerAuthContext authContext = serverAuthConfig.getAuthContext(authContextID, serviceSubject, new HashMap<>());
assertNotNull(authContext);
}
示例9: getAuthContext
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
@Override
public ServerAuthContext getAuthContext(final String authContextID,
final Subject serviceSubject,
@SuppressWarnings("rawtypes") final Map properties) throws AuthException {
final Map<?, ?> augmentedOptions = augmentProperties(properties);
final OpenIdConnectAuthModule module = new OpenIdConnectAuthModule();
if (authContextID == null) {
module.initialize(NON_MANDATORY, NON_MANDATORY, handler, augmentedOptions);
} else {
module.initialize(MANDATORY, MANDATORY, handler, augmentedOptions);
}
return module;
}
示例10: getAuthContext
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
@Override
public ServerAuthContext getAuthContext(String authContextID, Subject serviceSubject, Map properties) throws AuthException {
return new CustomServerAuthContext(serverAuthModules);
}
示例11: getAuthContext
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
@Override
public ServerAuthContext getAuthContext(String authContextID, Subject serviceSubject,
@SuppressWarnings("rawtypes") Map properties) throws AuthException {
return new DefaultServerAuthContext(handler, serverAuthModule);
}
示例12: getAuthContext
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
@Override
public ServerAuthContext getAuthContext(String authContextID, Subject serviceSubject,
@SuppressWarnings("rawtypes") Map properties) throws AuthException {
return new YubiServerAuthContext(handler);
}
示例13: JaspiServerAuthenticator
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
public JaspiServerAuthenticator(ServerAuthContext sctx)
{
this.sctx = sctx;
}
示例14: enableServerAuthentication
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
public boolean enableServerAuthentication(Deployment dep, JBossWebservicesMetaData wsmd)
{
String securityDomain = null;
if (wsmd != null)
{
securityDomain = wsmd.getProperty(JaspiServerAuthenticator.JASPI_SECURITY_DOMAIN);
}
if (securityDomain == null)
{
return false;
}
ApplicationPolicy appPolicy = SecurityConfiguration.getApplicationPolicy(securityDomain);
if (appPolicy == null)
{
Loggers.ROOT_LOGGER.noApplicationPolicy(securityDomain);
return false;
}
BaseAuthenticationInfo bai = appPolicy.getAuthenticationInfo();
if (bai == null || bai instanceof AuthenticationInfo)
{
Loggers.ROOT_LOGGER.noJaspiApplicationPolicy(securityDomain);
return false;
}
JASPIAuthenticationInfo jai = (JASPIAuthenticationInfo) bai;
String contextRoot = dep.getService().getContextRoot();
String appId = "localhost " + contextRoot;
AuthConfigFactory factory = AuthConfigFactory.getFactory();
Properties properties = new Properties();
AuthConfigProvider provider = new JBossWSAuthConfigProvider(properties, factory);
provider = factory.getConfigProvider(JBossWSAuthConstants.SOAP_LAYER, appId, null);
JBossCallbackHandler callbackHandler = new JBossCallbackHandler();
try
{
ServerAuthConfig serverConfig = provider.getServerAuthConfig(JBossWSAuthConstants.SOAP_LAYER, appId,
callbackHandler);
Properties serverContextProperties = new Properties();
serverContextProperties.put("security-domain", securityDomain);
serverContextProperties.put("jaspi-policy", jai);
Bus bus = dep.getAttachment(Bus.class);
serverContextProperties.put(Bus.class, bus);
String authContextID = dep.getSimpleName();
ServerAuthContext sctx = serverConfig.getAuthContext(authContextID, null, serverContextProperties);
JaspiServerAuthenticator serverAuthenticator = new JaspiServerAuthenticator(sctx);
bus.getInInterceptors().add(new JaspiSeverInInterceptor(serverAuthenticator));
bus.getOutInterceptors().add(new JaspiSeverOutInterceptor(serverAuthenticator));
return true;
}
catch (Exception e)
{
Loggers.DEPLOYMENT_LOGGER.cannotCreateServerAuthContext(securityDomain, e);
}
return false;
}
示例15: testProvider
import javax.security.auth.message.config.ServerAuthContext; //导入依赖的package包/类
@Test
public void testProvider() throws Exception {
final CallbackHandler h = mock(CallbackHandler.class);
final Map<String, String> options = new HashMap<>();
final AuthModuleConfigProvider provider = new AuthModuleConfigProvider(options, null);
assertNull(provider.getClientAuthConfig("HttpServlet", "server1 /", h));
final ServerAuthConfig serverAuthConfig = provider.getServerAuthConfig("HttpServlet", "server1 /", h);
assertNotNull(serverAuthConfig);
assertEquals("server1 /", serverAuthConfig.getAppContext());
assertEquals("HttpServlet", serverAuthConfig.getMessageLayer());
final Subject serviceSubject = new Subject();
assertNull(serverAuthConfig.getAuthContextID(mock(MessageInfo.class)));
final MessageInfo messageInfoMandatory = mock(MessageInfo.class);
when(messageInfoMandatory.getMap()).thenReturn(Collections.singletonMap("javax.security.auth.message.MessagePolicy.isMandatory", "true"));
final HttpSession session = mock(HttpSession.class);
final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
when(servletRequest.getMethod()).thenReturn("GET");
when(servletRequest.isSecure()).thenReturn(true);
when(servletRequest.getSession()).thenReturn(session);
when(servletRequest.getRequestURI()).thenReturn("/util/ejb2");
when(servletRequest.getContextPath()).thenReturn("/util");
when(messageInfoMandatory.getRequestMessage()).thenReturn(servletRequest);
final HttpServletResponse servletResponse = mock(HttpServletResponse.class);
when(messageInfoMandatory.getResponseMessage()).thenReturn(servletResponse);
final String authContextID = serverAuthConfig.getAuthContextID(messageInfoMandatory);
assertNotNull(authContextID);
final ServerAuthContext authContext = serverAuthConfig.getAuthContext(authContextID, serviceSubject, new HashMap<>());
assertNotNull(authContext);
final AuthStatus validateRequest = authContext.validateRequest(messageInfoMandatory, null, serviceSubject);
assertEquals(AuthStatus.SEND_SUCCESS, validateRequest);
final AuthStatus secureResponse = authContext.secureResponse(messageInfoMandatory, serviceSubject);
assertEquals(AuthStatus.SEND_SUCCESS, secureResponse);
authContext.cleanSubject(messageInfoMandatory, serviceSubject);
assertTrue(serverAuthConfig.isProtected());
serverAuthConfig.refresh();
provider.refresh();
}