Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import com.ibm.websphere.security.NotImplementedException;
  2. import com.ibm.wsspi.security.auth.callback.Constants;
  3. import com.ibm.wsspi.security.auth.callback.WSMappingCallbackHandlerFactory;
  4. import javax.resource.spi.security.PasswordCredential;
  5. import javax.security.auth.Subject;
  6. import javax.security.auth.callback.CallbackHandler;
  7. import javax.security.auth.login.LoginContext;
  8. import javax.security.auth.login.LoginException;
  9.  
  10. Map map = new HashMap();
  11. map.put(Constants.MAPPING_ALIAS, "REPLACE_WITH_YOUR_AUTH_ALIAS");
  12. CallbackHandler callbackHandler = null;
  13. try {
  14. callbackHandler = WSMappingCallbackHandlerFactory.getInstance().getCallbackHandler(map, null);
  15. } catch (NotImplementedException e) {
  16. }
  17.  
  18. LoginContext loginContext = null;
  19. try {
  20. loginContext = new LoginContext("DefaultPrincipalMapping", callbackHandler);
  21. loginContext.login();
  22. } catch (LoginException e) {
  23. }
  24.  
  25. Subject subject = loginContext.getSubject();
  26. Set credentials = subject.getPrivateCredentials();
  27.  
  28. PasswordCredential passwordCredential = (PasswordCredential) credentials.iterator().next();
  29.  
  30. String user = passwordCredential.getUserName();
  31. String password = new String(passwordCredential.getPassword());
  32.  
  33. response.setContentType("text/html");
  34. PrintWriter out = response.getWriter();
  35. out.println("<h1>User: " + user + " --- Password: " + password+"</h1>");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement