org.eclipse.jetty.server.Request.getAuthentication()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(298)

本文整理了Java中org.eclipse.jetty.server.Request.getAuthentication方法的一些代码示例,展示了Request.getAuthentication的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getAuthentication方法的具体详情如下:
包路径:org.eclipse.jetty.server.Request
类名称:Request
方法名:getAuthentication

Request.getAuthentication介绍

[英]Get the authentication.
[中]获取身份验证。

代码示例

代码示例来源:origin: nz.ac.auckland.common/common-jetty8

  1. @Override
  2. public Authentication validateRequest(ServletRequest request, ServletResponse response, boolean mandatory) throws ServerAuthException {
  3. return ((Request)request).getAuthentication();
  4. }

代码示例来源:origin: works.lmz.common/common-jetty-remoteuser

  1. @Override
  2. public Authentication validateRequest(ServletRequest request, ServletResponse response, boolean mandatory) throws ServerAuthException {
  3. return ((Request)request).getAuthentication();
  4. }

代码示例来源:origin: org.ops4j.pax.web/pax-web-jetty

  1. private OsgiAuth getOsgiAuth() {
  2. OsgiAuth auth;
  3. if (request.getAuthentication() instanceof OsgiAuth) {
  4. auth = (OsgiAuth) request.getAuthentication();
  5. } else {
  6. auth = new OsgiAuth();
  7. request.setAuthentication(auth);
  8. }
  9. return auth;
  10. }

代码示例来源:origin: org.eclipse.jetty/jetty-security

  1. try
  2. Authentication authentication = baseRequest.getAuthentication();
  3. if (authentication==null || authentication==Authentication.NOT_CHECKED)
  4. authentication=authenticator==null?Authentication.UNAUTHENTICATED:authenticator.validateRequest(request, response, isAuthMandatory);
  5. Authentication auth=baseRequest.getAuthentication();
  6. if (auth instanceof Authentication.User)

代码示例来源:origin: org.graniteds/granite-server

  1. @Override
  2. public void prelogin(HttpSession session, Object httpRequest, String servletName) {
  3. if (session == null) // Cannot prelogin() without a session
  4. return;
  5. if (session.getAttribute(AuthenticationContext.class.getName()) instanceof Jetty8AuthenticationContext)
  6. return;
  7. Request request = (Request)httpRequest;
  8. Authentication authentication = request.getAuthentication();
  9. UserIdentity.Scope scope = request.getUserIdentityScope();
  10. Jetty8AuthenticationContext authorizationContext = new Jetty8AuthenticationContext(scope, authentication);
  11. session.setAttribute(AuthenticationContext.class.getName(), authorizationContext);
  12. }

代码示例来源:origin: jenkinsci/winstone

  1. /**
  2. * Extract the user authentication
  3. * @param request The request to extract from
  4. * @return The string to log for authenticated user.
  5. */
  6. protected String getAuthentication(Request request)
  7. {
  8. Authentication authentication = request.getAuthentication();
  9. if (authentication instanceof Authentication.User)
  10. return ((Authentication.User)authentication).getUserIdentity().getUserPrincipal().getName();
  11. // TODO extract the user name if it is Authentication.Deferred and return as '?username'
  12. return null;
  13. }

代码示例来源:origin: org.graniteds/granite-server

  1. Authentication authentication = request.getAuthentication();
  2. UserIdentity.Scope scope = request.getUserIdentityScope();

代码示例来源:origin: com.nitorcreations/willow-logging-jetty

  1. @Override
  2. public Principal getPrincipal() {
  3. Authentication authentication = request.getAuthentication();
  4. if (authentication instanceof Authentication.User) {
  5. return ((Authentication.User) authentication).getUserIdentity()
  6. .getUserPrincipal();
  7. }
  8. return null;
  9. }

代码示例来源:origin: org.overlord/overlord-commons-auth-jetty8

  1. Authentication authentication = jettyRequest.getAuthentication();
  2. User userAuth = (User) authentication;
  3. UserIdentity userIdentity = userAuth.getUserIdentity();

