Search in sources :

Example 1 with OrientDbWebSession

use of ru.ydn.wicket.wicketorientdb.OrientDbWebSession 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 OrientDbWebSession

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

the class WicketSessionCookieJar method setSessionCookies.

protected void setSessionCookies(SessionCookies sessionCookies) {
    OrientDbWebSession session = OrientDbWebSession.get();
    session.setAttribute(OK_HTTP_COOKIES, sessionCookies);
}
Also used : OrientDbWebSession(ru.ydn.wicket.wicketorientdb.OrientDbWebSession)

Example 3 with OrientDbWebSession

use of ru.ydn.wicket.wicketorientdb.OrientDbWebSession 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)

Example 4 with OrientDbWebSession

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

the class PersonalCookieManager method getPersonalCookieManager.

protected CookieManager getPersonalCookieManager() {
    try {
        if (!ThreadContext.exists() || RequestCycle.get() == null)
            return defaultManager;
        OrientDbWebSession session = OrientDbWebSession.get();
        session.bind();
        String id = session.getId();
        if (session.isSignedIn())
            id = session.getUsername() + '-' + id;
        return cache.get(id, new Callable<CookieManager>() {

            @Override
            public CookieManager call() throws Exception {
                return new CookieManager();
            }
        });
    } catch (ExecutionException e) {
        throw new IllegalStateException("Cookie Manager should be always calculated");
    }
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) OrientDbWebSession(ru.ydn.wicket.wicketorientdb.OrientDbWebSession) CookieManager(java.net.CookieManager) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with OrientDbWebSession

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

the class WicketSessionCookieJar method getSessionCookies.

protected SessionCookies getSessionCookies() {
    OrientDbWebSession session = OrientDbWebSession.get();
    SessionCookies sessionCookies = (SessionCookies) session.getAttribute(OK_HTTP_COOKIES);
    if (sessionCookies == null) {
        sessionCookies = new SessionCookies();
        setSessionCookies(sessionCookies);
    }
    return sessionCookies;
}
Also used : OrientDbWebSession(ru.ydn.wicket.wicketorientdb.OrientDbWebSession)

Aggregations

OrientDbWebSession (ru.ydn.wicket.wicketorientdb.OrientDbWebSession)5 IOrientDbSettings (ru.ydn.wicket.wicketorientdb.IOrientDbSettings)2 IOException (java.io.IOException)1 Authenticator (java.net.Authenticator)1 CookieManager (java.net.CookieManager)1 PasswordAuthentication (java.net.PasswordAuthentication)1 ExecutionException (java.util.concurrent.ExecutionException)1 SharedResourceReference (org.apache.wicket.request.resource.SharedResourceReference)1