Advertisement
Guest User

Untitled

a guest
Mar 24th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /**
  2. * {@code IAuthenticationStrategy} that allows developers to automatically log in without entering a user name and
  3. * password. To enable this functionality the application you must put the following in the Application.init method:
  4. * <pre>
  5. * getSecuritySettings().setAuthenticationStrategy(new DeveloperAutologinAuthenticationStrategy());
  6. * </pre>
  7. * Once set as the application's IAuthenticationStrategy you must set the following system properties before starting
  8. * the application and the application must be running in DEVELOPMENT mode.
  9. * <pre>
  10. * -Duser=devuser
  11. * -Dpassword=devpassword
  12. * </pre>
  13. */
  14. public class DeveloperAutologinAuthenticationStrategy extends DefaultAuthenticationStrategy
  15. {
  16. private static final Logger log = LoggerFactory.getLogger(DeveloperAutologinAuthenticationStrategy.class);
  17.  
  18. public DeveloperAutologinAuthenticationStrategy()
  19. {
  20. super("LoggedIn");
  21. }
  22.  
  23. @Override
  24. public String[] load()
  25. {
  26. String[] result = super.load();
  27. if(result == null && Application.get().usesDevelopmentConfig())
  28. {
  29. String devUser = System.getProperty("user");
  30. String devPassword = System.getProperty("password");
  31. if(StringUtils.isNotBlank(devUser) && StringUtils.isNotBlank(devPassword))
  32. {
  33. log.info("Automatically logging in development user " + devUser);
  34. return new String[]{devUser, devPassword};
  35. }
  36. }
  37. return result;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement