001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.auth.integration;
007
008import static org.junit.Assert.assertEquals;
009
010import java.io.IOException;
011
012import org.apache.commons.codec.binary.Base64;
013import org.apache.http.client.methods.HttpGet;
014import org.apache.http.message.AbstractHttpMessage;
015import org.junit.Test;
016
017/**
018 * @author peichman
019 */
020public class ServletContainerAuthenticatingRealmIT extends AbstractResourceIT {
021
022    /**
023     * Convenience method for applying HTTP Basic auth credentials to a request
024     *
025     * @param method the request to add the credentials to
026     * @param username the username to add
027     */
028    private static void setAuth(final AbstractHttpMessage method, final String username) {
029        final String creds = username + ":password";
030        final String encCreds = new String(Base64.encodeBase64(creds.getBytes()));
031        final String basic = "Basic " + encCreds;
032        method.setHeader("Authorization", basic);
033    }
034
035   @Test
036    public void testUserWithoutRoles() throws IOException {
037        // make sure this doesn't cause Shiro to explode
038        final HttpGet request = new HttpGet(serverAddress);
039        setAuth(request, "noroles");
040        assertEquals(200, getStatus(request));
041    }
042
043}