Exemplo n.º 1
0
 private OAuthContext getOAuthContext() {
   OAuthContext oauth = mc.getContent(OAuthContext.class);
   if (oauth == null || oauth.getSubject() == null || oauth.getSubject().getLogin() == null) {
     throw new WebApplicationException(403);
   }
   return oauth;
 }
Exemplo n.º 2
0
  @POST
  public void updateCalendar(
      @FormParam("hour") int hour, @FormParam("description") String description) {
    // This permission check can be done in a custom filter; it can be simpler to do
    // in the actual service code if the context data (such as an hour in this case)
    // are not available in the request URI but in the message payload
    OAuthContext oauth = getOAuthContext();
    List<OAuthPermission> perms = oauth.getPermissions();
    boolean checkPassed = false;
    for (OAuthPermission perm : perms) {
      if (perm.getPermission().startsWith(OAuthConstants.UPDATE_CALENDAR_SCOPE)) {
        int authorizedHour =
            Integer.valueOf(
                perm.getPermission().substring(OAuthConstants.UPDATE_CALENDAR_SCOPE.length()));
        if (authorizedHour == 24 || authorizedHour == hour) {
          checkPassed = true;
        }
      }
    }
    if (!checkPassed) {
      throw new WebApplicationException(403);
    }
    // end of the check

    Calendar calendar = getUserCalendar();
    calendar.getEntry(hour).setEventDescription(description);
  }
Exemplo n.º 3
0
 @GET
 public Calendar getUserCalendar() {
   OAuthContext oauth = getOAuthContext();
   String userName = oauth.getSubject().getLogin();
   UserAccount account = accounts.getAccount(userName);
   if (account == null) {
     account = accounts.getAccountWithAlias(userName);
   }
   Calendar calendar = new Calendar();
   return calendar;
 }
Exemplo n.º 4
0
 @GET
 @Produces({"application/json", "application/jwt"})
 public Response getUserInfo() {
   OAuthContext oauth = OAuthContextUtils.getContext(mc);
   UserInfo userInfo =
       userInfoProvider.getUserInfo(
           oauth.getClientId(), oauth.getSubject(), oauth.getPermissions());
   if (userInfo != null) {
     userInfo.setIssuer(issuer);
   }
   userInfo.setAudience(oauth.getClientId());
   Object responseEntity = userInfo;
   if (super.isJwsRequired() || super.isJweRequired()) {
     responseEntity =
         super.processJwt(
             new JwtToken(userInfo), oauthDataProvider.getClient(oauth.getClientId()));
   }
   return Response.ok(responseEntity).build();
 }