Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
23822fe
[CITE-217] Adding Access Token
diya17 Oct 19, 2023
17dbe63
[CITE-217] Adding user token manager
diya17 Oct 25, 2023
6f89887
[CITE-217] Adding create token method for access token
diya17 Oct 31, 2023
57f6eea
[CITE-217] Adding CRUD operations
diya17 Nov 3, 2023
befbf1d
Extending user access token repository and manager
diya17 Nov 3, 2023
ba2c4d1
[CITE-217] Adding Form and controller
diya17 Nov 7, 2023
8beb5a3
[CITE-217] Adding controllers
diya17 Nov 9, 2023
78d74b9
[CITE-217] : Controllers and views
diya17 Nov 14, 2023
d0b037d
[CITE-217] Adding views for details
diya17 Nov 16, 2023
24c6348
[CITE-217] Changing endpoints
diya17 Nov 21, 2023
8d4de31
[CITE-217] Adding to the header
diya17 Nov 28, 2023
abe4e3d
[CITE-217] Making changes to controllers and views
diya17 Jan 25, 2024
5c320f3
[CITE-217] Fixing issues with deletion and regeneration
diya17 Jan 26, 2024
0086228
[CITE-217] Changing token implementation to implicit token
diya17 Jan 29, 2024
163a27c
[CITE-217] Extending Oauthclient manager
diya17 Jan 31, 2024
a4047a1
[CITE-217] Changing CRUD to OauthClient
diya17 Feb 2, 2024
4a248d6
[CITE-217] Refactoring and changing CRUD class
diya17 Feb 6, 2024
5e4088d
[CITE-217] Changing access token generation
diya17 Feb 7, 2024
7c617b4
[CITE-217] Adding testcases
diya17 Feb 9, 2024
a122954
[CITE-217] : Refactoring
diya17 Feb 13, 2024
0f0f5fe
[CITE-217] Update pom
diya17 Feb 13, 2024
c7d70e0
[CITE-217] : Update Method
diya17 Mar 6, 2024
d648041
Merge branch 'develop' into story/CITE-217
PradnyaC11 Mar 28, 2025
27d7271
[CITE-217] Resolved the errors and removed duplicate codes
PradnyaC11 Apr 1, 2025
ec9d301
[CITE-217] Seperated manager class for personal oauth
Girik1105 Dec 22, 2025
51f7b94
[CITE-217] Created own seperate sub class and removed flag
Girik1105 Dec 23, 2025
8096355
[CITE-217] Removed garbage text
Girik1105 Dec 23, 2025
14630b3
[CITE-217] Fixed javascript to show tokens after regenration
Girik1105 Dec 23, 2025
bbdde80
[CITE-217] Code cleanup
Girik1105 Dec 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion citesphere/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -542,14 +542,23 @@
<version>4.13.1</version>
<scope>test</scope>
</dependency>



<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.12.4</version>
<scope>test</scope>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation


<!-- https://mvnrepository.com/artifact/xalan/xalan -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package edu.asu.diging.citesphere.core.exceptions;

