use of javax.ws.rs.core.CacheControl in project oxAuth by GluuFederation.
the class RegisterRestWebServiceImpl method requestClientRead.
@Override
public Response requestClientRead(String clientId, String authorization, HttpServletRequest httpRequest, SecurityContext securityContext) {
String accessToken = tokenService.getTokenFromAuthorizationParameter(authorization);
log.debug("Attempting to read client: clientId = {}, registrationAccessToken = {} isSecure = {}", clientId, accessToken, securityContext.isSecure());
Response.ResponseBuilder builder = Response.ok();
OAuth2AuditLog oAuth2AuditLog = new OAuth2AuditLog(ServerUtil.getIpAddress(httpRequest), Action.CLIENT_READ);
oAuth2AuditLog.setClientId(clientId);
try {
if (appConfiguration.getDynamicRegistrationEnabled()) {
if (registerParamsValidator.validateParamsClientRead(clientId, accessToken)) {
Client client = clientService.getClient(clientId, accessToken);
if (client != null) {
oAuth2AuditLog.setScope(clientScopesToString(client));
oAuth2AuditLog.setSuccess(true);
builder.entity(clientAsEntity(client));
} else {
log.trace("The Access Token is not valid for the Client ID, returns invalid_token error.");
builder = Response.status(Response.Status.BAD_REQUEST.getStatusCode());
builder.entity(errorResponseFactory.getErrorAsJson(RegisterErrorResponseType.INVALID_TOKEN));
}
} else {
log.trace("Client parameters are invalid.");
builder = Response.status(Response.Status.BAD_REQUEST);
builder.entity(errorResponseFactory.getErrorAsJson(RegisterErrorResponseType.INVALID_CLIENT_METADATA));
}
} else {
builder = Response.status(Response.Status.BAD_REQUEST);
builder.entity(errorResponseFactory.getErrorAsJson(RegisterErrorResponseType.ACCESS_DENIED));
}
} catch (JSONException e) {
builder = Response.status(500);
builder.entity(errorResponseFactory.getErrorAsJson(RegisterErrorResponseType.INVALID_CLIENT_METADATA));
log.error(e.getMessage(), e);
} catch (StringEncrypter.EncryptionException e) {
builder = Response.status(500);
builder.entity(errorResponseFactory.getErrorAsJson(RegisterErrorResponseType.INVALID_CLIENT_METADATA));
log.error(e.getMessage(), e);
}
CacheControl cacheControl = new CacheControl();
cacheControl.setNoTransform(false);
cacheControl.setNoStore(true);
builder.cacheControl(cacheControl);
builder.header("Pragma", "no-cache");
applicationAuditLogger.sendMessage(oAuth2AuditLog);
return builder.build();
}
use of javax.ws.rs.core.CacheControl in project oxAuth by GluuFederation.
the class UserInfoRestWebServiceImpl method requestUserInfo.
public Response requestUserInfo(String accessToken, String authorization, HttpServletRequest request, SecurityContext securityContext) {
if (authorization != null && !authorization.isEmpty() && authorization.startsWith("Bearer ")) {
accessToken = authorization.substring(7);
}
log.debug("Attempting to request User Info, Access token = {}, Is Secure = {}", accessToken, securityContext.isSecure());
Response.ResponseBuilder builder = Response.ok();
OAuth2AuditLog oAuth2AuditLog = new OAuth2AuditLog(ServerUtil.getIpAddress(request), Action.USER_INFO);
try {
if (!UserInfoParamsValidator.validateParams(accessToken)) {
builder = Response.status(400);
builder.entity(errorResponseFactory.getErrorAsJson(UserInfoErrorResponseType.INVALID_REQUEST));
} else {
AuthorizationGrant authorizationGrant = authorizationGrantList.getAuthorizationGrantByAccessToken(accessToken);
if (authorizationGrant == null) {
builder = Response.status(400);
builder.entity(errorResponseFactory.getErrorAsJson(UserInfoErrorResponseType.INVALID_TOKEN));
} else if (authorizationGrant.getAuthorizationGrantType() == AuthorizationGrantType.CLIENT_CREDENTIALS) {
builder = Response.status(403);
builder.entity(errorResponseFactory.getErrorAsJson(UserInfoErrorResponseType.INSUFFICIENT_SCOPE));
} else if (!authorizationGrant.getScopes().contains(DefaultScope.OPEN_ID.toString()) && !authorizationGrant.getScopes().contains(DefaultScope.PROFILE.toString())) {
builder = Response.status(403);
builder.entity(errorResponseFactory.getErrorAsJson(UserInfoErrorResponseType.INSUFFICIENT_SCOPE));
oAuth2AuditLog.updateOAuth2AuditLog(authorizationGrant, false);
} else {
oAuth2AuditLog.updateOAuth2AuditLog(authorizationGrant, true);
CacheControl cacheControl = new CacheControl();
cacheControl.setPrivate(true);
cacheControl.setNoTransform(false);
cacheControl.setNoStore(true);
builder.cacheControl(cacheControl);
builder.header("Pragma", "no-cache");
User currentUser = authorizationGrant.getUser();
try {
currentUser = userService.getUserByDn(authorizationGrant.getUserDn());
} catch (EntryPersistenceException ex) {
log.warn("Failed to reload user entry: '{}'", authorizationGrant.getUserDn());
}
if (authorizationGrant.getClient() != null && authorizationGrant.getClient().getUserInfoEncryptedResponseAlg() != null && authorizationGrant.getClient().getUserInfoEncryptedResponseEnc() != null) {
KeyEncryptionAlgorithm keyEncryptionAlgorithm = KeyEncryptionAlgorithm.fromName(authorizationGrant.getClient().getUserInfoEncryptedResponseAlg());
BlockEncryptionAlgorithm blockEncryptionAlgorithm = BlockEncryptionAlgorithm.fromName(authorizationGrant.getClient().getUserInfoEncryptedResponseEnc());
builder.type("application/jwt");
builder.entity(getJweResponse(keyEncryptionAlgorithm, blockEncryptionAlgorithm, currentUser, authorizationGrant, authorizationGrant.getScopes()));
} else if (authorizationGrant.getClient() != null && authorizationGrant.getClient().getUserInfoSignedResponseAlg() != null) {
SignatureAlgorithm algorithm = SignatureAlgorithm.fromString(authorizationGrant.getClient().getUserInfoSignedResponseAlg());
builder.type("application/jwt");
builder.entity(getJwtResponse(algorithm, currentUser, authorizationGrant, authorizationGrant.getScopes()));
} else {
builder.type((MediaType.APPLICATION_JSON + ";charset=UTF-8"));
builder.entity(getJSonResponse(currentUser, authorizationGrant, authorizationGrant.getScopes()));
}
}
}
} catch (StringEncrypter.EncryptionException e) {
// 500
builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
log.error(e.getMessage(), e);
} catch (InvalidJwtException e) {
// 500
builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
log.error(e.getMessage(), e);
} catch (SignatureException e) {
// 500
builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
log.error(e.getMessage(), e);
} catch (InvalidClaimException e) {
// 500
builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
log.error(e.getMessage(), e);
} catch (Exception e) {
// 500
builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
log.error(e.getMessage(), e);
}
applicationAuditLogger.sendMessage(oAuth2AuditLog);
return builder.build();
}
use of javax.ws.rs.core.CacheControl in project oxAuth by GluuFederation.
the class TokenRestWebServiceImpl method response.
private Response response(ResponseBuilder builder) {
CacheControl cacheControl = new CacheControl();
cacheControl.setNoTransform(false);
cacheControl.setNoStore(true);
builder.cacheControl(cacheControl);
builder.header("Pragma", "no-cache");
return builder.build();
}
use of javax.ws.rs.core.CacheControl in project oxAuth by GluuFederation.
the class ServerUtil method cacheControl.
public static CacheControl cacheControl(boolean p_noStore, boolean p_noTransform) {
final CacheControl cacheControl = new CacheControl();
cacheControl.setNoStore(p_noStore);
cacheControl.setNoTransform(p_noTransform);
return cacheControl;
}
use of javax.ws.rs.core.CacheControl in project stanbol by apache.
the class UserResource method store.
// **********************************
// ****** ADD PERMISSION TO USER ****
// **********************************
// **************************************
// ****** REMOVE PERMISSION FROM USER ***
// **************************************
// ************************************
// ****** ADD PERMISSION TO ROLE ******
// ************************************
// **************************************
// ****** REMOVE PERMISSION FROM ROLE ***
// **************************************
////////////////////////////////////////////////////////////////
/**
* Pushes user data into system graph
*
* @param userNode
* @param uriInfo
* @param currentUserName
* @param newUserName
* @param fullName
* @param email
* @param password
* @param roles
* @param permissions
* @return
*/
private Response store(GraphNode userNode, UriInfo uriInfo, String currentUserName, String newUserName, String fullName, String email, String password, List<String> roles, List<String> permissions) {
if (newUserName != null && !newUserName.equals("")) {
changeLiteral(userNode, PLATFORM.userName, newUserName);
}
if (fullName != null && !fullName.equals("")) {
changeLiteral(userNode, FOAF.name, fullName);
}
if (password != null && !password.equals("")) {
String passwordSha1 = PasswordUtil.convertPassword(password);
changeLiteral(userNode, PERMISSION.passwordSha1, passwordSha1);
}
if (email != null && !email.equals("")) {
changeResource(userNode, FOAF.mbox, new IRI("mailto:" + email));
}
BlankNodeOrIRI userResource = (BlankNodeOrIRI) userNode.getNode();
if (roles != null) {
clearRoles(userResource);
Lock writeLock = systemGraph.getLock().writeLock();
writeLock.lock();
try {
for (int i = 0; i < roles.size(); i++) {
roles.set(i, roles.get(i).trim());
if (!roles.get(i).equals("")) {
addRole(userNode, roles.get(i));
}
}
} finally {
writeLock.unlock();
}
}
if (permissions != null) {
clearPermissions(userResource);
Lock writeLock = systemGraph.getLock().writeLock();
writeLock.lock();
try {
for (int i = 0; i < permissions.size(); i++) {
permissions.set(i, permissions.get(i).trim());
if (!permissions.get(i).equals("")) {
addPermission(userNode, permissions.get(i));
}
}
} finally {
writeLock.unlock();
}
}
URI pageUri = uriInfo.getBaseUriBuilder().path("system/console/usermanagement").build();
// header Cache-control: no-cache, just in case intermediaries are
// holding onto old stuff
CacheControl cc = new CacheControl();
cc.setNoCache(true);
// the jax-rs things available
return Response.seeOther(pageUri).cacheControl(cc).build();
}
Aggregations