Java源码示例:javax.security.enterprise.authentication.mechanism.http.BasicAuthenticationMechanismDefinition

示例1
public void init(@Observes @Initialized(ApplicationScoped.class) final ServletContext context) {
    final Map<String, ? extends ServletRegistration> servletRegistrations = context.getServletRegistrations();
    servletRegistrations.forEach((servletName, servletRegistration) -> {
        try {
            final Class<?> servletClass = Thread.currentThread().getContextClassLoader().loadClass(servletName);
            if (servletClass.isAnnotationPresent(BasicAuthenticationMechanismDefinition.class)) {
                servletAuthenticationMapper.put(servletName,
                                                CDI.current().select(BasicAuthenticationMechanism.class).get());
            }

            if (servletClass.isAnnotationPresent(FormAuthenticationMechanismDefinition.class)) {
                servletAuthenticationMapper.put(servletName,
                                                CDI.current().select(FormAuthenticationMechanism.class).get());
            }

        } catch (final ClassNotFoundException e) {
            // Ignore
        }
    });

    final Set<HttpAuthenticationMechanism> availableBeans =
            authenticationMechanisms.stream().collect(Collectors.toSet());
    availableBeans.removeAll(servletAuthenticationMapper.values());
    availableBeans.remove(defaultAuthenticationMechanism);

    if (availableBeans.size() == 1) {
        defaultAuthenticationMechanism.setDelegate(availableBeans.iterator().next());
    } else if (availableBeans.size() > 1) {
        throw new IllegalStateException(
                "Multiple HttpAuthenticationMechanism found " +
                availableBeans.stream()
                              .map(b -> substringBefore(b.getClass().getSimpleName(), "$$"))
                              .collect(toList()) + " " +
                "without a @WebServlet association. " +
                "Deploy a single one for the application, or associate it with a @WebServlet.");
    }
}
 
示例2
void processAuthenticationMechanismDefinitions(@Observes
                                               @WithAnnotations({
                                                       BasicAuthenticationMechanismDefinition.class,
                                                       FormAuthenticationMechanismDefinition.class
                                               }) final ProcessAnnotatedType<?> processAnnotatedType) {
    final AnnotatedType<?> annotatedType = processAnnotatedType.getAnnotatedType();

    if (annotatedType.isAnnotationPresent(BasicAuthenticationMechanismDefinition.class)) {
        basicAuthentication.add(annotatedType);
    }

    if (annotatedType.isAnnotationPresent(FormAuthenticationMechanismDefinition.class)) {
        formAuthentication.add(annotatedType);
    }
}