Search in sources :

Example 1 with IOrientDbSettings

use of ru.ydn.wicket.wicketorientdb.IOrientDbSettings in project wicket-orientdb by OrienteerBAP.

the class OrientDBHttpAPIResource method mountOrientDbRestApi.

/**
 * Mounts OrientDB REST API Bridge to an app
 * @param resource {@link OrientDBHttpAPIResource} to mount
 * @param app {@link WebApplication} to mount to
 * @param mountPaths array of paths to mount to
 */
@SuppressWarnings("restriction")
public static void mountOrientDbRestApi(OrientDBHttpAPIResource resource, WebApplication app, String... mountPaths) {
    app.getSharedResources().add(ORIENT_DB_KEY, resource);
    Authenticator.setDefault(new Authenticator() {

        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            String username;
            String password;
            OrientDbWebSession session = OrientDbWebSession.get();
            if (session.isSignedIn()) {
                username = session.getUsername();
                password = session.getPassword();
            } else {
                IOrientDbSettings settings = OrientDbWebApplication.get().getOrientDbSettings();
                username = settings.getGuestUserName();
                password = settings.getGuestPassword();
            }
            return new PasswordAuthentication(username, password.toCharArray());
        }
    });
    CookieHandler.setDefault(new PersonalCookieManager());
    sun.net.www.protocol.http.AuthCacheValue.setAuthCache(new MultiUserCache());
    for (String mountPath : mountPaths) {
        app.mountResource(mountPath, new SharedResourceReference(ORIENT_DB_KEY));
    }
}
Also used : SharedResourceReference(org.apache.wicket.request.resource.SharedResourceReference) IOrientDbSettings(ru.ydn.wicket.wicketorientdb.IOrientDbSettings) OrientDbWebSession(ru.ydn.wicket.wicketorientdb.OrientDbWebSession) Authenticator(java.net.Authenticator) PasswordAuthentication(java.net.PasswordAuthentication)

Example 2 with IOrientDbSettings

use of ru.ydn.wicket.wicketorientdb.IOrientDbSettings in project wicket-orientdb by OrienteerBAP.

the class OrientDBHttpAPIResource method onMapHeaders.

@Override
protected void onMapHeaders(Attributes attributes, Headers.Builder builder) {
    if (builder.get(LazyAuthorizationRequestCycleListener.AUTHORIZATION_HEADER) == null) {
        String username;
        String password;
        OrientDbWebSession session = OrientDbWebSession.get();
        if (session.isSignedIn()) {
            username = session.getUsername();
            password = session.getPassword();
        } else {
            IOrientDbSettings settings = OrientDbWebApplication.get().getOrientDbSettings();
            username = settings.getGuestUserName();
            password = settings.getGuestPassword();
        }
        builder.add(LazyAuthorizationRequestCycleListener.AUTHORIZATION_HEADER, Credentials.basic(username, password));
    }
    builder.add("Accept-Encoding", "identity");
}
Also used : IOrientDbSettings(ru.ydn.wicket.wicketorientdb.IOrientDbSettings) OrientDbWebSession(ru.ydn.wicket.wicketorientdb.OrientDbWebSession)

Aggregations

IOrientDbSettings (ru.ydn.wicket.wicketorientdb.IOrientDbSettings)2 OrientDbWebSession (ru.ydn.wicket.wicketorientdb.OrientDbWebSession)2 Authenticator (java.net.Authenticator)1 PasswordAuthentication (java.net.PasswordAuthentication)1 SharedResourceReference (org.apache.wicket.request.resource.SharedResourceReference)1