use of com.authlete.common.types.User in project java-oauth-server by authlete.
the class AuthorizationDecisionEndpoint method post.
/**
* Process a request from the form in the authorization page.
*
* <p>
* NOTE:
* A better implementation would re-display the authorization page
* when the pair of login ID and password is wrong, but this
* implementation does not do it for brevity. A much better
* implementation would check the login credentials by Ajax.
* </p>
*
* @param request
* A request from the form in the authorization page.
*
* @param parameters
* Request parameters.
*
* @return
* A response to the user agent. Basically, the response
* will trigger redirection to the client's redirect
* endpoint.
*/
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response post(@Context HttpServletRequest request, MultivaluedMap<String, String> parameters) {
// Get the existing session.
HttpSession session = getSession(request);
// Retrieve some variables from the session. See the implementation
// of AuthorizationRequestHandlerSpiImpl.getAuthorizationPage().
Params params = (Params) takeAttribute(session, "params");
String[] acrs = (String[]) takeAttribute(session, "acrs");
Client client = (Client) takeAttribute(session, "client");
User user = getUser(session, parameters);
Date authTime = (Date) session.getAttribute("authTime");
// Implementation of AuthorizationDecisionHandlerSpi.
AuthorizationDecisionHandlerSpi spi = new AuthorizationDecisionHandlerSpiImpl(parameters, user, authTime, params.getIdTokenClaims(), acrs, client);
// Handle the end-user's decision.
return handle(AuthleteApiFactory.getDefaultApi(), spi, params);
}
use of com.authlete.common.types.User in project java-oauth-server by authlete.
the class AuthorizationDecisionEndpoint method getUser.
/**
* Look up an end-user.
*/
private static User getUser(HttpSession session, MultivaluedMap<String, String> parameters) {
// Look up the user in the session to see if they're already logged in.
User sessionUser = (User) session.getAttribute("user");
if (sessionUser != null) {
return sessionUser;
}
// Look up an end-user who has the login credentials.
User loginUser = UserDao.getByCredentials(parameters.getFirst("loginId"), parameters.getFirst("password"));
if (loginUser != null) {
session.setAttribute("user", loginUser);
session.setAttribute("authTime", new Date());
}
return loginUser;
}
use of com.authlete.common.types.User in project java-oauth-server by authlete.
the class FederationEndpoint method callback.
@GET
@Path("callback/{federationId}")
public Response callback(@Context HttpServletRequest req, @PathParam("federationId") String federationId) {
// Authentication response from the OpenID Provider.
URI authenticationResponse = getFullUri(req);
// Get the Federation instance that corresponds to the federation ID.
Federation federation = getFederation(federationId);
// Data used to render the authorization page.
AuthzPageModel model = getAuthzPageModel(req);
// "state" and "code_verifier" which were generated in initiation().
String state = takeFromSession(req, KEY_STATE);
String verifier = takeFromSession(req, KEY_VERIFIER);
// Ensure that 'state' is available.
ensureState(state);
// Communicate with the OpenID Provider to get information about the user.
UserInfo userInfo = getUserInfo(federation, authenticationResponse, state, verifier, model);
// Register the user into this server (or overwrite the existing info).
User user = registerUser(federation, userInfo);
// Make the user login.
makeUserLogin(req, user);
// Go back to the authorization page.
return authorizationPage(model, user, null);
}
use of com.authlete.common.types.User in project java-oauth-server by authlete.
the class DeviceVerificationEndpoint method authenticateUser.
private void authenticateUser(HttpSession session, MultivaluedMap<String, String> parameters) {
// Look up the user in the session to see if they're already logged in.
User sessionUser = (User) session.getAttribute("user");
if (sessionUser != null) {
// OK. The user has been already authenticated.
return;
}
// The user has not been authenticated yet. Then, check the user credentials
// in the submitted parameters
// Look up an end-user who has the login credentials.
User loginUser = UserDao.getByCredentials(parameters.getFirst("loginId"), parameters.getFirst("password"));
if (loginUser != null) {
// OK. The user having the credentials was found.
// Set the login information about the user in the session.
session.setAttribute("user", loginUser);
session.setAttribute("authTime", new Date());
return;
}
// Error. The user authentication has failed.
// Urge the user to input valid login credentials again.
// The model for rendering the verification page.
DeviceVerificationPageModel model = new DeviceVerificationPageModel().setLoginId(parameters.getFirst("loginId")).setUserCode(parameters.getFirst("userCode")).setNotification("User authentication failed.");
// Throw a "401 Unauthorized" exception and show the verification page.
throw unauthorizedException(new Viewable(TEMPLATE, model), CHALLENGE);
}
use of com.authlete.common.types.User in project java-oauth-server by authlete.
the class DeviceVerificationEndpoint method get.
/**
* The verification endpoint for {@code GET} method. This method returns a
* verification page where the end-user is asked to input her login credentials
* (if not authenticated) and a user code.
*/
@GET
public Response get(@Context HttpServletRequest request, @Context UriInfo uriInfo) {
// Get user information from the existing session if present.
User user = getUserFromSessionIfPresent(request);
// Get the user code from the query parameters if present.
String userCode = uriInfo.getQueryParameters().getFirst("user_code");
// The model for rendering the verification page.
DeviceVerificationPageModel model = new DeviceVerificationPageModel().setUser(user).setUserCode(userCode);
// Create a response of "200 OK" having the verification page.
return ok(new Viewable(TEMPLATE, model));
}
Aggregations