代码示例来源:origin: os-libera/OpenVirteX

  1. @Override
  2. public void handle(final String target, final Request baseRequest,
  3. final HttpServletRequest request, final HttpServletResponse response)
  4. throws IOException, ServletException {
  5. if (baseRequest.getAuthentication() == null
  6. || baseRequest.getAuthentication().equals(
  7. Authentication.UNAUTHENTICATED)) {
  8. response.sendError(Response.SC_UNAUTHORIZED, "Permission denied.");
  9. baseRequest.setHandled(true);
  10. return;
  11. }
  12. if (target.equals("/status")) {
  13. this.monitoringService.handle(request, response);
  14. } else if (target.equals("/tenant")) {
  15. this.tenantService.handle(request, response);
  16. } else if (target.equals("/admin")) {
  17. this.adminService.handle(request, response);
  18. } else {
  19. response.sendError(Response.SC_NOT_FOUND, target
  20. + " is not a service offered by OVX");
  21. }
  22. baseRequest.setHandled(true);
  23. }

代码示例来源:origin: org.gatein.wci/wci-jetty8

  1. private void _login(Request req, Response resp, Credentials credentials) throws ServletException
  2. {
  3. HttpSession session = req.getSession();
  4. if(session.getAttribute(SessionAuthentication.__J_AUTHENTICATED) == null)
  5. {
  6. synchronized (session)
  7. {
  8. if(session.getAttribute(SessionAuthentication.__J_AUTHENTICATED) == null)
  9. {
  10. req.login(credentials.getUsername(), credentials.getPassword());
  11. session.setAttribute(SessionAuthentication.__J_AUTHENTICATED, req.getAuthentication());
  12. }
  13. }
  14. }
  15. }

代码示例来源:origin: org.keycloak/keycloak-jetty-core

  1. protected Authentication register(Request request, KeycloakPrincipal<RefreshableKeycloakSecurityContext> principal) {
  2. request.setAttribute(AdapterDeploymentContext.class.getName(), deploymentContext);
  3. Authentication authentication = request.getAuthentication();
  4. if (!(authentication instanceof KeycloakAuthentication)) {
  5. UserIdentity userIdentity = createIdentity(principal);
  6. authentication = createAuthentication(userIdentity, request);
  7. request.setAuthentication(authentication);
  8. }
  9. return authentication;
  10. }

代码示例来源:origin: org.keycloak/spring-boot-container-bundle

  1. protected Authentication register(Request request, KeycloakPrincipal<RefreshableKeycloakSecurityContext> principal) {
  2. request.setAttribute(AdapterDeploymentContext.class.getName(), deploymentContext);
  3. Authentication authentication = request.getAuthentication();
  4. if (!(authentication instanceof KeycloakAuthentication)) {
  5. UserIdentity userIdentity = createIdentity(principal);
  6. authentication = createAuthentication(userIdentity, request);
  7. request.setAuthentication(authentication);
  8. }
  9. return authentication;
  10. }

代码示例来源:origin: org.overlord/overlord-commons-auth-jetty8

  1. Authentication authentication = jettyRequest.getAuthentication();
  2. User userAuth = (User) authentication;
  3. UserIdentity userIdentity = userAuth.getUserIdentity();

代码示例来源:origin: org.graniteds/granite-server

  1. public void logout() throws SecurityServiceException {
  2. ServletGraniteContext graniteContext = (ServletGraniteContext)GraniteContext.getCurrentInstance();
  3. if (graniteContext instanceof HttpGraniteContext) {
  4. Request request = (Request)graniteContext.getRequest();
  5. Authentication authentication = request.getAuthentication();
  6. if (authentication instanceof Authentication.User)
  7. ((Authentication.User)authentication).logout();
  8. if (request.getSession(false) != null) {
  9. endLogout();
  10. request.getSession(false).invalidate();
  11. }
  12. }
  13. else {
  14. HttpSession session = graniteContext.getSession();
  15. if (session != null) {
  16. AuthenticationContext authenticationContext = (AuthenticationContext)session.getAttribute(AuthenticationContext.class.getName());
  17. authenticationContext.logout();
  18. session.removeAttribute(AuthenticationContext.class.getName());
  19. endLogout();
  20. session.invalidate();
  21. }
  22. }
  23. }

代码示例来源:origin: org.graniteds/granite-server

  1. if (graniteContext instanceof HttpGraniteContext) {
  2. Request request = (Request)graniteContext.getRequest();
  3. Authentication authentication = request.getAuthentication();
  4. if (authentication instanceof Authentication.User)
  5. ((Authentication.User)authentication).logout();

代码示例来源:origin: org.graniteds/granite-server

  1. public Principal login(Object credentials, String charset) throws SecurityServiceException {
  2. String[] decoded = decodeBase64Credentials(credentials, charset);
  3. ServletGraniteContext graniteContext = (ServletGraniteContext)GraniteContext.getCurrentInstance();
  4. Principal principal = null;
  5. if (graniteContext instanceof HttpGraniteContext) {
  6. HttpServletRequest httpRequest = graniteContext.getRequest();
  7. Request request = (Request)httpRequest;
  8. Authentication authentication = request.getAuthentication();
  9. UserIdentity.Scope scope = request.getUserIdentityScope();
  10. Jetty8AuthenticationContext authenticationContext = new Jetty8AuthenticationContext(scope, authentication);
  11. principal = authenticationContext.authenticate(decoded[0], decoded[1]);
  12. if (principal != null)
  13. graniteContext.getSession().setAttribute(AuthenticationContext.class.getName(), authenticationContext);
  14. }
  15. else {
  16. AuthenticationContext authenticationContext = (AuthenticationContext)graniteContext.getSession().getAttribute(AuthenticationContext.class.getName());
  17. if (authenticationContext != null)
  18. principal = authenticationContext.authenticate(decoded[0], decoded[1]);
  19. else
  20. return null;
  21. }
  22. if (principal == null)
  23. throw SecurityServiceException.newInvalidCredentialsException("Wrong username or password");
  24. graniteContext.setPrincipal(principal);
  25. endLogin(credentials, charset);
  26. return principal;
  27. }

代码示例来源:origin: org.graniteds/granite-server

  1. public Principal login(Object credentials, String charset) throws SecurityServiceException {
  2. String[] decoded = decodeBase64Credentials(credentials, charset);
  3. ServletGraniteContext graniteContext = (ServletGraniteContext)GraniteContext.getCurrentInstance();
  4. Principal principal = null;
  5. if (graniteContext instanceof HttpGraniteContext) {
  6. HttpServletRequest httpRequest = graniteContext.getRequest();
  7. Request request = (Request)httpRequest;
  8. Authentication authentication = request.getAuthentication();
  9. UserIdentity.Scope scope = request.getUserIdentityScope();
  10. Jetty9AuthenticationContext authenticationContext = new Jetty9AuthenticationContext(scope, authentication);
  11. principal = authenticationContext.authenticate(decoded[0], decoded[1]);
  12. if (principal != null)
  13. graniteContext.getSession().setAttribute(AuthenticationContext.class.getName(), authenticationContext);
  14. }
  15. else {
  16. AuthenticationContext authenticationContext = (AuthenticationContext)graniteContext.getSession().getAttribute(AuthenticationContext.class.getName());
  17. if (authenticationContext != null)
  18. principal = authenticationContext.authenticate(decoded[0], decoded[1]);
  19. else
  20. return null;
  21. }
  22. if (principal == null)
  23. throw SecurityServiceException.newInvalidCredentialsException("Wrong username or password");
  24. graniteContext.setPrincipal(principal);
  25. endLogin(credentials, charset);
  26. return principal;
  27. }

代码示例来源:origin: jboss-fuse/fabric8

  1. @Override
  2. public void log(Request request, Response response) {
  3. try {
  4. if (!enabled) {
  5. return;
  6. }
  7. StorageService s = storage.getService();
  8. if (s == null) {
  9. return;
  10. }
  11. if (ignorePathMap != null && ignorePathMap.getMatch(request.getRequestURI()) != null)
  12. return;
  13. String output = "{ " +
  14. "\"host\": \"" + host + "\", " +
  15. "\"@timestamp\": \"" + InsightUtils.formatDate(request.getTimeStamp()) + "\", " +
  16. "\"remote\": \"" + request.getRemoteAddr() + "\", " +
  17. "\"user\": \"" + (request.getAuthentication() instanceof Authentication.User ? ((Authentication.User)request.getAuthentication()).getUserIdentity().getUserPrincipal().getName() : "") + "\", " +
  18. "\"method\": \"" + request.getMethod() + "\", " +
  19. "\"uri\": \"" + request.getUri().toString() + "\", " +
  20. "\"protocol\": \"" + request.getProtocol() + "\", " +
  21. "\"status\": \"" + response.getStatus() + "\", " +
  22. "\"responseLength\": \"" + response.getContentCount() + "\" " +
  23. " }";
  24. s.store(type, request.getTimeStamp(), output);
  25. }
  26. catch (Exception e)
  27. {
  28. LOG.warn(e);
  29. }
  30. }

代码示例来源:origin: jenkinsci/winstone

  1. Authentication authentication = request.getAuthentication();
  2. String remoteUser;
  3. if (authentication instanceof Authentication.User) {

相关文章

Request类方法