protected TypedQuery<RefreshToken> getRefreshTokensQuery(
     Client c, UserSubject resourceOwnerSubject) {
   if (c == null && resourceOwnerSubject == null) {
     return entityManager.createQuery(
         "SELECT t FROM " + REFRESH_TOKEN_TABLE_NAME + " t", RefreshToken.class);
   } else if (c == null) {
     return entityManager.createQuery(
         "SELECT t FROM "
             + REFRESH_TOKEN_TABLE_NAME
             + " t JOIN t.subject s WHERE s.login = '******'",
         RefreshToken.class);
   } else if (resourceOwnerSubject == null) {
     return entityManager.createQuery(
         "SELECT t FROM "
             + REFRESH_TOKEN_TABLE_NAME
             + " t JOIN t.client c WHERE c.clientId = '"
             + c.getClientId()
             + "'",
         RefreshToken.class);
   } else {
     return entityManager.createQuery(
         "SELECT t FROM "
             + REFRESH_TOKEN_TABLE_NAME
             + " t JOIN t.subject s JOIN t.client c WHERE s.login = '******' AND c.clientId = '"
             + c.getClientId()
             + "'",
         RefreshToken.class);
   }
 }
Exemple #2
0
 private static UserSubject recreateUserSubject(String sequence) {
   UserSubject subject = null;
   if (!sequence.trim().isEmpty()) {
     String[] subjectParts = sequence.split("&");
     subject = new UserSubject(getStringPart(subjectParts[0]), getStringPart(subjectParts[1]));
     subject.setRoles(parseSimpleList(subjectParts[2]));
     subject.setProperties(parseSimpleMap(subjectParts[3]));
   }
   return subject;
 }
Exemple #3
0
 private static void tokenizeUserSubject(StringBuilder state, UserSubject subject) {
   if (subject != null) {
     // 1
     state.append(tokenizeString(subject.getLogin()));
     state.append("&");
     // 2
     state.append(tokenizeString(subject.getId()));
     state.append("&");
     // 3
     state.append(tokenizeString(subject.getRoles().toString()));
     state.append("&");
     // 4
     state.append(tokenizeString(subject.getProperties().toString()));
   } else {
     state.append("&");
   }
 }
 protected TypedQuery<Client> getClientsQuery(UserSubject resourceOwnerSubject) {
   if (resourceOwnerSubject == null) {
     return entityManager.createQuery("SELECT c FROM " + CLIENT_TABLE_NAME + " c", Client.class);
   } else {
     return entityManager.createQuery(
         "SELECT c FROM "
             + CLIENT_TABLE_NAME
             + " c JOIN c.resourceOwnerSubject r WHERE r.login = '******'",
         Client.class);
   }
 }
 public String getName(UserSubject subject) {
   return subject.getLogin();
 }