Skip to content

Instantly share code, notes, and snippets.

@agonist
Created July 24, 2014 08:07
Show Gist options
  • Save agonist/26bbf630f2200049a396 to your computer and use it in GitHub Desktop.
Save agonist/26bbf630f2200049a396 to your computer and use it in GitHub Desktop.
auth
@Component
@Provides
@Instantiate
public class MyAuthenticator implements Authenticator {
/**
* The famous {@link org.slf4j.Logger}
*/
private static final Logger logger = LoggerFactory.getLogger(MyAuthenticator.class);
@Override
public String getName() {
return "my-authenticator";
}
/**
* just check if the current user is logged in
* @param context
* @return
*/
@Override
public String getUserName(Context context) {
Subject currentUser = SecurityUtils.getSubject();
if (currentUser.isAuthenticated()) {
return currentUser.toString();
}
return null;
}
@Override
public Result onUnauthorized(Context context) {
return Results.ok("Your are not authenticated !");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment