当前位置: 首页>>代码示例>>Java>>正文


Java AuthStatus.SUCCESS属性代码示例

本文整理汇总了Java中javax.security.auth.message.AuthStatus.SUCCESS属性的典型用法代码示例。如果您正苦于以下问题:Java AuthStatus.SUCCESS属性的具体用法?Java AuthStatus.SUCCESS怎么用?Java AuthStatus.SUCCESS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.security.auth.message.AuthStatus的用法示例。


在下文中一共展示了AuthStatus.SUCCESS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateRequest

@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI());

    String login = (String) request.getSession().getAttribute("login");
    String groups = (String) request.getSession().getAttribute("groups");

    CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, login);
    GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{groups});
    Callback[] callbacks = new Callback[]{callerPrincipalCallback, groupPrincipalCallback};

    try {
        callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new AuthException(e.getMessage());
    }

    return AuthStatus.SUCCESS;
}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:21,代码来源:SessionSAM.java

示例2: validateRequest

@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI());

    CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, "");
    GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{UserGroupMapping.GUEST_ROLE_ID});
    Callback[] callbacks = {callerPrincipalCallback, groupPrincipalCallback};

    try {
        callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new AuthException(e.getMessage());
    }

    return AuthStatus.SUCCESS;

}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:19,代码来源:GuestSAM.java

示例3: validateRequest

@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage();
    AuthServices.addCORSHeaders(response);

    LOGGER.log(Level.FINE, "validateRequest @" + request.getMethod() + " " + request.getRequestURI());

    if (isOptionsRequest(request)) {
        return AuthStatus.SUCCESS;
    }

    CustomSAM module = getModule(messageInfo);

    if (module != null) {
        return module.validateRequest(messageInfo, clientSubject, serviceSubject);
    }

    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

    return AuthStatus.FAILURE;
}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:23,代码来源:CustomServerAuthContext.java

示例4: validateRequest

@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage();

    LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI());

    String authorization = request.getHeader("Authorization");
    String[] splitAuthorization = authorization.split(" ");
    String jwt = splitAuthorization[1];

    JWTokenUserGroupMapping jwTokenUserGroupMapping = JWTokenFactory.validateAuthToken(key, jwt);

    if (jwTokenUserGroupMapping != null) {

        UserGroupMapping userGroupMapping = jwTokenUserGroupMapping.getUserGroupMapping();
        CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, userGroupMapping.getLogin());
        GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{userGroupMapping.getGroupName()});
        Callback[] callbacks = new Callback[]{callerPrincipalCallback, groupPrincipalCallback};

        try {
            callbackHandler.handle(callbacks);
        } catch (IOException | UnsupportedCallbackException e) {
            throw new AuthException(e.getMessage());
        }

        JWTokenFactory.refreshTokenIfNeeded(key, response, jwTokenUserGroupMapping);

        return AuthStatus.SUCCESS;
    }

    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    return AuthStatus.FAILURE;

}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:36,代码来源:JWTSAM.java

示例5: validateRequest

/**
 * This method delegates to a login module if configured in the module options.
 * The sub classes will need to validate the request 
 */
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, 
      Subject serviceSubject) 
throws AuthException
{
   String loginModuleName = (String) options.get("login-module-delegate");
   if(loginModuleName != null)
   {
      ClassLoader tcl = SecurityActions.getContextClassLoader();
      try
      {
         Class clazz = tcl.loadClass(loginModuleName);
         LoginModule lm = (LoginModule) clazz.newInstance();
         lm.initialize(clientSubject, callbackHandler, new HashMap(), options);
         lm.login();
         lm.commit();
      }
      catch (Exception e)
      {
         throw new AuthException(e.getLocalizedMessage());
      }
   } 
   else
   {
      return validate(clientSubject, messageInfo) ? AuthStatus.SUCCESS : AuthStatus.FAILURE;
   } 
   
   return AuthStatus.SUCCESS;
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:32,代码来源:AbstractServerAuthModule.java

示例6: secureRequest

/**
 * @see ClientAuthModule#secureRequest(javax.security.auth.message.MessageInfo, javax.security.auth.Subject)
 */
public AuthStatus secureRequest(MessageInfo param, Subject source) 
throws AuthException
{ 
   source.getPrincipals().add(this.principal);
   source.getPublicCredentials().add(this.credential);
   return AuthStatus.SUCCESS;
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:10,代码来源:SimpleClientAuthModule.java

示例7: validateResponse

/**
 * @see ClientAuthModule#validateResponse(javax.security.auth.message.MessageInfo, javax.security.auth.Subject, javax.security.auth.Subject)
 */
public AuthStatus validateResponse(MessageInfo messageInfo, Subject source, Subject recipient) throws AuthException
{  
   //Custom check: Check that the source of the response and the recipient
   // of the response have identical credentials
   Set sourceSet = source.getPrincipals(SimplePrincipal.class);
   Set recipientSet = recipient.getPrincipals(SimplePrincipal.class);
   if(sourceSet == null && recipientSet == null)
      throw new AuthException();
   if(sourceSet.size() != recipientSet.size())
      throw new AuthException(PicketBoxMessages.MESSAGES.sizeMismatchMessage("source", "recipient"));
   return AuthStatus.SUCCESS;
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:15,代码来源:SimpleClientAuthModule.java

示例8: validateRequest

@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject)
    throws AuthException {
  _logger.debug("Enter validateRequest");

  if (!requiresAuthentication(messageInfo)) {
    _logger.debug("Returning success, auth policy not mandatory");
    return AuthStatus.SUCCESS;
  }

  HttpServletRequest req = (HttpServletRequest) messageInfo.getRequestMessage();
  HttpServletResponse resp = (HttpServletResponse) messageInfo.getResponseMessage();

  try {
    UserAccount account = (UserAccount) req.getSession().getAttribute(USER_ACCOUNT_SESSION_KEY);
    if (account != null) {
      _logger.debug("Returning success, user already logged in");
      addPrincipalsToSubject(clientSubject, account);
      return AuthStatus.SUCCESS;
    }

    if (!req.getRequestURI().endsWith(LOGIN_PAGE)) {
      redirectToLoginPage(req, resp);
      return AuthStatus.SEND_CONTINUE;
    }

    if ("GET".equals(req.getMethod())) {
      forwardToLoginPage(req, resp, "GET request");
      return AuthStatus.SEND_CONTINUE;
    }

    String userName = req.getParameter("j_username");
    String password = req.getParameter("j_password");
    String otp = req.getParameter("j_otp");

    if (userName == null || password == null || otp == null) {
      _logger.debug("Returning failure, missing request parameter(s)");
      forwardToFailedLoginPage(req, resp, null);
      return AuthStatus.SEND_CONTINUE;
    }

    UserAccount userAccount = _accountMap.get(userName);
    if (userAccount != null
        && userAccount.getHashedPassword().equals(
            PasswordEncoder.encodePasswordForUser(userName, userAccount.getSalt(), password))
        && YubicoClient.isValidOTPFormat(otp)) {
      _logger.debug("Verifying Yubikey for {}...", userName);
      VerificationResponse response = _yubicoClient.verify(otp);
      if (response.isOk()) {
        if (response.getPublicId().equals(userAccount.getPublicYubiId())) {
          addPrincipalsToSubject(clientSubject, userAccount);
          req.getSession().setAttribute(USER_ACCOUNT_SESSION_KEY, userAccount);

          String originalUri = (String) req.getSession().getAttribute(ORIGINAL_URI_SESSION_KEY);
          if (originalUri != null) {
            _logger.debug("Login successful for {}, redirecting to {}", userName, originalUri);
            resp.sendRedirect(originalUri);
            return AuthStatus.SEND_CONTINUE;
          } else {
            _logger.debug("Login successful for {}, returning success", userName);
            return AuthStatus.SUCCESS;
          }
        } else {
          _logger.warn("Login attempt for {} with wrong Yubikey {}!", userName, response.getPublicId());
        }
      } else {
        _logger.info("Failed to verify Yubikey for {}, response not OK", userName);
      }
    }

    forwardToFailedLoginPage(req, resp, "authentication failed");
    return AuthStatus.SEND_CONTINUE;
  } catch (Exception e) {
    _logger.error("Authentication failed with exception", e);
    throw new AuthException(e.getMessage());
  }
}
 
开发者ID:erik-wramner,项目名称:YubikeyAuth,代码行数:77,代码来源:YubiAuthModule.java

示例9: validateRequest

@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException
{
   return AuthStatus.SUCCESS;
}
 
开发者ID:jbossws,项目名称:jbossws-cxf,代码行数:5,代码来源:UsernameTokenServerAuthModule.java

示例10: secureResponse

public AuthStatus secureResponse(MessageInfo messageInfo, Subject arg1) throws AuthException
{
   return AuthStatus.SUCCESS;
}
 
开发者ID:jbossws,项目名称:jbossws-cxf,代码行数:4,代码来源:UsernameTokenServerAuthModule.java

示例11: secureRequest

public AuthStatus secureRequest(MessageInfo messageInfo, Subject source) throws AuthException
{
   log = "secureRequest";
   return AuthStatus.SUCCESS;
}
 
开发者ID:jbossws,项目名称:jbossws-cxf,代码行数:5,代码来源:SOAPClientAuthModule.java

示例12: validateResponse

public AuthStatus validateResponse(MessageInfo messageInfo, Subject source, Subject recipient) throws AuthException
{
   return AuthStatus.SUCCESS;
}
 
开发者ID:jbossws,项目名称:jbossws-cxf,代码行数:4,代码来源:SOAPClientAuthModule.java

示例13: validateRequest

/**
 * <p>
 * Checks for the presence of the cookie, if it is present it will use that
 * as the subject if not it will redirect to a login screen.
 * </p>
 * {@inheritDoc}
 */
@Override
public AuthStatus validateRequest(final MessageInfo messageInfo,
    final Subject client,
    final Subject serviceSubject)
        throws AuthException {

    final HttpServletRequest req = (HttpServletRequest) messageInfo.getRequestMessage();
    final HttpServletResponse resp = (HttpServletResponse) messageInfo.getResponseMessage();
    try {

        final String localRequestUri = req.getRequestURI().substring(req.getContextPath().length());

        if (LOGIN_ENDPOINT.equals(localRequestUri)) {
            return handleLoginEndpoint(req, resp);
        }

        if (LOGOUT_ENDPOINT.equals(localRequestUri)) {
            return handleLogoutEndpoint(req, resp);
        }

        // Allow if authentication is not required.
        if (!mandatory) {
            return AuthStatus.SUCCESS;
        }

        // require SSL if mandatory
        if (!req.isSecure()) {
            resp.sendError(HttpURLConnection.HTTP_FORBIDDEN, "SSL Required");
            return AuthStatus.SEND_FAILURE;
        }

        final String subject = getSubject(req);

        // Check if there is no subject then redirect to login endpoint
        if (subject == null) {
            return handleRedirectToLoginEndpoint(req, resp);
        }

        handler.handle(new Callback[] {
            new CallerPrincipalCallback(client, subject),
            new GroupPrincipalCallback(client, GROUPS)
        });
        return AuthStatus.SUCCESS;

    } catch (final IOException
        | ServletException
        | UnsupportedCallbackException e) {
        LOG.throwing(TestServerAuthModule.class.getName(), "validateRequest", e);
        throw new AuthException(e.getMessage());
    }
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:58,代码来源:TestServerAuthModule.java

示例14: validateRequest

@Override
public AuthStatus validateRequest(final ValidateContext context) throws IOException {

    return AuthStatus.SUCCESS;
}
 
开发者ID:trajano,项目名称:openid-connect,代码行数:5,代码来源:SecurityAssertionPassedRequestProcessor.java

示例15: invokeModules

private AuthStatus invokeModules(MessageInfo messageInfo,
      Subject clientSubject, Subject serviceSubject) 
throws AuthException
{
   //Control Flag behavior
   boolean encounteredRequiredError = false; 
   boolean encounteredOptionalError = false; 
   AuthException moduleException = null;
   AuthStatus overallDecision = AuthStatus.FAILURE;
   
   int length = modules.size();
   for(int i = 0; i < length; i++)
   {
      ServerAuthModule module = (ServerAuthModule)modules.get(i);
      ControlFlag flag = (ControlFlag)this.controlFlags.get(i); 
      AuthStatus decision = AuthStatus.FAILURE;
      try
      {
         decision = module.validateRequest(messageInfo, clientSubject, serviceSubject);
      }
      catch(Exception ae)
      { 
         decision = AuthStatus.FAILURE;
         if(moduleException == null)
            moduleException = new AuthException(ae.getMessage());
      }
      
      if(decision == AuthStatus.SUCCESS)
      { 
         overallDecision =  AuthStatus.SUCCESS;
         //SUFFICIENT case
         if(flag == ControlFlag.SUFFICIENT && encounteredRequiredError == false)
            return AuthStatus.SUCCESS;
         continue; //Continue with the other modules
      }
      //Go through the failure cases 
      //REQUISITE case
      if(flag == ControlFlag.REQUISITE)
      {
         if(moduleException == null)
            moduleException = new AuthException(PicketBoxMessages.MESSAGES.authenticationFailedMessage());
         else
            throw moduleException;
      }
      //REQUIRED Case
      if(flag == ControlFlag.REQUIRED)
      {
         if(encounteredRequiredError == false)
            encounteredRequiredError = true;
      }
      if(flag == ControlFlag.OPTIONAL)
         encounteredOptionalError = true; 
   }
   
   //All the authorization modules have been visited.
   String msg = getAdditionalErrorMessage(moduleException);
   if(encounteredRequiredError)
      throw new AuthException(PicketBoxMessages.MESSAGES.authenticationFailedMessage() + msg);
   if(overallDecision == AuthStatus.FAILURE && encounteredOptionalError)
      throw new AuthException(PicketBoxMessages.MESSAGES.authenticationFailedMessage() + msg);
   if(overallDecision == AuthStatus.FAILURE)
      throw new AuthException(PicketBoxMessages.MESSAGES.authenticationFailedMessage());
   return AuthStatus.SUCCESS;
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:64,代码来源:JBossServerAuthContext.java


注:本文中的javax.security.auth.message.AuthStatus.SUCCESS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。