final boolean isAdmin = roles.contains(RestletUtilRoles.ADMIN.getRole()); dataModel.put("isAdmin", isAdmin); dataModel.put("currentUser", nextClientInfo.getUser()); dataModel.put("pageUrl", nextRequest.getOriginalRef().toString(false, false)); final User currentUser = nextClientInfo.getUser(); if(currentUser != null)
protected Client getAuthenticatedClient() throws OAuthException { User authenticatedClient = getRequest().getClientInfo().getUser(); if (authenticatedClient == null) { getLogger().warning("Authenticated client_id is missing."); return null; } // XXX: We 'know' the client was authenticated before, 'client' should // not be null. Client client = clients.findById(authenticatedClient.getIdentifier()); getLogger().fine( "Requested by authenticated client " + client.getClientId()); return client; }
protected static Client getAuthenticatedClient() throws OAuthException { User authenticatedClient = getRequest().getClientInfo().getUser(); if (authenticatedClient == null) { getLogger().warning("Authenticated client_id is missing."); return null; } // XXX: We 'know' the client was authenticated before, 'client' should // not be null. Client client = clients.findById(authenticatedClient.getIdentifier()); getLogger().fine( "Requested by authenticated client " + client.getClientId()); return client; }
public void enrole(ClientInfo clientInfo) { User user = findUser(clientInfo.getUser().getIdentifier()); if (user != null) { // Find all the inherited groups of this user Set<Group> userGroups = findGroups(user); // Add roles specific to this user Set<Role> userRoles = findRoles(user); for (Role role : userRoles) { clientInfo.getRoles().add(role); } // Add roles common to group members Set<Role> groupRoles = findRoles(userGroups); for (Role role : groupRoles) { clientInfo.getRoles().add(role); } } } }
@Get("json") public Representation getUserStatus() throws JSONException { User user = getRequest().getClientInfo().getUser(); getLogger().info("getUserStatus: " + user.getIdentifier()); SampleUser sampleUser = OAuth2Sample.getSampleUserManager() .findUserById(user.getIdentifier()); if (sampleUser == null) { setStatus(Status.CLIENT_ERROR_BAD_REQUEST); return null; } JSONObject result = new JSONObject(); Object status = sampleUser.getStatus(); if (status != null) { result.put("status", status); } else { result.put("status", ""); } return new JsonRepresentation(result); }
@Put("json") public Representation updateUserStatus(Representation representation) throws IOException, JSONException { JSONObject request = new JsonRepresentation(representation) .getJsonObject(); Object status = request.get("status"); if (status == null) { setStatus(Status.CLIENT_ERROR_BAD_REQUEST); return null; } User user = getRequest().getClientInfo().getUser(); getLogger().info("updateUserStatus: " + user.getIdentifier()); SampleUser sampleUser = OAuth2Sample.getSampleUserManager() .findUserById(user.getIdentifier()); if (sampleUser != null) { sampleUser.setStatus(status.toString()); } JSONObject result = new JSONObject(); result.put("status", status); return new JsonRepresentation(result); } }
@Override public void enrole(final ClientInfo clientInfo) final RestletUtilUser user = RestletUtilSesameRealm.this.findUser(clientInfo.getUser().getIdentifier());
@Override public void enrole(final ClientInfo clientInfo) final User user = RestletUtilMemoryRealm.this.findUser(clientInfo.getUser().getIdentifier());
private void checkUpdateUserAuthentication(String usernameString) throws ResourceException { if(this.getRequest().getClientInfo().isAuthenticated()) { if(this.getRequest().getClientInfo().getUser().getIdentifier().equals(usernameString)) { // Always allow users to update their own information return; } } // Check for user create permission if the update would be on another user this.checkAuthentication(BaseOasActions.USER_CREATE); // For system safety, all user updates must be authenticated, even if the // OasAction.USER_CREATE is setup to allow users to register themselves into the system if(!this.getRequest().getClientInfo().isAuthenticated()) { this.log.error("User was not authenticated"); throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "Only authenticated users can update user details"); } }
@Get public Representation getIndexPageHtml(final Representation entity) throws ResourceException { this.checkAuthentication(BaseOasActions.WHOAMI_CHECK); Representation result = null; if(this.getRequest().getClientInfo().isAuthenticated()) { result = new StringRepresentation(this.getRequest().getClientInfo().getUser().getIdentifier()); } return result; }
this.log.warn("Authenticated user did not have any roles: user={}", request.getClientInfo().getUser());
/** * Generates a CallLog for the request and adds it to the buffer. * * @param request * The Request object associated with the request. * @param response * The Response object associated with the request. * @param duration * The duration of the request in milliseconds. * @param startTime * The time at which the request arrived to the agent as an * epoch. */ public void addCallLogToBuffer(Request request, Response response, int duration, long startTime) { CallLog callLog = new CallLog(); callLog.setDate(new Date(startTime)); callLog.setDuration(duration); callLog.setMethod(request.getMethod().getName()); callLog.setPath(request.getResourceRef().getPath()); callLog.setRemoteIp(request.getClientInfo().getUpstreamAddress()); callLog.setStatusCode(response.getStatus().getCode()); callLog.setUserAgent(request.getClientInfo().getAgent()); callLog.setUserToken((request.getClientInfo().getUser() == null) ? "" : request.getClientInfo().getUser().getIdentifier()); callLogs.add(callLog); if (callLogs.size() >= bufferSize) { flushLogs(); } }
/** * Generates a CallLog for the request and adds it to the buffer. * * @param request * The Request object associated with the request. * @param response * The Response object associated with the request. * @param duration * The duration of the request in milliseconds. * @param startTime * The time at which the request arrived to the agent as an * epoch. */ public void addCallLogToBuffer(Request request, Response response, int duration, long startTime) { CallLog callLog = new CallLog(); callLog.setDate(new Date(startTime)); callLog.setDuration(duration); callLog.setMethod(request.getMethod().getName()); callLog.setPath(request.getResourceRef().getPath()); callLog.setRemoteIp(request.getClientInfo().getUpstreamAddress()); callLog.setStatusCode(response.getStatus().getCode()); callLog.setUserAgent(request.getClientInfo().getAgent()); callLog.setUserToken((request.getClientInfo().getUser() == null) ? "" : request.getClientInfo().getUser().getIdentifier()); callLogs.add(callLog); if (callLogs.size() >= bufferSize) { flushLogs(); } }
/** * Generates a CallLog for the request and adds it to the buffer. * * @param request * The Request object associated with the request. * @param response * The Response object associated with the request. * @param duration * The duration of the request in milliseconds. * @param startTime * The time at which the request arrived to the agent as an * epoch. */ public void addCallLogToBuffer(Request request, Response response, int duration, long startTime) { CallLog callLog = new CallLog(); callLog.setDate(new Date(startTime)); callLog.setDuration(duration); callLog.setMethod(request.getMethod().getName()); callLog.setPath(request.getResourceRef().getPath()); callLog.setRemoteIp(request.getClientInfo().getUpstreamAddress()); callLog.setStatusCode(response.getStatus().getCode()); callLog.setUserAgent(request.getClientInfo().getAgent()); callLog.setUserToken((request.getClientInfo().getUser() == null) ? "" : request.getClientInfo().getUser().getIdentifier()); callLogs.add(callLog); if (callLogs.size() >= bufferSize) { flushLogs(); } }
private UnitOfWork createUnitOfWork( Request request ) { UsecaseBuilder usecaseBuilder = UsecaseBuilder.buildUsecase( request.getResourceRef().getIdentifier( true ) ); User user = request.getClientInfo().getUser(); if( user != null ) { UserIdentity userIdentity = new UserIdentity( user.getIdentifier(), user.getName(), user.getEmail(), user.getFirstName(), user.getLastName() ); usecaseBuilder.withMetaInfo( userIdentity ); } return uowf.newUnitOfWork( usecaseBuilder.newUsecase() ); }