For anyone else who might make the same mistake I did, I changed this:

  (GET "/admin" request (friend/authorize #{::admin}  (admin
request)))
to this:

  (GET "/admin" request (friend/authorize #{::admin} {} (admin
request)))

adding an empty map before the string that is my actual HTML page.
That resolved the error in the stack trace.

However, my login still fails. I copy and paste both the username and
password, very carefully, into the login form, and hit submit, only to
get redirected to:

http://localhost:30000/login?&login_failed=Y&username=

I have not idea why this fails. I thought I had followed the
documentation carefully, but I suppose there is always something that
I miss.





On Jan 16, 1:30 am, larry google groups <lawrencecloj...@gmail.com>
wrote:
> Looking here:
>
> https://github.com/cemerick/friend/blob/master/src/cemerick/friend.clj
>
> I see in the stacktrace that the problem seems to be with the last
> line of this function:
>
> (defn default-unauthenticated-handler
>   [request]
>   (-> request
>     ::auth-config
>     :login-uri
>     (util/resolve-absolute-uri request)
>     ring.util.response/redirect
>     (assoc :session (:session request))
>     (assoc-in [:session ::unauthorized-uri] (:uri request))))
>
> I guess I've turned the request into a string by this point? I can get
> to the unauthenticated routes in my app without a problem. They work
> great. It is only the authenticated routes that blow up.
>
> I am a bit confused about what is going on.
>
> On Jan 16, 1:26 am, larry google groups <lawrencecloj...@gmail.com>
> wrote:
>
>
>
>
>
>
>
> > Reading here:
>
> >https://github.com/cemerick/friend
>
> > I see this:
>
> > (Note that Friend itself requires some core Ring middlewares: params,
> > keyword-params and nested-params.
>
> > I did not have nested-params so I will add this.
>
> > This might be a stupid question, but why doesn't Friend include the
> > Ring middlewares that it depends on? Why do I have to manually hook
> > these in when writing my app?
>
> > On Jan 16, 1:00 am, larry google groups <lawrencecloj...@gmail.com>
> > wrote:
>
> > > I have the following setting up an app where some pages will be
> > > protected by Friend.
>
> > > (defroutes app-routes
> > >   (GET "/" request (index request))
> > >   (GET "/search-results" request (search-results request))
> > >   (GET "/account" request (friend/authorize #{::user} (account
> > > request)))
> > >   (GET "/admin" request (friend/authorize #{::admin} (admin request)))
> > >   (friend/logout (ANY "/logout" request (ring.util.response/redirect
> > > "/")))
> > >   (GET "/login" request (login request))
> > >   (route/not-found "Page not found"))
>
> > > (def app
> > >     (-> app-routes
> > >         (friend/authenticate {:credential-fn (partial creds/bcrypt-
> > > credential-fn (:users @interactions))
> > >                               :workflows [(workflows/interactive-
> > > form)]})
> > >         (wrap-resource "public")
> > >         (wrap-session {:cookie-name "discovery-session" :cookie-attrs
> > > {:max-age 10000 }})
> > >         (wrap-cookies)
> > >         (wrap-params)))
>
> > > (defn -main [& args]
> > >   (let [port (Integer/parseInt (first args))]
> > >     (try
> > >       (run-jetty #'app {:port (or port 8080) :join? false})
> > >       (catch Exception e (debug/print-error-info e)))))
>
> > >  If I try to go to /admin without being logged in, I should get
> > > redirected to /login, but instead I get:
>
> > > java.lang.ClassCastException: java.lang.String cannot be cast to
> > > clojure.lang.Associative
> > >         at clojure.lang.RT.assoc(RT.java:691)
> > >         at clojure.core$assoc.invoke(core.clj:187)
> > >         at clojure.core$assoc_in.invoke(core.clj:5459)
> > >         at clojure.core$assoc_in.invoke(core.clj:5458)
> > >         at cemerick.friend
> > > $default_unauthenticated_handler.invoke(friend.clj:164)
> > >         at clojure.lang.Var.invoke(Var.java:415)
> > >         at cemerick.friend$authenticate_STAR_.invoke(friend.clj:202)
> > >         at cemerick.friend$authenticate$fn__1341.invoke(friend.clj:
> > > 207)
> > >         at ring.middleware.resource$wrap_resource
> > > $fn__2730.invoke(resource.clj:17)
> > >         at ring.middleware.session$wrap_session
> > > $fn__2651.invoke(session.clj:43)
> > >         at ring.middleware.cookies$wrap_cookies
> > > $fn__2588.invoke(cookies.clj:160)
> > >         at ring.middleware.cookies$wrap_cookies
> > > $fn__2588.invoke(cookies.clj:160)
> > >         at ring.middleware.params$wrap_params
> > > $fn__2400.invoke(params.clj:55)
> > >         at clojure.lang.Var.invoke(Var.java:415)
> > >         at ring.adapter.jetty$proxy_handler$fn__2809.invoke(jetty.clj:
> > > 18)
> > >         at ring.adapter.jetty.proxy
> > > $org.eclipse.jetty.server.handler.AbstractHandler$0.handle(Unknown
> > > Source)
> > >         at
> > > org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:
> > > 111)
> > >         at org.eclipse.jetty.server.Server.handle(Server.java:349)
> > >         at
> > > org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpC
> > >  onnection.java:
> > > 452)
> > >         at
> > > org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttp
> > >  Connection.java:
> > > 884)
> > >         at org.eclipse.jetty.server.AbstractHttpConnection
> > > $RequestHandler.headerComplete(AbstractHttpConnection.java:938)
> > >         at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:
> > > 634)
> > >         at
> > > org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230)
> > >         at
> > > org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.jav
> > >  a:
> > > 76)
> > >         at
> > > org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint
> > >  .java:
> > > 609)
> > >         at org.eclipse.jetty.io.nio.SelectChannelEndPoint
> > > $1.run(SelectChannelEndPoint.java:45)
> > >         at
> > > org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java
> > >  :
> > > 599)
> > >         at org.eclipse.jetty.util.thread.QueuedThreadPool
> > > $3.run(QueuedThreadPool.java:534)
> > >         at java.lang.Thread.run(Thread.java:722)
>
> > > Has anyone seen this error before?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to