Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.yammer.dropwizard.auth.basic;
 
    private static final String PREFIX = "Basic";
    private static final String HEADER_NAME = "WWW-Authenticate";
    private static final String HEADER_VALUE =  + " realm=\"%s\"";
    private final Authenticator<BasicCredentials, T> authenticator;
    private final String realm;
    private final boolean required;
    BasicAuthInjectable(Authenticator<BasicCredentials, T> authenticatorString realmboolean required) {
        this. = authenticator;
        this. = realm;
        this. = required;
    }
        return ;
    }
    public String getRealm() {
        return ;
    }
    public boolean isRequired() {
        return ;
    }
    @Override
    public T getValue(HttpContext c) {
        final String header = c.getRequest().getHeaderValue(.);
        try {
            if (header != null) {
                final int space = header.indexOf(' ');
                if (space > 0) {
                    final String method = header.substring(0, space);
                    if (.equalsIgnoreCase(method)) {
                        final String decoded = B64Code.decode(header.substring(space + 1),
                                                              .);
                        final int i = decoded.indexOf(':');
                        if (i > 0) {
                            final String username = decoded.substring(0, i);
                            final String password = decoded.substring(i + 1);
                            final BasicCredentials credentials = new BasicCredentials(username,
                                                                                      password);
                            final Optional<T> result = .authenticate(credentials);
                            if (result.isPresent()) {
                                return result.get();
                            }
                        }
                    }
                }
            }
        } catch (UnsupportedEncodingException e) {
            ..debug(e"Error decoding credentials");
        } catch (IllegalArgumentException e) {
            ..debug(e"Error decoding credentials");
        } catch (AuthenticationException e) {
            ..warn(e"Error authenticating credentials");
            throw new WebApplicationException(..);
        }
        if () {
            throw new WebApplicationException(Response.status(..)
                                                      .header(,
                                                              String.format())
                                                      .entity("Credentials are required to access this resource.")
                                                      .type(.)
                                                      .build());
        }
        return null;
    }
New to GrepCode? Check out our FAQ X