How to disable a provider in SecureSocial?
Asked Answered
O

2

5

I am using Play Framework 2.3.2 with Activator 1.2.3 and am experimenting with SecureSocial plugin master-SNAPSHOT.

Documentation says the following:

SecureSocial is designed in a modular architecture using plugins. This means you can easily enable/disable them to include only what you need and also that you can change the built-in plugins for your own implementation if there is a need to customize how things work.

Plugins are defined in the play.plugins file under the conf directory. If you don't have that file yet create one and add:

[example list of plugins]

Only the authentication providers you include in the play.plugins file will appear on the login page.

(Emphasis added.)

I am now trying out the Java Demo included in the SecureSocial repository. The play.plugins file contains only a single row:

1500:com.typesafe.plugin.CommonsMailerPlugin

But if I run the demo, all the providers are available: Running demo screenshot

How do I turn off some providers? Based on the documentation I'd expect to comment out some lines in play.plugins, but there are none to comment out.

What is going on here?

Outvote answered 3/8, 2014 at 12:31 Comment(0)
C
7

If the providers are not configured in the plugins file you must be using master-SNAPSHOT - instead of 2.1.3 - which does not use Play plugins anymore. Instead there is now a RuntimeEnvironment where you configure the services available for the module (including the UserService you need to implement).

The default environment includes all the providers and is what the demo uses: https://github.com/jaliss/securesocial/blob/master/samples/java/demo/app/service/MyEnvironment.scala

There a lot of changes in master and the docs have not been updated yet. To customize the providers available you need to create your own environment class extending RuntimeEnvironment.Default and override the providers field. For example:

class MyEnvironment extends RuntimeEnvironment.Default[DemoUser] {
    override val userService: UserService[DemoUser] = new MyUserService()
    override lazy val providers = ListMap(
         include(
            new FacebookProvider(routes, cacheService,oauth2ClientFor(FacebookProvider.Facebook))
         ),
         include(
            new FoursquareProvider(routes,cacheService,oauth2ClientFor(FoursquareProvider.Foursquare))
         ),
         include(
            new UsernamePasswordProvider[DemoUser](userService, avatarService, viewTemplates, passwordHashers)
         )
    )
}

Where MyUserService is your UserService implementation and DemoUser is the class you want to use to represent users in your actions.

Crutchfield answered 6/8, 2014 at 20:38 Comment(3)
Hey, thanks for the info. Yes, it's actually master-SNAPSHOT (I am crazy from all the incompatible versions of stuff when working with Play, so this slipped me). In MyEnvironment I overrode providers, left only those that I want and it works! If you update your answer to spell out the procedure I will accept it.Outvote
Is there a Java equivalent for this? I am new to Scala and am struggling to get this working in java.Ibert
The environment needs to be written in Scala. Checkout the sample Java demo in the repository to see how it is used. See github.com/jaliss/securesocial/blob/master/samples/java/demo/… and github.com/jaliss/securesocial/blob/master/samples/java/demo/…Crutchfield
P
0

Well I am implementing my solution in JAVA. And I wanted to do the same thing. Following is my final code for this solution. I made a function "filter" and override the providers() method.

  public class SocialSecureRuntimeEnvironment extends RuntimeEnvironment.Default<Nuser> {
  private BaseUserService<Nuser> userService = new NuserService();
  private ListMap<String, IdentityProvider> providers = null;

  @Override
  public BaseUserService<Nuser> userService() {
    return userService;
  }

  @Override
  public ListMap<String, IdentityProvider> providers() {
    if (providers != null) {
      return providers;
    }
    providers = filter(super.providers(), "userpass");
    return providers;
  }

  @SuppressWarnings("unchecked")
  private ListMap<String, IdentityProvider> filter(ListMap<String, IdentityProvider> current,
      String provider) {
    while (current.size() > 0 && !current.key().equals(provider)) {
      current = current.next();
    }

    if (current.size() > 1) {
      current = (ListMap<String, IdentityProvider>) current.drop(current.size() - 1);
    }
    return current;
  }
}

Following is what my Login Screen looks like after this.

enter image description here

Pimply answered 3/4, 2015 at 15:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.