Search in sources :

Example 1 with DemoUser

use of de.ids_mannheim.korap.user.DemoUser in project Kustvakt by KorAP.

the class KustvaktAuthenticationManager method setAccessAndLocation.

// a. set location depending on X-Forwarded-For.
// X-Forwarded-For: clientIP, ProxyID, ProxyID...
// the following private address spaces may be used to define intranet
// spaces:
// 10.0.0.0 - 10.255.255.255 (10/8 prefix)
// 172.16.0.0 - 172.31.255.255 (172.16/12 prefix)
// 192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
// b. set corpusAccess depending on location:
// c. DemoUser only gets corpusAccess=FREE.
// 16.05.17/FB
@Override
public void setAccessAndLocation(User user, HttpHeaders headers) {
    MultivaluedMap<String, String> headerMap = headers.getRequestHeaders();
    Location location = Location.EXTERN;
    CorpusAccess corpusAccess = CorpusAccess.FREE;
    if (user instanceof DemoUser) {
        // to be absolutely sure:
        user.setCorpusAccess(User.CorpusAccess.FREE);
        if (DEBUG) {
            jlog.debug("setAccessAndLocation: DemoUser: location=" + user.locationtoString() + " access=" + user.accesstoString());
        }
        return;
    }
    if (headerMap != null && headerMap.containsKey(HttpHeader.X_FORWARDED_FOR.toString())) {
        String[] vals = headerMap.getFirst(HttpHeader.X_FORWARDED_FOR.toString()).split(",");
        String clientAddress = vals[0];
        try {
            InetAddress ip = InetAddress.getByName(clientAddress);
            if (ip.isSiteLocalAddress()) {
                location = Location.INTERN;
                corpusAccess = CorpusAccess.ALL;
            } else {
                corpusAccess = CorpusAccess.PUB;
            }
            if (DEBUG) {
                jlog.debug(String.format("X-Forwarded-For : '%s' (%d values) -> %s\n", Arrays.toString(vals), vals.length, vals[0]));
                jlog.debug(String.format("X-Forwarded-For : location = %s corpusAccess = %s\n", location == Location.INTERN ? "INTERN" : "EXTERN", corpusAccess == CorpusAccess.ALL ? "ALL" : corpusAccess == CorpusAccess.PUB ? "PUB" : "FREE"));
            }
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        user.setLocation(location);
        user.setCorpusAccess(corpusAccess);
        if (DEBUG) {
            jlog.debug("setAccessAndLocation: KorAPUser: location=" + user.locationtoString() + ", access=" + user.accesstoString());
        }
    }
}
Also used : CorpusAccess(de.ids_mannheim.korap.user.User.CorpusAccess) DemoUser(de.ids_mannheim.korap.user.DemoUser) UnknownHostException(java.net.UnknownHostException) InetAddress(java.net.InetAddress) Location(de.ids_mannheim.korap.user.User.Location)

Aggregations

DemoUser (de.ids_mannheim.korap.user.DemoUser)1 CorpusAccess (de.ids_mannheim.korap.user.User.CorpusAccess)1 Location (de.ids_mannheim.korap.user.User.Location)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1