eu.limetri.ygg.auth.keycloak.dummy.DummySecureRestletBinding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ygg-auth-keycloak-dummy Show documentation
Show all versions of ygg-auth-keycloak-dummy Show documentation
This is a dummy implementation of ygg-auth-keycloak, which just accepts every request.
It is intended for LOCAL testing purposes ONLY! Do NOT use in production!
/**
* Copyright (C) 2014 ATB. All rights reserved.
*
* This library is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* There are special exceptions to the terms and conditions of the GPLv3 as it
* is applied to this software, see the FLOSS License Exception
* .
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this library. If not, see .
*/
package eu.limetri.ygg.auth.keycloak.dummy;
import eu.limetri.ygg.api.AccessToken;
import eu.limetri.ygg.api.Context;
import org.apache.camel.Exchange;
import org.apache.camel.component.restlet.DefaultRestletBinding;
import org.restlet.Request;
import org.restlet.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author Philip Reimer
*/
@Component("authBinding")
public class DummySecureRestletBinding extends DefaultRestletBinding {
private static final Logger log = LoggerFactory.getLogger(DummySecureRestletBinding.class);
@Autowired
private Context context;
public void setContext(Context context) {
this.context = context;
}
@Override
public void populateExchangeFromRestletRequest(Request request, Response response, Exchange exchange)
throws Exception {
//
// needed for default mapping of headers
//
super.populateExchangeFromRestletRequest(request, response, exchange);
AccessToken accessToken = new DummyKeycloakAccessToken();
exchange.setProperty(AccessToken.PROP_ACCESS_TOKEN, accessToken);
context.setAccessToken(accessToken);
}
static class DummyKeycloakAccessToken implements AccessToken {
@Override
public boolean hasRole(String role) {
return true;
}
@Override
public String getUserName() {
return "humpty-dumpty";
}
@Override
public String getFirstName() {
return "Humpty";
}
@Override
public String getLastName() {
return "Dumpty";
}
@Override
public String getId() {
return "nouser";
}
@Override
public String getUserProfilePage() {
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy