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


Java AuthException类代码示例

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


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

示例1: validateRequest

import javax.security.auth.message.AuthException; //导入依赖的package包/类
@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,代码行数:22,代码来源:SessionSAM.java

示例2: validateRequest

import javax.security.auth.message.AuthException; //导入依赖的package包/类
@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,代码行数:20,代码来源:GuestSAM.java

示例3: validateRequest

import javax.security.auth.message.AuthException; //导入依赖的package包/类
@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,代码行数:24,代码来源:CustomServerAuthContext.java

示例4: secureResponse

import javax.security.auth.message.AuthException; //导入依赖的package包/类
@Override
public AuthStatus secureResponse(MessageInfo messageInfo, Subject serviceSubject) throws AuthException {

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

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

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

    CustomSAM module = getModule(messageInfo);

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

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

示例5: validateRequest

import javax.security.auth.message.AuthException; //导入依赖的package包/类
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthException {

    String authorizationHeader = request.getHeader("Authorization");
    if (authorizationHeader != null && authorizationHeader.startsWith(BEARER)) {
        String token = authorizationHeader.substring(BEARER.length());

        JWTCredential credential = tokenHandler.retrieveCredential(token);

        CredentialValidationResult result = identityStore.validate(credential);

        if (result.getStatus() == VALID) {
            // Communicate the details of the authenticated user to the
            // container. In many cases the underlying handler will just store the details
            // and the container will actually handle the login after we return from
            // this method.
            return httpMessageContext.notifyContainerAboutLogin(
                    result.getCallerPrincipal(), result.getCallerGroups());
        } else {
            throw new AuthException("Login failed");
        }
    }

    return httpMessageContext.doNothing();
}
 
开发者ID:rdebusscher,项目名称:soteria-jwt,代码行数:26,代码来源:JWTAuthenticationMechanism.java

示例6: validateRequest

import javax.security.auth.message.AuthException; //导入依赖的package包/类
@Override
public AuthStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMsgContext) throws AuthException {

    String[] credentials = getCredentials(request);
    if (!isEmpty(credentials)) {

        IdentityStore identityStore = CDI.current().select(IdentityStore.class).get();

        CredentialValidationResult result = identityStore.validate(
                new UsernamePasswordCredential(credentials[0], new Password(credentials[1])));

        if (result.getStatus() == VALID) {
            return httpMsgContext.notifyContainerAboutLogin(
                    result.getCallerName(), result.getCallerGroups());
        }
    }

    if (httpMsgContext.isProtected()) {
        response.setHeader("WWW-Authenticate", basicHeaderValue);
        return httpMsgContext.responseUnAuthorized();
    }

    return httpMsgContext.doNothing();
}
 
开发者ID:rdebusscher,项目名称:octopus-jsr375,代码行数:25,代码来源:BasicAuthenticationMechanism.java

示例7: handleLoginPost

import javax.security.auth.message.AuthException; //导入依赖的package包/类
/**
 * Handles the POST method for login endpoint.
 *
 * @param req
 *            request
 * @param resp
 *            response
 * @param stateUri
 *            URI for the state
 * @param nonce
 *            nonce
 * @return {@link AuthStatus#SEND_SUCCESS}
 * @throws IOException
 *             servlet error
 * @throws ServletException
 *             servlet error
 * @throws AuthException
 *             authentication error
 */
private static AuthStatus handleLoginPost(final HttpServletRequest req,
    final HttpServletResponse resp,
    final URI stateUri,
    final String nonce) throws ServletException,
        IOException,
        AuthException {

    final HttpSession session = req.getSession(false);
    if (session == null) {
        throw new AuthException("session is required");
    }
    if (!nonce.equals(session.getAttribute(NONCE_SESSION_KEY))) {
        throw new AuthException("nonce mismatch");
    }
    final String subject = UriBuilder.fromUri("https://test-server-auth-module").userInfo(req.getParameter("j_username"))
        .build().toASCIIString();
    session.setAttribute(SUBJECT_SESSION_KEY, subject);

    // Remove nonce as it is no longer required
    session.removeAttribute(NONCE_SESSION_KEY);
    final String redirectUri = req.getContextPath() + stateUri.toASCIIString();
    resp.sendRedirect(URI.create(redirectUri).normalize().toASCIIString());
    return AuthStatus.SEND_SUCCESS;
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:44,代码来源:TestServerAuthModule.java

示例8: handleLogoutEndpoint

import javax.security.auth.message.AuthException; //导入依赖的package包/类
/**
 * Handle the logout endpoint. This will clear the cookie and redirect to
 * the URI that has been specified.
 *
 * @param req
 *            request
 * @param resp
 *            response
 * @return authentication status
 * @throws AuthException
 *             happens when there is invalid request data
 * @throws IOException
 *             servlet error
 * @throws ServletException
 *             servlet error
 */
private static AuthStatus handleLogoutEndpoint(final HttpServletRequest req,
    final HttpServletResponse resp) throws AuthException,
        ServletException,
        IOException {

    final String postLogoutRedirectUri = req.getParameter(POST_LOGOUT_REDIRECT_URI);
    if (postLogoutRedirectUri != null) {

        final String postLogoutRedirectUriNormalized = URI.create(postLogoutRedirectUri).normalize().toASCIIString();
        // Check that the post logout redirect uri is relative to the application if not fail.
        final String contextUri = URI.create(req.getRequestURL().toString()).resolve(req.getContextPath()).toASCIIString();
        if (!postLogoutRedirectUriNormalized.startsWith(contextUri)) {
            throw new AuthException("invalid post_logout_redirect_uri");
        }

        final HttpSession session = req.getSession(false);
        if (session != null) {
            session.removeAttribute(SUBJECT_SESSION_KEY);
            session.removeAttribute(NONCE_SESSION_KEY);
        }
        resp.sendRedirect(postLogoutRedirectUriNormalized);
        return AuthStatus.SEND_SUCCESS;
    }
    throw new AuthException("missing post_logout_redirect_uri");
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:42,代码来源:TestServerAuthModule.java

示例9: validateStateUri

import javax.security.auth.message.AuthException; //导入依赖的package包/类
/**
 * Validates the state URI. It ensures that it is:
 * <ul>
 * <li>an absolute URI, no <code>http:</code> or any other scheme
 * definition.
 * <li>It has no host component.
 * <li>Path must start with <code>/</code>
 * <li>Path must not contain <code>/..</code>
 * </ul>
 *
 * @param stateUri
 *            URI to evaluate
 * @throws AuthException
 *             validation failure
 */
private static void validateStateUri(final URI stateUri) throws AuthException {

    if (stateUri.isAbsolute()) {
        throw new AuthException("'state' must not be an absolute URI");
    }
    if (stateUri.getHost() != null) {
        throw new AuthException("'state' must not have a host component");
    }
    if (!stateUri.getPath().startsWith("/")) {
        throw new AuthException("'state' must start with '/'");
    }
    if (stateUri.getPath().contains("/..")) {
        throw new AuthException("'state' must not resolve to a parent path");
    }
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:31,代码来源:TestServerAuthModule.java

示例10: cleanSubject

import javax.security.auth.message.AuthException; //导入依赖的package包/类
/**
 * Removes the <code>authenticated</code> group and the user ID from the
 * principal set.
 *
 * @param messageInfo
 *            message info
 * @param subject
 *            subject
 */
@Override
public void cleanSubject(final MessageInfo messageInfo,
    final Subject subject) throws AuthException {

    final HttpServletRequest req = (HttpServletRequest) messageInfo.getRequestMessage();
    final String subjectCookie = getSubject(req);

    final Iterator<Principal> iterator = subject.getPrincipals().iterator();
    while (iterator.hasNext()) {
        final Principal principal = iterator.next();
        if ("authenticated".equals(principal.getName())) {
            iterator.remove();
        }
        if (principal.getName().equals(subjectCookie)) {
            iterator.remove();
        }
    }
    // Does nothing.
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:29,代码来源:TestServerAuthModule.java

示例11: handleLogoutEndpoint

import javax.security.auth.message.AuthException; //导入依赖的package包/类
/**
 * Handle the logout endpoint. This will clear the cookie and redirect to
 * the URI that has been specified.
 *
 * @param req
 *            request
 * @param resp
 *            response
 * @return authentication status
 * @throws AuthException
 *             happens when there is invalid request data
 * @throws IOException
 *             servlet error
 * @throws ServletException
 *             servlet error
 */
private static AuthStatus handleLogoutEndpoint(final HttpServletRequest req,
    final HttpServletResponse resp) throws AuthException,
        ServletException,
        IOException {

    final String postLogoutRedirectUri = req.getParameter(POST_LOGOUT_REDIRECT_URI);
    if (postLogoutRedirectUri != null) {

        final String postLogoutRedirectUriNormalized = URI.create(postLogoutRedirectUri).normalize().toASCIIString();
        // Check that the post logout redirect uri is relative to the application if not fail.
        final String contextUri = URI.create(req.getRequestURL().toString()).resolve(req.getContextPath()).toASCIIString();
        if (!postLogoutRedirectUriNormalized.startsWith(contextUri)) {
            throw new AuthException("invalid post_logout_redirect_uri");
        }

        final Cookie cookie = new Cookie(SUBJECT_COOKIE_KEY, "");
        cookie.setMaxAge(0);
        cookie.setSecure(true);
        resp.addCookie(cookie);
        resp.sendRedirect(postLogoutRedirectUriNormalized);
        return AuthStatus.SEND_SUCCESS;
    }
    throw new AuthException("missing post_logout_redirect_uri");
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:41,代码来源:TestServerAuthModule.java

示例12: handleRedirectToLoginEndpoint

import javax.security.auth.message.AuthException; //导入依赖的package包/类
/**
 * Builds the redirect URI including the assembly of <code>state</code>.
 *
 * @param req
 *            servlet request
 * @param resp
 *            servlet response
 * @return {@link AuthStatus#SEND_SUCCESS}
 * @throws AuthException
 *             happens when there is invalid request data
 * @throws IOException
 *             servlet error
 * @throws ServletException
 *             servlet error
 */
private static AuthStatus handleRedirectToLoginEndpoint(final HttpServletRequest req,
    final HttpServletResponse resp) throws AuthException,
        ServletException,
        IOException {

    if (!"GET".equals(req.getMethod())) {
        throw new AuthException("Only 'GET' method is supported when redirecting to the endpoint");
    }
    final StringBuilder stateBuilder = new StringBuilder(req.getRequestURI().substring(req.getContextPath().length()));
    if (req.getQueryString() != null) {
        stateBuilder.append('?');
        stateBuilder.append(req.getQueryString());
    }
    final StringBuilder redirectUriBuilder = new StringBuilder(req.getContextPath());
    redirectUriBuilder.append(LOGIN_ENDPOINT);
    redirectUriBuilder.append("?state=");
    redirectUriBuilder.append(
        URLEncoder.encode(stateBuilder.toString(), "US-ASCII"));
    resp.sendRedirect(URI.create(redirectUriBuilder.toString()).normalize().toASCIIString());

    // The JASPIC spec is ambiguous for this scenario, however
    // SEND_SUCCESS works on the top three application servers.

    return AuthStatus.SEND_SUCCESS;
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:41,代码来源:TestServerAuthModule.java

示例13: getAuthContext

import javax.security.auth.message.AuthException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Augments the options with the properties specified and initializes the
 * module as mandatory or non-mandatory depending on whether the
 * authContextID is <code>null</code>.
 * </p>
 */
@Override
public ServerAuthContext getAuthContext(final String authContextID,
    final Subject serviceSubject,
    @SuppressWarnings("rawtypes") final Map properties) throws AuthException {

    @SuppressWarnings("rawtypes")
    final Map augmentedOptions = augmentProperties(properties);
    final TestServerAuthModule context = new TestServerAuthModule();

    if (authContextID == null) {
        context.initialize(NON_MANDATORY, NON_MANDATORY, handler, augmentedOptions);
    } else {
        context.initialize(MANDATORY, MANDATORY, handler, augmentedOptions);
    }
    return context;
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:25,代码来源:TestServerAuthModuleAuthConfig.java

示例14: testFailLoginInvalidMethod

import javax.security.auth.message.AuthException; //导入依赖的package包/类
/**
 * Tests the login endpoint PUT operation.
 */
@Test(expected = AuthException.class)
public void testFailLoginInvalidMethod() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("PUT");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(servletRequest.getParameter("state")).thenReturn("/rooted/page");
    when(servletRequest.getParameter("nonce")).thenReturn("abc");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    module.validateRequest(messageInfo, client, null);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:28,代码来源:TestServerAuthModuleTest.java

示例15: testFailLoginInvalidState

import javax.security.auth.message.AuthException; //导入依赖的package包/类
/**
 * Tests the login endpoint GET operation.
 */
@Test(expected = AuthException.class)
public void testFailLoginInvalidState() throws Exception {

    final TestServerAuthModule module = new TestServerAuthModule();
    final MessagePolicy mockRequestPolicy = mock(MessagePolicy.class);
    when(mockRequestPolicy.isMandatory()).thenReturn(true);

    final CallbackHandler h = mock(CallbackHandler.class);
    module.initialize(mockRequestPolicy, null, h, options);

    final MessageInfo messageInfo = mock(MessageInfo.class);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getMethod()).thenReturn("GET");
    when(servletRequest.isSecure()).thenReturn(true);
    when(servletRequest.getRequestURI()).thenReturn("/util/j_security_check");
    when(servletRequest.getContextPath()).thenReturn("/util");
    when(servletRequest.getParameter("state")).thenReturn("http://www.trajano.net/");
    when(messageInfo.getRequestMessage()).thenReturn(servletRequest);

    final Subject client = new Subject();
    module.validateRequest(messageInfo, client, null);
}
 
开发者ID:trajano,项目名称:jaspic-tester,代码行数:27,代码来源:TestServerAuthModuleTest.java


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