use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.
the class AuthenticationManagementResource method addExecutionFlow.
/**
* Add new flow with new execution to existing flow
*
* @param flowAlias Alias of parent authentication flow
* @param data New authentication flow / execution JSON data containing 'alias', 'type', 'provider', and 'description' attributes
*/
@Path("/flows/{flowAlias}/executions/flow")
@POST
@NoCache
@Consumes(MediaType.APPLICATION_JSON)
public Response addExecutionFlow(@PathParam("flowAlias") String flowAlias, Map<String, String> data) {
auth.realm().requireManageRealm();
AuthenticationFlowModel parentFlow = realm.getFlowByAlias(flowAlias);
if (parentFlow == null) {
return ErrorResponse.error("Parent flow doesn't exist", Response.Status.BAD_REQUEST);
}
String alias = data.get("alias");
String type = data.get("type");
String provider = data.get("provider");
String description = data.get("description");
AuthenticationFlowModel newFlow = realm.getFlowByAlias(alias);
if (newFlow != null) {
return ErrorResponse.exists("New flow alias name already exists");
}
newFlow = new AuthenticationFlowModel();
newFlow.setAlias(alias);
newFlow.setDescription(description);
newFlow.setProviderId(type);
newFlow = realm.addAuthenticationFlow(newFlow);
AuthenticationExecutionModel execution = new AuthenticationExecutionModel();
execution.setParentFlow(parentFlow.getId());
execution.setFlowId(newFlow.getId());
execution.setRequirement(AuthenticationExecutionModel.Requirement.DISABLED);
execution.setAuthenticatorFlow(true);
if (type.equals("form-flow")) {
execution.setAuthenticator(provider);
}
execution.setPriority(getNextPriority(parentFlow));
execution = realm.addAuthenticatorExecution(execution);
data.put("id", execution.getId());
adminEvent.operation(OperationType.CREATE).resource(ResourceType.AUTH_EXECUTION_FLOW).resourcePath(session.getContext().getUri()).representation(data).success();
String addExecutionPathSegment = UriBuilder.fromMethod(AuthenticationManagementResource.class, "addExecutionFlow").build(parentFlow.getAlias()).getPath();
return Response.created(session.getContext().getUri().getBaseUriBuilder().path(session.getContext().getUri().getPath().replace(addExecutionPathSegment, "")).path("flows").path(newFlow.getId()).build()).build();
}
use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.
the class AuthenticationManagementResource method lowerRequiredActionPriority.
/**
* Lower required action's priority
*
* @param alias Alias of required action
*/
@Path("/required-actions/{alias}/lower-priority")
@POST
@NoCache
public void lowerRequiredActionPriority(@PathParam("alias") String alias) {
auth.realm().requireManageRealm();
RequiredActionProviderModel model = realm.getRequiredActionProviderByAlias(alias);
if (model == null) {
throw new NotFoundException("Failed to find required action.");
}
List<RequiredActionProviderModel> actions = realm.getRequiredActionProvidersStream().collect(Collectors.toList());
int i;
for (i = 0; i < actions.size(); i++) {
if (actions.get(i).getId().equals(model.getId())) {
break;
}
}
if (i + 1 >= actions.size())
return;
RequiredActionProviderModel next = actions.get(i + 1);
int tmp = model.getPriority();
model.setPriority(next.getPriority());
realm.updateRequiredActionProvider(model);
next.setPriority(tmp);
realm.updateRequiredActionProvider(next);
adminEvent.operation(OperationType.UPDATE).resource(ResourceType.REQUIRED_ACTION).resourcePath(session.getContext().getUri()).success();
}
use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.
the class RoleMapperResource method getRoleMappings.
/**
* Get role mappings
*
* @return
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public MappingsRepresentation getRoleMappings() {
viewPermission.require();
List<RoleRepresentation> realmRolesRepresentation = new ArrayList<>();
Map<String, ClientMappingsRepresentation> appMappings = new HashMap<>();
final AtomicReference<ClientMappingsRepresentation> mappings = new AtomicReference<>();
roleMapper.getRoleMappingsStream().forEach(roleMapping -> {
RoleContainerModel container = roleMapping.getContainer();
if (container instanceof RealmModel) {
realmRolesRepresentation.add(ModelToRepresentation.toBriefRepresentation(roleMapping));
} else if (container instanceof ClientModel) {
ClientModel clientModel = (ClientModel) container;
mappings.set(appMappings.get(clientModel.getClientId()));
if (mappings.get() == null) {
mappings.set(new ClientMappingsRepresentation());
mappings.get().setId(clientModel.getId());
mappings.get().setClient(clientModel.getClientId());
mappings.get().setMappings(new ArrayList<>());
appMappings.put(clientModel.getClientId(), mappings.get());
}
mappings.get().getMappings().add(ModelToRepresentation.toBriefRepresentation(roleMapping));
}
});
MappingsRepresentation all = new MappingsRepresentation();
if (!realmRolesRepresentation.isEmpty())
all.setRealmMappings(realmRolesRepresentation);
if (!appMappings.isEmpty())
all.setClientMappings(appMappings);
return all;
}
use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.
the class UserResource method removeMembership.
@DELETE
@Path("groups/{groupId}")
@NoCache
public void removeMembership(@PathParam("groupId") String groupId) {
auth.users().requireManageGroupMembership(user);
GroupModel group = session.groups().getGroupById(realm, groupId);
if (group == null) {
throw new NotFoundException("Group not found");
}
auth.groups().requireManageMembership(group);
try {
if (user.isMemberOf(group)) {
user.leaveGroup(group);
adminEvent.operation(OperationType.DELETE).resource(ResourceType.GROUP_MEMBERSHIP).representation(ModelToRepresentation.toRepresentation(group, true)).resourcePath(session.getContext().getUri()).success();
}
} catch (ModelException me) {
Properties messages = AdminRoot.getMessages(session, realm, auth.adminAuth().getToken().getLocale());
throw new ErrorResponseException(me.getMessage(), MessageFormat.format(messages.getProperty(me.getMessage(), me.getMessage()), me.getParameters()), Status.BAD_REQUEST);
}
}
use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.
the class ProtocolMappersResource method getMapperById.
/**
* Get mapper by id
*
* @param id Mapper id
* @return
*/
@GET
@NoCache
@Path("models/{id}")
@Produces(MediaType.APPLICATION_JSON)
public ProtocolMapperRepresentation getMapperById(@PathParam("id") String id) {
viewPermission.require();
ProtocolMapperModel model = client.getProtocolMapperById(id);
if (model == null)
throw new NotFoundException("Model not found");
return ModelToRepresentation.toRepresentation(model);
}
Aggregations