Java Code Examples for javax.security.enterprise.identitystore.CredentialValidationResult#getStatus()
The following examples show how to use
javax.security.enterprise.identitystore.CredentialValidationResult#getStatus() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleAuthenticationMechanism.java From thorntail with Apache License 2.0 | 6 votes |
@Override public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthenticationException { String name = request.getParameter("name"); Password password = new Password(request.getParameter("password")); // Delegate the {credentials in -> identity data out} function to // the Identity Store CredentialValidationResult result = identityStoreHandler.validate( new UsernamePasswordCredential(name, password)); 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()); } return httpMessageContext.responseUnauthorized(); }
Example 2
Source File: SimpleAuthenticationMechanism.java From thorntail with Apache License 2.0 | 6 votes |
@Override public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthenticationException { String name = request.getParameter("name"); Password password = new Password(request.getParameter("password")); // Delegate the {credentials in -> identity data out} function to // the Identity Store CredentialValidationResult result = identityStoreHandler.validate( new UsernamePasswordCredential(name, password)); 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()); } return httpMessageContext.responseUnauthorized(); }
Example 3
Source File: IdentityStoreLoginHandler.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public AuthenticatedIdentity login(HttpServletRequest request, String username, String password) { CredentialValidationResult result = CDI.current() .select(IdentityStoreHandler.class) .get() .validate(new UsernamePasswordCredential(username, new Password(password))); if (result.getStatus() == VALID) { return new DefaultAuthenticatedIdentity(result.getCallerPrincipal(), result.getCallerGroups()); } return null; }
Example 4
Source File: LiteAuthenticationMechanism.java From Java-EE-8-Sampler with MIT License | 5 votes |
@Override public AuthenticationStatus validateRequest(HttpServletRequest req, HttpServletResponse res, HttpMessageContext context) { CredentialValidationResult result = idStoreHandler.validate( new UsernamePasswordCredential( req.getParameter("name"), req.getParameter("password"))); if (result.getStatus() == VALID) { return context.notifyContainerAboutLogin(result); } else { return context.responseUnauthorized(); } }
Example 5
Source File: JwtAuthenticationMechanism.java From javaee8-jaxrs-sample with GNU General Public License v3.0 | 5 votes |
@Override public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext context) { LOGGER.log(Level.INFO, "validateRequest: {0}", request.getRequestURI()); // Get the (caller) name and password from the request // NOTE: This is for the smallest possible example only. In practice // putting the password in a request query parameter is highly insecure String name = request.getParameter("username"); String password = request.getParameter("password"); String token = extractToken(context); if (name != null && password != null && "POST".equals(request.getMethod()) && request.getRequestURI().endsWith("/auth/login")) { LOGGER.log(Level.INFO, "user credentials : {0}, {1}", new String[]{name, password}); // validation of the credential using the identity store CredentialValidationResult result = identityStoreHandler.validate(new UsernamePasswordCredential(name, password)); if (result.getStatus() == CredentialValidationResult.Status.VALID) { // Communicate the details of the authenticated user to the container and return SUCCESS. return createToken(result, context); } // if the authentication failed, we return the unauthorized status in the http response return context.responseUnauthorized(); } else if (token != null) { // validation of the jwt credential return validateToken(token, context); } else if (context.isProtected()) { // A protected resource is a resource for which a constraint has been defined. // if there are no credentials and the resource is protected, we response with unauthorized status return context.responseUnauthorized(); } // there are no credentials AND the resource is not protected, // SO Instructs the container to "do nothing" return context.doNothing(); }
Example 6
Source File: TestAuthenticationMechanism.java From ee8-sandbox with Apache License 2.0 | 5 votes |
@Override public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthenticationException { final String name = request.getParameter("name"); final String pwd = request.getParameter("password"); if (name != null && pwd != null ) { // Get the (caller) name and password from the request // NOTE: This is for the smallest possible example only. In practice // putting the password in a request query parameter is highly // insecure Password password = new Password(pwd); // Delegate the {credentials in -> identity data out} function to // the Identity Store CredentialValidationResult result = identityStoreHandler.validate( new UsernamePasswordCredential(name, password)); 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()); } return httpMessageContext.responseUnauthorized(); } return httpMessageContext.doNothing(); }
Example 7
Source File: TestAuthenticationMechanism.java From ee8-sandbox with Apache License 2.0 | 5 votes |
@Override public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthenticationException { final String name = request.getParameter("name"); final String pwd = request.getParameter("password"); if (name != null && pwd != null ) { // Get the (caller) name and password from the request // NOTE: This is for the smallest possible example only. In practice // putting the password in a request query parameter is highly // insecure Password password = new Password(pwd); // Delegate the {credentials in -> identity data out} function to // the Identity Store CredentialValidationResult result = identityStoreHandler.validate( new UsernamePasswordCredential(name, password)); 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()); } return httpMessageContext.responseUnauthorized(); } return httpMessageContext.doNothing(); }