javax.security.auth.message.config.AuthConfigProvider Java Examples
The following examples show how to use
javax.security.auth.message.config.AuthConfigProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuthenticatorBase.java From Tomcat8-Source-Read with MIT License | 6 votes |
private JaspicState getJaspicState(AuthConfigProvider jaspicProvider, Request request, Response response, boolean authMandatory) throws IOException { JaspicState jaspicState = new JaspicState(); jaspicState.messageInfo = new MessageInfoImpl(request.getRequest(), response.getResponse(), authMandatory); try { CallbackHandler callbackHandler = createCallbackHandler(); ServerAuthConfig serverAuthConfig = jaspicProvider.getServerAuthConfig( "HttpServlet", jaspicAppContextID, callbackHandler); String authContextID = serverAuthConfig.getAuthContextID(jaspicState.messageInfo); jaspicState.serverAuthContext = serverAuthConfig.getAuthContext(authContextID, null, null); } catch (AuthException e) { log.warn(sm.getString("authenticator.jaspicServerAuthContextFail"), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return null; } return jaspicState; }
Example #2
Source File: JBossAuthConfigFactory.java From lams with GNU General Public License v2.0 | 6 votes |
public String[] getRegistrationIDs(AuthConfigProvider provider) { List<String> al = new ArrayList<String>(); if (provider == null) { al.addAll(keyToAuthConfigProviderMap.keySet()); } else { // get all entries that have the supplied provider as value and store their keys. for (Map.Entry<String, AuthConfigProvider> entry : this.keyToAuthConfigProviderMap.entrySet()) { if (entry.getValue().equals(provider)) al.add(entry.getKey()); } } String[] sarr = new String[al.size()]; al.toArray(sarr); return sarr; }
Example #3
Source File: TestAuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
private void doTestResistration(String layer, String appContext, String expectedRegId) { AuthConfigFactory factory = new AuthConfigFactoryImpl(); AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null); SimpleRegistrationListener listener = new SimpleRegistrationListener(layer, appContext); String regId = factory.registerConfigProvider(acp1, layer, appContext, null); Assert.assertEquals(expectedRegId, regId); factory.getConfigProvider(layer, appContext, listener); factory.removeRegistration(regId); Assert.assertTrue(listener.wasCorrectlyCalled()); listener.reset(); factory.registerConfigProvider(acp1, layer, appContext, null); factory.getConfigProvider(layer, appContext, listener); // Replace it AuthConfigProvider acp2 = new SimpleAuthConfigProvider(null, null); factory.registerConfigProvider(acp2, layer, appContext, null); Assert.assertTrue(listener.wasCorrectlyCalled()); }
Example #4
Source File: TestAuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
private void doTestSearchOrder(String layer, String appContext, int expected) { AuthConfigFactory factory = new AuthConfigFactoryImpl(); AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null); factory.registerConfigProvider(acp1, null, null, "1"); AuthConfigProvider acp2 = new SimpleAuthConfigProvider(null, null); factory.registerConfigProvider(acp2, null, "AC_1", "2"); AuthConfigProvider acp3 = new SimpleAuthConfigProvider(null, null); factory.registerConfigProvider(acp3, "L_1", null, "3"); AuthConfigProvider acp4 = new SimpleAuthConfigProvider(null, null); factory.registerConfigProvider(acp4, "L_2", "AC_2", "4"); AuthConfigProvider searchResult = factory.getConfigProvider(layer, appContext, null); int searchIndex; if (searchResult == acp1) { searchIndex = 1; } else if (searchResult == acp2) { searchIndex = 2; } else if (searchResult == acp3) { searchIndex = 3; } else if (searchResult == acp4) { searchIndex = 4; } else { searchIndex = -1; } Assert.assertEquals(expected, searchIndex); }
Example #5
Source File: AuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public String[] getRegistrationIDs(AuthConfigProvider provider) { List<String> result = new ArrayList<>(); if (provider == null) { result.addAll(layerAppContextRegistrations.keySet()); result.addAll(appContextRegistrations.keySet()); result.addAll(layerRegistrations.keySet()); if (!defaultRegistration.isEmpty()) { result.add(DEFAULT_REGISTRATION_ID); } } else { findProvider(provider, layerAppContextRegistrations, result); findProvider(provider, appContextRegistrations, result); findProvider(provider, layerRegistrations, result); findProvider(provider, defaultRegistration, result); } return result.toArray(EMPTY_STRING_ARRAY); }
Example #6
Source File: AuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
@SuppressWarnings("unchecked") private String doRegisterConfigProvider(String className, @SuppressWarnings("rawtypes") Map properties, String layer, String appContext, String description) { if (log.isDebugEnabled()) { log.debug(sm.getString("authConfigFactoryImpl.registerClass", className, layer, appContext)); } AuthConfigProvider provider = null; if (className != null) { provider = createAuthConfigProvider(className, properties); } String registrationID = getRegistrationID(layer, appContext); RegistrationContextImpl registrationContextImpl = new RegistrationContextImpl( layer, appContext, description, true, provider, properties); addRegistrationContextImpl(layer, appContext, registrationID, registrationContextImpl); return registrationID; }
Example #7
Source File: AuthenticatorBase.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public boolean authenticate(Request request, HttpServletResponse httpResponse) throws IOException { AuthConfigProvider jaspicProvider = getJaspicProvider(); if (jaspicProvider == null) { return doAuthenticate(request, httpResponse); } else { Response response = request.getResponse(); JaspicState jaspicState = getJaspicState(jaspicProvider, request, response, true); if (jaspicState == null) { return false; } boolean result = authenticateJaspic(request, response, jaspicState, true); secureResponseJspic(request, response, jaspicState); return result; } }
Example #8
Source File: TestAuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testDetachListenerNonexistingRegistration() { AuthConfigFactory factory = new AuthConfigFactoryImpl(); AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null); String registrationId = factory.registerConfigProvider(acp1, "L_1", "AC_1", null); SimpleRegistrationListener listener1 = new SimpleRegistrationListener("L_1", "AC_1"); factory.getConfigProvider("L_1", "AC_1", listener1); factory.removeRegistration(registrationId); String[] registrationIds = factory.detachListener(listener1, "L_1", "AC_1"); Assert.assertTrue(registrationIds.length == 0); }
Example #9
Source File: TomEESecurityContext.java From tomee with Apache License 2.0 | 5 votes |
private ServerAuthContext getServerAuthContext(final HttpServletRequest request) throws AuthException { final String appContext = request.getServletContext().getVirtualServerName() + " " + request.getContextPath(); final AuthConfigProvider authConfigProvider = AuthConfigFactory.getFactory().getConfigProvider("HttpServlet", appContext, null); final ServerAuthConfig serverAuthConfig = authConfigProvider.getServerAuthConfig("HttpServlet", appContext, CallbackHandlerImpl.getInstance()); return serverAuthConfig.getAuthContext(null, null, null); }
Example #10
Source File: JBossAuthConfigFactory.java From lams with GNU General Public License v2.0 | 5 votes |
public AuthConfigProvider getConfigProvider(String layer, String appContext, RegistrationListener listener) { String input = new StringBuilder().append(layer).append(appContext).toString(); String allLayer = "null" + appContext; String allContext = layer + "null"; String general = "nullnull"; AuthConfigProvider acp = null; String key = null; for (int i = 0; i < 4; i++) { if (i == 0) key = input; if (i == 1) key = allLayer; if (i == 2) key = allContext; if (i == 3) key = general; if (this.keyToAuthConfigProviderMap.containsKey(key)) { acp = this.keyToAuthConfigProviderMap.get(key); break; } } // if (listener != null) this.keyToRegistrationListenerMap.put(input, listener); return acp; }
Example #11
Source File: TestAuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
private void doTestNullClassName(boolean shouldOverrideExistingProvider, String layer, String appContext) { AuthConfigFactory factory = new AuthConfigFactoryImpl(); if (shouldOverrideExistingProvider) { factory.registerConfigProvider(SimpleAuthConfigProvider.class.getName(), null, layer, appContext, null); } String registrationId = factory.registerConfigProvider(null, null, layer, appContext, null); factory.refresh(); String[] registrationIds = factory.getRegistrationIDs(null); Set<String> ids = new HashSet<>(Arrays.asList(registrationIds)); Assert.assertTrue(ids.contains(registrationId)); AuthConfigProvider provider = factory.getConfigProvider(layer, appContext, null); Assert.assertNull(provider); }
Example #12
Source File: TestAuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testAllRegistrationIds() { AuthConfigFactory factory = new AuthConfigFactoryImpl(); AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null); String registrationId1 = factory.registerConfigProvider(acp1, "L_1", "AC_1", null); AuthConfigProvider acp2 = new SimpleAuthConfigProvider(null, null); String registrationId2 = factory.registerConfigProvider(acp2, "L_2", "AC_2", null); String[] registrationIds = factory.getRegistrationIDs(null); Assert.assertTrue(registrationIds.length == 2); Set<String> ids = new HashSet<>(Arrays.asList(registrationIds)); Assert.assertTrue(ids.contains(registrationId1)); Assert.assertTrue(ids.contains(registrationId2)); }
Example #13
Source File: TestAuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testRegistrationNullListener() { AuthConfigFactory factory = new AuthConfigFactoryImpl(); AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null); String registrationId = factory.registerConfigProvider(acp1, "L_1", "AC_1", null); factory.getConfigProvider("L_1", "AC_1", null); boolean result = factory.removeRegistration(registrationId); Assert.assertTrue(result); }
Example #14
Source File: TestAuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testDetachListener() { AuthConfigFactory factory = new AuthConfigFactoryImpl(); AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null); String registrationId = factory.registerConfigProvider(acp1, "L_1", "AC_1", null); SimpleRegistrationListener listener1 = new SimpleRegistrationListener("L_1", "AC_1"); factory.getConfigProvider("L_1", "AC_1", listener1); String[] registrationIds = factory.detachListener(listener1, "L_1", "AC_1"); Assert.assertTrue(registrationIds.length == 1); Assert.assertEquals(registrationId, registrationIds[0]); }
Example #15
Source File: AuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public AuthConfigProvider getConfigProvider(String layer, String appContext, RegistrationListener listener) { RegistrationContextImpl registrationContext = findRegistrationContextImpl(layer, appContext); if (registrationContext != null) { if (listener != null) { RegistrationListenerWrapper wrapper = new RegistrationListenerWrapper( layer, appContext, listener); registrationContext.addListener(wrapper); } return registrationContext.getProvider(); } return null; }
Example #16
Source File: AuthenticatorBase.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public void logout(Request request) { AuthConfigProvider provider = getJaspicProvider(); if (provider != null) { MessageInfo messageInfo = new MessageInfoImpl(request, request.getResponse(), true); Subject client = (Subject) request.getNote(Constants.REQ_JASPIC_SUBJECT_NOTE); if (client != null) { ServerAuthContext serverAuthContext; try { ServerAuthConfig serverAuthConfig = provider.getServerAuthConfig("HttpServlet", jaspicAppContextID, CallbackHandlerImpl.getInstance()); String authContextID = serverAuthConfig.getAuthContextID(messageInfo); serverAuthContext = serverAuthConfig.getAuthContext(authContextID, null, null); serverAuthContext.cleanSubject(messageInfo, client); } catch (AuthException e) { log.debug(sm.getString("authenticator.jaspicCleanSubjectFail"), e); } } } Principal p = request.getPrincipal(); if (p instanceof TomcatPrincipal) { try { ((TomcatPrincipal) p).logout(); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.debug(sm.getString("authenticator.tomcatPrincipalLogoutFail"), t); } } register(request, request.getResponse(), null, null, null, null); }
Example #17
Source File: AuthenticatorBase.java From Tomcat8-Source-Read with MIT License | 5 votes |
private AuthConfigProvider getJaspicProvider() { AuthConfigProvider provider = jaspicProvider; if (provider == null) { provider = findJaspicProvider(); } if (provider == NO_PROVIDER_AVAILABLE) { return null; } return provider; }
Example #18
Source File: AuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
private RegistrationContextImpl(String messageLayer, String appContext, String description, boolean persistent, AuthConfigProvider provider, Map<String,String> properties) { this.messageLayer = messageLayer; this.appContext = appContext; this.description = description; this.persistent = persistent; this.provider = provider; Map<String,String> propertiesCopy = new HashMap<>(); if (properties != null) { propertiesCopy.putAll(properties); } this.properties = Collections.unmodifiableMap(propertiesCopy); }
Example #19
Source File: AuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
private void findProvider(AuthConfigProvider provider, Map<String,RegistrationContextImpl> registrations, List<String> result) { for (Entry<String,RegistrationContextImpl> entry : registrations.entrySet()) { if (provider.equals(entry.getValue().getProvider())) { result.add(entry.getKey()); } } }
Example #20
Source File: AuthenticatorBase.java From Tomcat8-Source-Read with MIT License | 5 votes |
private AuthConfigProvider findJaspicProvider() { AuthConfigFactory factory = AuthConfigFactory.getFactory(); AuthConfigProvider provider = null; if (factory != null) { provider = factory.getConfigProvider("HttpServlet", jaspicAppContextID, this); } if (provider == null) { provider = NO_PROVIDER_AVAILABLE; } jaspicProvider = provider; return provider; }
Example #21
Source File: AuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public String registerConfigProvider(AuthConfigProvider provider, String layer, String appContext, String description) { if (log.isDebugEnabled()) { log.debug(sm.getString("authConfigFactoryImpl.registerInstance", provider.getClass().getName(), layer, appContext)); } String registrationID = getRegistrationID(layer, appContext); RegistrationContextImpl registrationContextImpl = new RegistrationContextImpl( layer, appContext, description, false, provider, null); addRegistrationContextImpl(layer, appContext, registrationID, registrationContextImpl); return registrationID; }
Example #22
Source File: TestAuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 4 votes |
private void doTestRegistrationInsert(String newLayer, String newAppContext, String expectedListenerLayer, String expectedListenerAppContext) { // Set up AuthConfigFactory factory = new AuthConfigFactoryImpl(); AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null); factory.registerConfigProvider(acp1, "L_1", "AC_1", null); AuthConfigProvider acp2 = new SimpleAuthConfigProvider(null, null); factory.registerConfigProvider(acp2, null, "AC_2", null); AuthConfigProvider acp3 = new SimpleAuthConfigProvider(null, null); factory.registerConfigProvider(acp3, "L_2", null, null); AuthConfigProvider acp4 = new SimpleAuthConfigProvider(null, null); factory.registerConfigProvider(acp4, null, null, null); SimpleRegistrationListener listener1 = new SimpleRegistrationListener("L_1", "AC_1"); factory.getConfigProvider("L_1", "AC_1", listener1); SimpleRegistrationListener listener2 = new SimpleRegistrationListener("L_3", "AC_2"); factory.getConfigProvider("L_3", "AC_2", listener2); SimpleRegistrationListener listener3 = new SimpleRegistrationListener("L_2", "AC_3"); factory.getConfigProvider("L_2", "AC_3", listener3); SimpleRegistrationListener listener4 = new SimpleRegistrationListener("L_4", "AC_4"); factory.getConfigProvider("L_4", "AC_4", listener4); List<SimpleRegistrationListener> listeners = new ArrayList<>(); listeners.add(listener1); listeners.add(listener2); listeners.add(listener3); listeners.add(listener4); // Register a new provider that will impact some existing registrations AuthConfigProvider acpNew = new SimpleAuthConfigProvider(null, null); factory.registerConfigProvider(acpNew, newLayer, newAppContext, null); // Check to see if the expected listener fired. for (SimpleRegistrationListener listener : listeners) { if (listener.wasCalled()) { Assert.assertEquals(listener.layer, expectedListenerLayer); Assert.assertEquals(listener.appContext, expectedListenerAppContext); Assert.assertTrue(listener.wasCorrectlyCalled()); } else { Assert.assertFalse((listener.layer.equals(expectedListenerLayer) && listener.appContext.equals(expectedListenerAppContext))); } } }
Example #23
Source File: AuthConfigFactoryImpl.java From Tomcat8-Source-Read with MIT License | 4 votes |
private AuthConfigProvider getProvider() { return provider; }
Example #24
Source File: Target_AuthenticatorBase.java From spring-graalvm-native with Apache License 2.0 | 4 votes |
@Substitute private AuthConfigProvider getJaspicProvider() { return null; }
Example #25
Source File: Target_AuthenticatorBase.java From spring-graalvm-native with Apache License 2.0 | 4 votes |
@Substitute private Optional<AuthConfigProvider> findJaspicProvider() { jaspicProvider = Optional.empty(); return jaspicProvider; }