public class CannotFindTokenException extends Exception {

private static final long serialVersionUID = 1L;

public CannotFindTokenException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package edu.asu.diging.citesphere.core.model.oauth;

import java.time.OffsetDateTime;

/**
* Interface representing a personal access token for API access.
* Personal access tokens allow users to authenticate against the API
* without going through the OAuth authorization code flow.
*/
public interface IPersonalAccessToken {

String getId();

String getName();
void setName(String name);

String getUsername();

OffsetDateTime getCreatedAt();
void setCreatedAt(OffsetDateTime createdAt);

boolean isPersonalAccessToken();
void setPersonalAccessToken(boolean isPersonalAccessToken);
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package edu.asu.diging.citesphere.core.model.oauth.impl;

import java.time.OffsetDateTime;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;

import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;

import edu.asu.diging.citesphere.core.model.oauth.IPersonalAccessToken;

/**
* Modeled after:
* https://blog.couchbase.com/custom-token-store-spring-securtiy-oauth2/
* @author jdamerow
*
*/
@Entity
public class DbAccessToken {
public class DbAccessToken implements IPersonalAccessToken {

@Id
private String id;
private String tokenId;
Expand All @@ -28,12 +32,15 @@ public class DbAccessToken {
private String authentication;
@Lob
private String refreshToken;



private String name;
private OffsetDateTime createdAt;
private boolean personalAccessToken;

public OAuth2Authentication getAuthentication() {
return SerializableObjectConverter.deserialize(authentication);
}

public void setAuthentication(OAuth2Authentication authentication) {
this.authentication = SerializableObjectConverter.serialize(authentication);
}
Expand Down Expand Up @@ -97,5 +104,34 @@ public void setRefreshToken(String refreshToken) {
public void setAuthentication(String authentication) {
this.authentication = authentication;
}

}

@Override
public String getName() {
return name;
}

@Override
public void setName(String name) {
this.name = name;
}

@Override
public OffsetDateTime getCreatedAt() {
return createdAt;
}

@Override
public void setCreatedAt(OffsetDateTime createdAt) {
this.createdAt = createdAt;
}

@Override
public boolean isPersonalAccessToken() {
return personalAccessToken;
}

@Override
public void setPersonalAccessToken(boolean personalAccessToken) {
this.personalAccessToken = personalAccessToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToOne;

import org.hibernate.annotations.GenericGenerator;
Expand All @@ -21,6 +26,9 @@
import edu.asu.diging.citesphere.user.impl.User;

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DTYPE", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("OAUTH")
public class OAuthClient implements IOAuthClient, ClientDetails {

/**
Expand Down Expand Up @@ -50,6 +58,7 @@ public class OAuthClient implements IOAuthClient, ClientDetails {
private int accessTokenValiditySeconds;
private int refereshTokenValiditySeconds;
private boolean autoApprove;

@OneToOne(targetEntity=User.class)
private IUser createdBy;

Expand Down Expand Up @@ -199,7 +208,6 @@ public void setAutoApprove(boolean autoApprove) {
this.autoApprove = autoApprove;
}

@Override
public IUser getCreatedBy() {
return this.createdBy;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package edu.asu.diging.citesphere.core.model.oauth.impl;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

/**
* Subclass of OAuthClient specifically for personal access tokens.
* The type itself identifies PAT clients
*/
@Entity
@DiscriminatorValue("PAT")
public class PersonalAccessTokenOAuthClient extends OAuthClient {

private static final long serialVersionUID = 1L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.List;
import java.util.Optional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import edu.asu.diging.citesphere.core.model.oauth.impl.DbAccessToken;
Expand All @@ -28,5 +30,8 @@ public interface DbAccessTokenRepository extends JpaRepository<DbAccessToken, St
List<DbAccessToken> findByAuthenticationId(String authenticationId);

void deleteByClientIdAndUsername(String clientId, String username);


Page<DbAccessToken> findByUsernameAndPersonalAccessToken(String username, boolean isPersonalAccessToken, Pageable pageable);

Optional<DbAccessToken> findByIdAndUsername(String id, String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

import edu.asu.diging.citesphere.core.model.oauth.impl.OAuthClient;

/**
* Repository for OAuth clients.
* Note: Personal access token clients now have their own repository
* (PersonalAccessTokenOAuthClientRepository).
*/
public interface OAuthClientRepository extends JpaRepository<OAuthClient, String> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.asu.diging.citesphere.core.repository.oauth;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;

import edu.asu.diging.citesphere.core.model.oauth.impl.PersonalAccessTokenOAuthClient;

/**
* Repository for personal access token OAuth clients.
* This repository handles the specialized PAT client subclass.
*/
public interface PersonalAccessTokenOAuthClientRepository
extends JpaRepository<PersonalAccessTokenOAuthClient, String> {

/**
* Find a personal access token client by the username of the user who created it.
* Each user has at most one PAT client.
*/
Optional<PersonalAccessTokenOAuthClient> findByCreatedByUsername(String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public interface IOAuthClientManager {
OAuthCredentials updateClientSecret(String clientId) throws CannotFindClientException;

List<OAuthClient> getClientsDetails(List<String> clientList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package edu.asu.diging.citesphere.core.service.oauth;

import org.springframework.data.domain.Pageable;

import edu.asu.diging.citesphere.core.exceptions.CannotFindTokenException;
import edu.asu.diging.citesphere.core.model.oauth.IPersonalAccessToken;
import edu.asu.diging.citesphere.user.IUser;

/**
* Manager for personal access token operations.
* Personal access tokens allow users to authenticate against the API
* without going through the OAuth authorization code flow.
*/
public interface IPersonalAccessTokenManager {

/**
* Creates a new personal access token for the user.
*
* @param name the user-given name for the token
* @param user the user creating the token
* @return credentials containing the token ID and token value (shown only once)
*/
PersonalAccessTokenCredentials createToken(String name, IUser user);

/**
* Gets all personal access tokens for the user.
*
* @param user the user whose tokens to retrieve
* @param pageable pagination information
* @return paginated result of tokens
*/
PersonalAccessTokenResultPage getTokensForUser(IUser user, Pageable pageable);

/**
* Deletes a personal access token.
*
* @param tokenId the ID of the token to delete
* @param user the user who owns the token
* @throws CannotFindTokenException if the token is not found or doesn't belong to the user
*/
void deleteToken(String tokenId, IUser user) throws CannotFindTokenException;

/**
* Regenerates a personal access token, invalidating the old token value
* and creating a new one.
*
* @param tokenId the ID of the token to regenerate
* @param user the user who owns the token
* @return credentials containing the token ID and new token value
* @throws CannotFindTokenException if the token is not found or doesn't belong to the user
*/
PersonalAccessTokenCredentials regenerateToken(String tokenId, IUser user) throws CannotFindTokenException;

/**
* Gets a personal access token by ID.
*
* @param tokenId the ID of the token
* @return the token, or null if not found
*/
IPersonalAccessToken getTokenById(String tokenId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package edu.asu.diging.citesphere.core.service.oauth;

/**
* This class is a temporary holder for personal access token ID and token value
* to be used after creation of a new token. The token value should only be shown
* once to the user and not stored unencrypted.
*/
public class PersonalAccessTokenCredentials {

private String tokenId;
private String tokenValue;
private String name;

public PersonalAccessTokenCredentials(String tokenId, String tokenValue, String name) {
this.tokenId = tokenId;
this.tokenValue = tokenValue;
this.name = name;
}

public String getTokenId() {
return tokenId;
}

public void setTokenId(String tokenId) {
this.tokenId = tokenId;
}

public String getTokenValue() {
return tokenValue;
}

public void setTokenValue(String tokenValue) {
this.tokenValue = tokenValue;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Loading