use of de.ids_mannheim.korap.oauth2.entity.OAuth2Client in project Kustvakt by KorAP.
the class OAuth2ClientService method listUserRegisteredClients.
public List<OAuth2UserClientDto> listUserRegisteredClients(String username, String clientId, String clientSecret) throws KustvaktException {
OAuth2Client client = authenticateClient(clientId, clientSecret);
if (!client.isSuper()) {
throw new KustvaktException(StatusCodes.CLIENT_AUTHORIZATION_FAILED, "Only super client is allowed to list user registered clients.", OAuth2Error.UNAUTHORIZED_CLIENT);
}
List<OAuth2Client> userClients = clientDao.retrieveUserRegisteredClients(username);
Collections.sort(userClients);
return createClientDtos(userClients);
}
use of de.ids_mannheim.korap.oauth2.entity.OAuth2Client in project Kustvakt by KorAP.
the class OAuth2ClientService method createClientDtos.
private List<OAuth2UserClientDto> createClientDtos(List<OAuth2Client> userClients) {
List<OAuth2UserClientDto> dtoList = new ArrayList<>(userClients.size());
for (OAuth2Client uc : userClients) {
if (uc.isSuper())
continue;
OAuth2UserClientDto dto = new OAuth2UserClientDto();
dto.setClientId(uc.getId());
dto.setClientName(uc.getName());
dto.setDescription(uc.getDescription());
dto.setUrl(uc.getUrl());
dto.setClientType(uc.getType());
dtoList.add(dto);
}
return dtoList;
}
use of de.ids_mannheim.korap.oauth2.entity.OAuth2Client in project Kustvakt by KorAP.
the class OAuth2ClientService method listUserAuthorizedClients.
public List<OAuth2UserClientDto> listUserAuthorizedClients(String username, String superClientId, String superClientSecret) throws KustvaktException {
OAuth2Client superClient = authenticateClient(superClientId, superClientSecret);
if (!superClient.isSuper()) {
throw new KustvaktException(StatusCodes.CLIENT_AUTHORIZATION_FAILED, "Only super client is allowed to list user authorized clients.", OAuth2Error.UNAUTHORIZED_CLIENT);
}
List<OAuth2Client> userClients = clientDao.retrieveUserAuthorizedClients(username);
userClients.addAll(clientDao.retrieveClientsByAccessTokens(username));
List<String> clientIds = new ArrayList<>();
List<OAuth2Client> uniqueClients = new ArrayList<>();
for (OAuth2Client c : userClients) {
String id = c.getId();
if (!clientIds.contains(id)) {
clientIds.add(id);
uniqueClients.add(c);
}
}
Collections.sort(uniqueClients);
return createClientDtos(uniqueClients);
}
use of de.ids_mannheim.korap.oauth2.entity.OAuth2Client in project Kustvakt by KorAP.
the class AccessTokenDao method storeAccessToken.
public void storeAccessToken(String token, RefreshToken refreshToken, Set<AccessScope> scopes, String userId, String clientId, ZonedDateTime authenticationTime) throws KustvaktException {
ParameterChecker.checkStringValue(token, "access_token");
// ParameterChecker.checkObjectValue(refreshToken, "refresh
// token");
ParameterChecker.checkObjectValue(scopes, "scopes");
// ParameterChecker.checkStringValue(userId, "username");
ParameterChecker.checkStringValue(clientId, "client_id");
ParameterChecker.checkObjectValue(authenticationTime, "authentication time");
ZonedDateTime now = ZonedDateTime.now(ZoneId.of(Attributes.DEFAULT_TIME_ZONE));
ZonedDateTime expiry;
AccessToken accessToken = new AccessToken();
if (refreshToken != null) {
accessToken.setRefreshToken(refreshToken);
expiry = now.plusSeconds(config.getAccessTokenExpiry());
} else {
expiry = now.plusSeconds(config.getAccessTokenLongExpiry());
}
OAuth2Client client = clientDao.retrieveClientById(clientId);
accessToken.setCreatedDate(now);
accessToken.setExpiryDate(expiry);
accessToken.setToken(token);
accessToken.setScopes(scopes);
accessToken.setUserId(userId);
accessToken.setClient(client);
accessToken.setUserAuthenticationTime(authenticationTime);
entityManager.persist(accessToken);
}
use of de.ids_mannheim.korap.oauth2.entity.OAuth2Client in project Kustvakt by KorAP.
the class OltuTokenService method revokeAllClientTokensViaSuperClient.
public void revokeAllClientTokensViaSuperClient(String username, OAuth2RevokeAllTokenSuperRequest revokeTokenRequest) throws KustvaktException {
String superClientId = revokeTokenRequest.getSuperClientId();
String superClientSecret = revokeTokenRequest.getSuperClientSecret();
OAuth2Client superClient = clientService.authenticateClient(superClientId, superClientSecret);
if (!superClient.isSuper()) {
throw new KustvaktException(StatusCodes.CLIENT_AUTHENTICATION_FAILED);
}
String clientId = revokeTokenRequest.getClientId();
OAuth2Client client = clientService.retrieveClient(clientId);
if (clientService.isPublicClient(client)) {
List<AccessToken> accessTokens = tokenDao.retrieveAccessTokenByClientId(clientId, username);
for (AccessToken t : accessTokens) {
revokeAccessToken(t);
}
} else {
List<RefreshToken> refreshTokens = refreshDao.retrieveRefreshTokenByClientId(clientId, username);
for (RefreshToken r : refreshTokens) {
revokeRefreshToken(r);
}
}
}
Aggregations